Updated Rector to commit c1cb710c872d25f5daa3fd085fc24640716a80f4

c1cb710c87 Remove ReservedObjectRector as requires explicit configuration and is handled by RenameClassRector already (#3975)
This commit is contained in:
Tomas Votruba 2023-05-26 13:14:15 +00:00
parent 11b175ef12
commit 1539fc211a
7 changed files with 15 additions and 168 deletions

View File

@ -1,4 +1,4 @@
# 398 Rules Overview
# 396 Rules Overview
<br>
@ -36,9 +36,9 @@
- [Php70](#php70) (19)
- [Php71](#php71) (9)
- [Php71](#php71) (8)
- [Php72](#php72) (10)
- [Php72](#php72) (9)
- [Php73](#php73) (9)
@ -4944,41 +4944,6 @@ Remove extra parameters
<br>
### ReservedObjectRector
Changes reserved "Object" name to "<Smart>Object" where <Smart> can be configured
:wrench: **configure it!**
- class: [`Rector\Php71\Rector\Name\ReservedObjectRector`](../rules/Php71/Rector/Name/ReservedObjectRector.php)
```php
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php71\Rector\Name\ReservedObjectRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ReservedObjectRector::class, [
'ReservedObject' => 'SmartObject',
'Object' => 'AnotherSmartObject',
]);
};
```
```diff
-class Object
+class SmartObject
{
}
```
<br>
## Php72
### CreateFunctionToAnonymousFunctionRector
@ -5022,20 +4987,6 @@ Null is no more allowed in `get_class()`
<br>
### IsObjectOnIncompleteClassRector
Incomplete class returns inverted bool on `is_object()`
- class: [`Rector\Php72\Rector\FuncCall\IsObjectOnIncompleteClassRector`](../rules/Php72/Rector/FuncCall/IsObjectOnIncompleteClassRector.php)
```diff
$incompleteObject = new __PHP_Incomplete_Class;
-$isObject = is_object($incompleteObject);
+$isObject = ! is_object($incompleteObject);
```
<br>
### ListEachRector
`each()` function is deprecated, use `key()` and `current()` instead

View File

@ -1,102 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Php71\Rector\Name;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Namespace_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202305\Webmozart\Assert\Assert;
/**
* @changelog https://wiki.php.net/rfc/object-typehint https://github.com/cebe/yii2/commit/9548a212ecf6e50fcdb0e5ba6daad88019cfc544
*
* @see \Rector\Tests\Php71\Rector\Name\ReservedObjectRector\ReservedObjectRectorTest
*/
final class ReservedObjectRector extends AbstractRector implements ConfigurableRectorInterface, MinPhpVersionInterface
{
/**
* @var array<string, string>
*/
private $reservedKeywordsToReplacements = [];
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::RESERVED_OBJECT_KEYWORD;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Changes reserved "Object" name to "<Smart>Object" where <Smart> can be configured', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
class Object
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SmartObject
{
}
CODE_SAMPLE
, ['ReservedObject' => 'SmartObject', 'Object' => 'AnotherSmartObject'])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Identifier::class, Name::class];
}
/**
* @param Identifier|Name $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof Identifier) {
return $this->processIdentifier($node);
}
return $this->processName($node);
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
Assert::allString(\array_keys($configuration));
Assert::allString($configuration);
$this->reservedKeywordsToReplacements = $configuration;
}
private function processIdentifier(Identifier $identifier) : Identifier
{
foreach ($this->reservedKeywordsToReplacements as $reservedKeyword => $replacement) {
if (!$this->isName($identifier, $reservedKeyword)) {
continue;
}
$identifier->name = $replacement;
return $identifier;
}
return $identifier;
}
private function processName(Name $name) : Name
{
// we look for "extends <Name>"
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
// "Object" can part of namespace name
if ($parentNode instanceof Namespace_) {
return $name;
}
// process lass part
foreach ($this->reservedKeywordsToReplacements as $reservedKeyword => $replacement) {
if (\strtolower($name->getLast()) === \strtolower($reservedKeyword)) {
$name->parts[\count($name->parts) - 1] = $replacement;
// invoke override
$name->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
return $name;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '6d4a73ed6e31a7fb64b547edad2270391ef03ca2';
public const PACKAGE_VERSION = 'c1cb710c872d25f5daa3fd085fc24640716a80f4';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-26 13:07:23';
public const RELEASE_DATE = '2023-05-26 13:10:17';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit885076ad0531d86ccc7e1e17b0cacc86::getLoader();
return ComposerAutoloaderInitfddc3b52116436b11ff580f5f26c1af4::getLoader();

View File

@ -2198,7 +2198,6 @@ return array(
'Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector' => $baseDir . '/rules/Php71/Rector/FuncCall/CountOnNullRector.php',
'Rector\\Php71\\Rector\\FuncCall\\RemoveExtraParametersRector' => $baseDir . '/rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php',
'Rector\\Php71\\Rector\\List_\\ListToArrayDestructRector' => $baseDir . '/rules/Php71/Rector/List_/ListToArrayDestructRector.php',
'Rector\\Php71\\Rector\\Name\\ReservedObjectRector' => $baseDir . '/rules/Php71/Rector/Name/ReservedObjectRector.php',
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => $baseDir . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
'Rector\\Php71\\ValueObject\\TwoNodeMatch' => $baseDir . '/rules/Php71/ValueObject/TwoNodeMatch.php',
'Rector\\Php72\\NodeFactory\\AnonymousFunctionFactory' => $baseDir . '/rules/Php72/NodeFactory/AnonymousFunctionFactory.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit885076ad0531d86ccc7e1e17b0cacc86
class ComposerAutoloaderInitfddc3b52116436b11ff580f5f26c1af4
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit885076ad0531d86ccc7e1e17b0cacc86
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit885076ad0531d86ccc7e1e17b0cacc86', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitfddc3b52116436b11ff580f5f26c1af4', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit885076ad0531d86ccc7e1e17b0cacc86', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitfddc3b52116436b11ff580f5f26c1af4', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86
class ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2440,7 +2440,6 @@ class ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86
'Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/FuncCall/CountOnNullRector.php',
'Rector\\Php71\\Rector\\FuncCall\\RemoveExtraParametersRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php',
'Rector\\Php71\\Rector\\List_\\ListToArrayDestructRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/List_/ListToArrayDestructRector.php',
'Rector\\Php71\\Rector\\Name\\ReservedObjectRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/Name/ReservedObjectRector.php',
'Rector\\Php71\\Rector\\TryCatch\\MultiExceptionCatchRector' => __DIR__ . '/../..' . '/rules/Php71/Rector/TryCatch/MultiExceptionCatchRector.php',
'Rector\\Php71\\ValueObject\\TwoNodeMatch' => __DIR__ . '/../..' . '/rules/Php71/ValueObject/TwoNodeMatch.php',
'Rector\\Php72\\NodeFactory\\AnonymousFunctionFactory' => __DIR__ . '/../..' . '/rules/Php72/NodeFactory/AnonymousFunctionFactory.php',
@ -3095,9 +3094,9 @@ class ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit885076ad0531d86ccc7e1e17b0cacc86::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfddc3b52116436b11ff580f5f26c1af4::$classMap;
}, null, ClassLoader::class);
}