mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 00:10:51 +00:00
Updated Rector to commit d30a86313f
d30a86313f
[Feature] Add configurable InlineSimplePropertyAnnotationRector for inlining of simple annotations (#2070)
This commit is contained in:
parent
446b0a8f86
commit
1f0de4d2de
|
@ -8,7 +8,7 @@
|
|||
|
||||
- [CodeQuality](#codequality) (70)
|
||||
|
||||
- [CodingStyle](#codingstyle) (34)
|
||||
- [CodingStyle](#codingstyle) (35)
|
||||
|
||||
- [Compatibility](#compatibility) (1)
|
||||
|
||||
|
@ -1917,6 +1917,47 @@ Refactor `func_get_args()` in to a variadic param
|
|||
|
||||
<br>
|
||||
|
||||
### InlineSimplePropertyAnnotationRector
|
||||
|
||||
Inline simple `@var` annotations (or other annotations) when they are the only thing in the phpdoc
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector`](../rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php)
|
||||
|
||||
```php
|
||||
use Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(InlineSimplePropertyAnnotationRector::class)
|
||||
->configure(['var', 'phpstan-var']);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
- /**
|
||||
- * @phpstan-var string
|
||||
- */
|
||||
+ /** @phpstan-var string */
|
||||
private const TEXT = 'text';
|
||||
|
||||
- /**
|
||||
- * @var DateTime[]
|
||||
- */
|
||||
+ /** @var DateTime[]|null */
|
||||
private ?array $dateTimes;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### MakeInheritedMethodVisibilitySameAsParentRector
|
||||
|
||||
Make method visibility same as parent one
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Property;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20220414\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\InlineSimplePropertyAnnotationRectorTest
|
||||
*/
|
||||
final class InlineSimplePropertyAnnotationRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $annotationsToConsiderForInlining = ['@var', '@phpstan-var', '@psalm-var'];
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Inline simple @var annotations (or other annotations) when they are the only thing in the phpdoc', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
/**
|
||||
* @phpstan-var string
|
||||
*/
|
||||
private const TEXT = 'text';
|
||||
|
||||
/**
|
||||
* @var DateTime[]
|
||||
*/
|
||||
private ?array $dateTimes;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
/** @phpstan-var string */
|
||||
private const TEXT = 'text';
|
||||
|
||||
/** @var DateTime[]|null */
|
||||
private ?array $dateTimes;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, ['var', 'phpstan-var'])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Property::class, \PhpParser\Node\Stmt\ClassConst::class];
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
\RectorPrefix20220414\Webmozart\Assert\Assert::allString($configuration);
|
||||
$this->annotationsToConsiderForInlining = \array_map(function (string $annotation) : string {
|
||||
return '@' . \ltrim($annotation, '@');
|
||||
}, $configuration);
|
||||
}
|
||||
/**
|
||||
* @param Property|ClassConst $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($this->shouldSkipNode($node)) {
|
||||
return null;
|
||||
}
|
||||
$comments = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::COMMENTS, []);
|
||||
if ((\is_array($comments) || $comments instanceof \Countable ? \count($comments) : 0) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
|
||||
$phpDocNode = $phpDocInfo->getPhpDocNode();
|
||||
$tags = $phpDocNode->getTags();
|
||||
if (\count($tags) !== 1) {
|
||||
return null;
|
||||
}
|
||||
$tag = $tags[0];
|
||||
if (!\in_array($tag->name, $this->annotationsToConsiderForInlining, \true)) {
|
||||
return null;
|
||||
}
|
||||
if (\strpos((string) $tag, "\n") !== \false) {
|
||||
return null;
|
||||
}
|
||||
// Handle edge cases where stringified tag is not same as it was originally
|
||||
/** @var Doc $comment */
|
||||
$comment = $comments[0];
|
||||
if (\strpos($comment->getText(), (string) $tag) === \false) {
|
||||
return null;
|
||||
}
|
||||
// Creating new node is the only way to enforce the "singleLined" property AFAIK
|
||||
$newPhpDocInfo = $this->phpDocInfoFactory->createEmpty($node);
|
||||
$newPhpDocInfo->makeSingleLined();
|
||||
$newPhpDocNode = $newPhpDocInfo->getPhpDocNode();
|
||||
$newPhpDocNode->children = [$tag];
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\Property $node
|
||||
*/
|
||||
private function shouldSkipNode($node) : bool
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Property && \count($node->props) !== 1) {
|
||||
return \true;
|
||||
}
|
||||
return $node instanceof \PhpParser\Node\Stmt\ClassConst && \count($node->consts) !== 1;
|
||||
}
|
||||
}
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'c50992351682af007606cb020cb4cdd19b749953';
|
||||
public const PACKAGE_VERSION = 'd30a86313f34e4d10a59910d8bfd1b588f329fe5';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-04-14 10:03:45';
|
||||
public const RELEASE_DATE = '2022-04-14 10:06:16';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20220414\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a::getLoader();
|
||||
return ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1594,6 +1594,7 @@ return array(
|
|||
'Rector\\CodingStyle\\Rector\\Plus\\UseIncrementAssignRector' => $baseDir . '/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\PostInc\\PostIncDecToPreIncDecRector' => $baseDir . '/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\AddFalseDefaultToBoolPropertyRector' => $baseDir . '/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\InlineSimplePropertyAnnotationRector' => $baseDir . '/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\NewlineAfterStatementRector' => $baseDir . '/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\SymplifyQuoteEscapeRector' => $baseDir . '/rules/CodingStyle/Rector/String_/SymplifyQuoteEscapeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\UseClassKeywordForClassNameResolutionRector' => $baseDir . '/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
||||
class ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire65d165cdbbdb7e4a70b4abb4e9b7f69a($fileIdentifier, $file);
|
||||
composerRequire1e57686944afa2e7ecd607002e1b2ac2($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire65d165cdbbdb7e4a70b4abb4e9b7f69a($fileIdentifier, $file)
|
||||
function composerRequire1e57686944afa2e7ecd607002e1b2ac2($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
||||
class ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2
|
||||
{
|
||||
public static $files = array (
|
||||
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
|
||||
|
@ -1963,6 +1963,7 @@ class ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
|||
'Rector\\CodingStyle\\Rector\\Plus\\UseIncrementAssignRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Plus/UseIncrementAssignRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\PostInc\\PostIncDecToPreIncDecRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\AddFalseDefaultToBoolPropertyRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Property/AddFalseDefaultToBoolPropertyRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Property\\InlineSimplePropertyAnnotationRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Property/InlineSimplePropertyAnnotationRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Stmt\\NewlineAfterStatementRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\SymplifyQuoteEscapeRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/String_/SymplifyQuoteEscapeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\String_\\UseClassKeywordForClassNameResolutionRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php',
|
||||
|
@ -3864,9 +3865,9 @@ class ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit65d165cdbbdb7e4a70b4abb4e9b7f69a::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1e57686944afa2e7ecd607002e1b2ac2::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20220414\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a', false) && !interface_exists('ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a', false) && !trait_exists('ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a', false)) {
|
||||
spl_autoload_call('RectorPrefix20220414\ComposerAutoloaderInit65d165cdbbdb7e4a70b4abb4e9b7f69a');
|
||||
if (!class_exists('ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2', false) && !interface_exists('ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2', false) && !trait_exists('ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2', false)) {
|
||||
spl_autoload_call('RectorPrefix20220414\ComposerAutoloaderInit1e57686944afa2e7ecd607002e1b2ac2');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20220414\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20220414\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire65d165cdbbdb7e4a70b4abb4e9b7f69a')) {
|
||||
function composerRequire65d165cdbbdb7e4a70b4abb4e9b7f69a() {
|
||||
return \RectorPrefix20220414\composerRequire65d165cdbbdb7e4a70b4abb4e9b7f69a(...func_get_args());
|
||||
if (!function_exists('composerRequire1e57686944afa2e7ecd607002e1b2ac2')) {
|
||||
function composerRequire1e57686944afa2e7ecd607002e1b2ac2() {
|
||||
return \RectorPrefix20220414\composerRequire1e57686944afa2e7ecd607002e1b2ac2(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user