mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
Updated Rector to commit 5ac3cb377abf968396c23573d8562e6ab6967f2a
5ac3cb377a
[Php70] Fix Php4 contructor not replaced with __construct() on php 7.4 environment (#5189)
This commit is contained in:
parent
58494f42d4
commit
440cc19f16
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1474,6 +1474,7 @@ return array(
|
||||
'Rector\\DowngradePhp81\\Rector\\ClassConst\\DowngradeFinalizePublicClassConstantRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/ClassConst/DowngradeFinalizePublicClassConstantRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeArrayIsListRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeHashAlgorithmXxHashRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNewInInitializerRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradePureIntersectionTypeRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradePureIntersectionTypeRector.php',
|
||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -1692,6 +1692,7 @@ class ComposerStaticInit46a0b0ac2ea1371bb06be09a20f71c2b
|
||||
'Rector\\DowngradePhp81\\Rector\\ClassConst\\DowngradeFinalizePublicClassConstantRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/ClassConst/DowngradeFinalizePublicClassConstantRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeArrayIsListRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeHashAlgorithmXxHashRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHashRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNewInInitializerRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradePureIntersectionTypeRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp81/Rector/FunctionLike/DowngradePureIntersectionTypeRector.php',
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -1743,12 +1743,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
|
||||
"reference": "3e960af992626719d4370dcede16a104a12acf64"
|
||||
"reference": "2d20783f344dec1895e19d2797d4c3b903b4f3cb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/3e960af992626719d4370dcede16a104a12acf64",
|
||||
"reference": "3e960af992626719d4370dcede16a104a12acf64",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/2d20783f344dec1895e19d2797d4c3b903b4f3cb",
|
||||
"reference": "2d20783f344dec1895e19d2797d4c3b903b4f3cb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1775,7 +1775,7 @@
|
||||
"tomasvotruba\/unused-public": "^0.2",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2023-10-18T15:35:32+00:00",
|
||||
"time": "2023-10-20T09:51:24+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
||||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 3e960af'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 7a0a6db'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 5c5530a'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 2d20783'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 7a0a6db'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 5c5530a'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202310;
|
||||
|
||||
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHashRector;
|
||||
use Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
|
||||
use Rector\DowngradePhp81\Rector\MethodCall\DowngradeIsEnumRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
@ -22,7 +23,7 @@ use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
|
||||
use Rector\Renaming\ValueObject\MethodCallRename;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->phpVersion(PhpVersion::PHP_80);
|
||||
$rectorConfig->rules([DowngradeFinalizePublicClassConstantRector::class, DowngradeFirstClassCallableSyntaxRector::class, DowngradeNeverTypeDeclarationRector::class, DowngradePureIntersectionTypeRector::class, DowngradeNewInInitializerRector::class, DowngradePhp81ResourceReturnToObjectRector::class, DowngradeReadonlyPropertyRector::class, DowngradeArraySpreadStringKeyRector::class, DowngradeArrayIsListRector::class, DowngradeSetAccessibleReflectionPropertyRector::class, DowngradeIsEnumRector::class, DowngradeOctalNumberRector::class]);
|
||||
$rectorConfig->rules([DowngradeFinalizePublicClassConstantRector::class, DowngradeFirstClassCallableSyntaxRector::class, DowngradeNeverTypeDeclarationRector::class, DowngradePureIntersectionTypeRector::class, DowngradeNewInInitializerRector::class, DowngradePhp81ResourceReturnToObjectRector::class, DowngradeReadonlyPropertyRector::class, DowngradeArraySpreadStringKeyRector::class, DowngradeArrayIsListRector::class, DowngradeSetAccessibleReflectionPropertyRector::class, DowngradeIsEnumRector::class, DowngradeOctalNumberRector::class, DowngradeHashAlgorithmXxHashRector::class]);
|
||||
// @see https://php.watch/versions/8.1/internal-method-return-types#reflection
|
||||
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename('ReflectionFunction', 'hasTentativeReturnType', 'hasReturnType'), new MethodCallRename('ReflectionFunction', 'getTentativeReturnType', 'getReturnType'), new MethodCallRename('ReflectionMethod', 'hasTentativeReturnType', 'hasReturnType'), new MethodCallRename('ReflectionMethod', 'getTentativeReturnType', 'getReturnType')]);
|
||||
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
|
||||
|
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DowngradePhp81\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\DowngradeHashAlgorithmXxHashRectorTest
|
||||
*/
|
||||
final class DowngradeHashAlgorithmXxHashRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
|
||||
*/
|
||||
private $argsAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
|
||||
*/
|
||||
private $valueResolver;
|
||||
private const HASH_ALGORITHMS_TO_DOWNGRADE = ['xxh32' => \MHASH_XXH32, 'xxh64' => \MHASH_XXH64, 'xxh3' => \MHASH_XXH3, 'xxh128' => \MHASH_XXH128];
|
||||
private const REPLACEMENT_ALGORITHM = 'md5';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $argNamedKey;
|
||||
public function __construct(ArgsAnalyzer $argsAnalyzer, ValueResolver $valueResolver)
|
||||
{
|
||||
$this->argsAnalyzer = $argsAnalyzer;
|
||||
$this->valueResolver = $valueResolver;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Downgrade hash algorithm xxh32, xxh64, xxh3 or xxh128 by default to md5. You can configure the algorithm to downgrade.', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return hash('xxh128', 'some-data-to-hash');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return hash('md5', 'some-data-to-hash');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [FuncCall::class];
|
||||
}
|
||||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->argNamedKey = 0;
|
||||
$algorithm = $this->getHashAlgorithm($node->getArgs());
|
||||
if ($algorithm === null || !\array_key_exists($algorithm, self::HASH_ALGORITHMS_TO_DOWNGRADE)) {
|
||||
return null;
|
||||
}
|
||||
$args = $node->getArgs();
|
||||
if (!isset($args[$this->argNamedKey])) {
|
||||
return null;
|
||||
}
|
||||
$arg = $args[$this->argNamedKey];
|
||||
$arg->value = new String_(self::REPLACEMENT_ALGORITHM);
|
||||
return $node;
|
||||
}
|
||||
private function shouldSkip(FuncCall $funcCall) : bool
|
||||
{
|
||||
if ($funcCall->isFirstClassCallable()) {
|
||||
return \true;
|
||||
}
|
||||
return !$this->nodeNameResolver->isName($funcCall, 'hash');
|
||||
}
|
||||
/**
|
||||
* @param Arg[] $args
|
||||
*/
|
||||
private function getHashAlgorithm(array $args) : ?string
|
||||
{
|
||||
$arg = null;
|
||||
if ($this->argsAnalyzer->hasNamedArg($args)) {
|
||||
foreach ($args as $key => $arg) {
|
||||
if ((($nullsafeVariable1 = $arg->name) ? $nullsafeVariable1->name : null) !== 'algo') {
|
||||
continue;
|
||||
}
|
||||
$this->argNamedKey = $key;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$arg = $args[$this->argNamedKey];
|
||||
}
|
||||
$algorithmNode = ($nullsafeVariable2 = $arg) ? $nullsafeVariable2->value : null;
|
||||
switch (\true) {
|
||||
case $algorithmNode instanceof String_:
|
||||
return $this->valueResolver->getValue($algorithmNode);
|
||||
case $algorithmNode instanceof ConstFetch:
|
||||
return $this->mapConstantToString($this->valueResolver->getValue($algorithmNode));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private function mapConstantToString(string $constant) : string
|
||||
{
|
||||
$mappedConstant = \array_search(\constant($constant), self::HASH_ALGORITHMS_TO_DOWNGRADE, \true);
|
||||
return $mappedConstant !== \false ? $mappedConstant : $constant;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user