Skip to content

Commit

Permalink
Add related polyfill interface to other PHP 8.0/7.3 rules (#5389)
Browse files Browse the repository at this point in the history
* add related polyfill interface to other PHP 8.0 rules

* cs
  • Loading branch information
TomasVotruba authored Dec 25, 2023
1 parent ebb2d2d commit 6ebab94
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.

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';
}

0 comments on commit 6ebab94

Please sign in to comment.