Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add related polyfill interface to other PHP 8.0/7.3 rules #5389

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

9 changes: 8 additions & 1 deletion rules/Php73/Rector/BooleanOr/IsCountableRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Core\ValueObject\PolyfillPackage;
use Rector\Php71\IsArrayAndDualCheckToAble;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Rector\VersionBonding\Contract\RelatedPolyfillInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Tests\Php73\Rector\BinaryOr\IsCountableRector\IsCountableRectorTest
*/
final class IsCountableRector extends AbstractRector implements MinPhpVersionInterface
final class IsCountableRector extends AbstractRector implements MinPhpVersionInterface, RelatedPolyfillInterface
{
public function __construct(
private readonly IsArrayAndDualCheckToAble $isArrayAndDualCheckToAble,
Expand Down Expand Up @@ -69,6 +71,11 @@ public function provideMinPhpVersion(): int
return PhpVersionFeature::IS_COUNTABLE;
}

public function providePolyfillPackage(): string
{
return PolyfillPackage::PHP_73;
}

private function shouldSkip(): bool
{
return ! $this->reflectionProvider->hasFunction(new Name('is_countable'), null);
Expand Down
9 changes: 8 additions & 1 deletion rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Core\ValueObject\PolyfillPackage;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Rector\VersionBonding\Contract\RelatedPolyfillInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -26,7 +28,7 @@
*
* @see \Rector\Tests\Php73\Rector\FuncCall\ArrayKeyFirstLastRector\ArrayKeyFirstLastRectorTest
*/
final class ArrayKeyFirstLastRector extends AbstractRector implements MinPhpVersionInterface
final class ArrayKeyFirstLastRector extends AbstractRector implements MinPhpVersionInterface, RelatedPolyfillInterface
{
/**
* @var string
Expand Down Expand Up @@ -103,6 +105,11 @@ public function provideMinPhpVersion(): int
return PhpVersionFeature::ARRAY_KEY_FIRST_LAST;
}

public function providePolyfillPackage(): string
{
return PolyfillPackage::PHP_73;
}

private function processArrayKeyFirstLast(
StmtsAwareInterface $stmtsAware,
bool $hasChanged,
Expand Down
9 changes: 8 additions & 1 deletion rules/Php80/Rector/NotIdentical/StrContainsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Core\ValueObject\PolyfillPackage;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Rector\VersionBonding\Contract\RelatedPolyfillInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -27,7 +29,7 @@
*
* @see \Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\StrContainsRectorTest
*/
final class StrContainsRector extends AbstractRector implements MinPhpVersionInterface
final class StrContainsRector extends AbstractRector implements MinPhpVersionInterface, RelatedPolyfillInterface
{
/**
* @var string[]
Expand Down Expand Up @@ -119,6 +121,11 @@ public function refactor(Node $node): ?Node
return $funcCall;
}

public function providePolyfillPackage(): string
{
return PolyfillPackage::PHP_80;
}

private function matchIdenticalOrNotIdenticalToFalse(Identical | NotIdentical | Equal | NotEqual $expr): ?FuncCall
{
if ($this->valueResolver->isFalse($expr->left)) {
Expand Down
9 changes: 8 additions & 1 deletion rules/Php80/Rector/Ternary/GetDebugTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use PhpParser\Node\Identifier;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Core\ValueObject\PolyfillPackage;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Rector\VersionBonding\Contract\RelatedPolyfillInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -21,7 +23,7 @@
*
* @see \Rector\Tests\Php80\Rector\Ternary\GetDebugTypeRector\GetDebugTypeRectorTest
*/
final class GetDebugTypeRector extends AbstractRector implements MinPhpVersionInterface
final class GetDebugTypeRector extends AbstractRector implements MinPhpVersionInterface, RelatedPolyfillInterface
{
public function provideMinPhpVersion(): int
{
Expand Down Expand Up @@ -90,6 +92,11 @@ public function refactor(Node $node): ?Node
return $this->nodeFactory->createFuncCall('get_debug_type', [$firstExpr]);
}

public function providePolyfillPackage(): string
{
return PolyfillPackage::PHP_80;
}

private function shouldSkip(Ternary $ternary): bool
{
if (! $ternary->cond instanceof FuncCall) {
Expand Down
5 changes: 5 additions & 0 deletions src/ValueObject/PolyfillPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ final class PolyfillPackage
* @var string
*/
public const PHP_80 = 'symfony/polyfill-php80';

/**
* @var string
*/
public const PHP_73 = 'symfony/polyfill-php73';
}