mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
Updated Rector to commit f74bdede72ab3a95dfa5f8670b369c2d4cd2e4db
f74bdede72
[CodingStyle] Deprecate PHPStormVarAnnotationRector, rather tokens responsibility (#2677)
This commit is contained in:
parent
c855f5df1c
commit
e67795209e
|
@ -4,7 +4,6 @@ declare (strict_types=1);
|
|||
namespace RectorPrefix202207;
|
||||
|
||||
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
|
||||
use Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector;
|
||||
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
|
||||
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
|
||||
use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
|
||||
|
@ -36,5 +35,5 @@ use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
|
|||
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->ruleWithConfiguration(FuncCallToConstFetchRector::class, ['php_sapi_name' => 'PHP_SAPI', 'pi' => 'M_PI']);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, RemoveDoubleUnderscoreInMethodNameRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, PHPStormVarAnnotationRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, SplitGroupedConstantsAndPropertiesRector::class, StringClassNameToClassConstantRector::class, ConsistentPregDelimiterRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class]);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, RemoveDoubleUnderscoreInMethodNameRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, SplitGroupedConstantsAndPropertiesRector::class, StringClassNameToClassConstantRector::class, ConsistentPregDelimiterRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class]);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 414 Rules Overview
|
||||
# 413 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
- [CodeQuality](#codequality) (73)
|
||||
|
||||
- [CodingStyle](#codingstyle) (37)
|
||||
- [CodingStyle](#codingstyle) (36)
|
||||
|
||||
- [Compatibility](#compatibility) (1)
|
||||
|
||||
|
@ -2123,21 +2123,6 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
<br>
|
||||
|
||||
### PHPStormVarAnnotationRector
|
||||
|
||||
Change various `@var` annotation formats to one PHPStorm understands
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector`](../rules/CodingStyle/Rector/Assign/PHPStormVarAnnotationRector.php)
|
||||
|
||||
```diff
|
||||
-$config = 5;
|
||||
-/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
|
||||
+/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
|
||||
+$config = 5;
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### PostIncDecToPreIncDecRector
|
||||
|
||||
Use ++$value or --$value instead of `$value++` or `$value--`
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Assign;
|
||||
|
||||
use RectorPrefix202207\Nette\Utils\Strings;
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Nop;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Util\StringUtils;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/shopsys/shopsys/pull/524
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector\PHPStormVarAnnotationRectorTest
|
||||
*/
|
||||
final class PHPStormVarAnnotationRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/YY5stJ/1
|
||||
*/
|
||||
private const SINGLE_ASTERISK_COMMENT_START_REGEX = '#^\\/\\* #';
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/meD7rP/1
|
||||
*/
|
||||
private const VAR_ANNOTATION_REGEX = '#\\@var(\\s)+\\$#';
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/yz2AZ7/1
|
||||
*/
|
||||
private const VARIABLE_NAME_AND_TYPE_MATCH_REGEX = '#(?<variableName>\\$\\w+)(?<space>\\s+)(?<type>[\\\\\\w]+)#';
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change various @var annotation formats to one PHPStorm understands', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
$config = 5;
|
||||
/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
/** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */
|
||||
$config = 5;
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Assign::class];
|
||||
}
|
||||
/**
|
||||
* @param Assign $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node);
|
||||
// unable to analyze
|
||||
if (!$currentStmt instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
$nextNode = $currentStmt->getAttribute(AttributeKey::NEXT_NODE);
|
||||
if (!$nextNode instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
$docContent = $this->getDocContent($nextNode);
|
||||
if ($docContent === '') {
|
||||
return null;
|
||||
}
|
||||
if (\strpos($docContent, '@var') === \false) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
$varName = '$' . $this->getName($node->var);
|
||||
$varPattern = '# ' . \preg_quote($varName, '#') . ' #';
|
||||
if (!StringUtils::isMatch($docContent, $varPattern)) {
|
||||
return null;
|
||||
}
|
||||
// switch docs
|
||||
$currentStmt->setDocComment($this->createDocComment($nextNode));
|
||||
$expressionPhpDocInfo = $this->phpDocInfoFactory->createFromNode($currentStmt);
|
||||
$currentStmt->setAttribute(AttributeKey::PHP_DOC_INFO, $expressionPhpDocInfo);
|
||||
// invoke override
|
||||
$currentStmt->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
// remove otherwise empty node
|
||||
if ($nextNode instanceof Nop) {
|
||||
$this->removeNode($nextNode);
|
||||
return null;
|
||||
}
|
||||
// remove commnets
|
||||
$nextNode->setAttribute(AttributeKey::PHP_DOC_INFO, null);
|
||||
$nextNode->setAttribute(AttributeKey::COMMENTS, null);
|
||||
return $node;
|
||||
}
|
||||
private function getDocContent(Node $node) : string
|
||||
{
|
||||
$docComment = $node->getDocComment();
|
||||
if ($docComment !== null) {
|
||||
return $docComment->getText();
|
||||
}
|
||||
if ($node->getComments() !== []) {
|
||||
$docContent = '';
|
||||
foreach ($node->getComments() as $comment) {
|
||||
$docContent .= $comment->getText();
|
||||
}
|
||||
return $docContent;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
private function createDocComment(Node $node) : Doc
|
||||
{
|
||||
if ($node->getDocComment() !== null) {
|
||||
return $node->getDocComment();
|
||||
}
|
||||
$docContent = $this->getDocContent($node);
|
||||
// normalize content
|
||||
// starts with "/*", instead of "/**"
|
||||
if (\strncmp($docContent, '/* ', \strlen('/* ')) === 0) {
|
||||
$docContent = Strings::replace($docContent, self::SINGLE_ASTERISK_COMMENT_START_REGEX, '/** ');
|
||||
}
|
||||
// $value is first, instead of type is first
|
||||
if (StringUtils::isMatch($docContent, self::VAR_ANNOTATION_REGEX)) {
|
||||
$docContent = Strings::replace($docContent, self::VARIABLE_NAME_AND_TYPE_MATCH_REGEX, '$3$2$1');
|
||||
}
|
||||
return new Doc($docContent);
|
||||
}
|
||||
}
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6d7404c65000caede512a5bc5a993f472e11cd0d';
|
||||
public const PACKAGE_VERSION = 'f74bdede72ab3a95dfa5f8670b369c2d4cd2e4db';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-07-18 17:20:13';
|
||||
public const RELEASE_DATE = '2022-07-18 15:26:30';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
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 ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91::getLoader();
|
||||
return ComposerAutoloaderInitdb94cf5b9d1c5a6e1da2724db76a582a::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1427,7 +1427,6 @@ return array(
|
|||
'Rector\\CodingStyle\\NodeFactory\\ArrayCallableToMethodCallFactory' => $baseDir . '/rules/CodingStyle/NodeFactory/ArrayCallableToMethodCallFactory.php',
|
||||
'Rector\\CodingStyle\\Node\\NameImporter' => $baseDir . '/rules/CodingStyle/Node/NameImporter.php',
|
||||
'Rector\\CodingStyle\\Rector\\ArrowFunction\\StaticArrowFunctionRector' => $baseDir . '/rules/CodingStyle/Rector/ArrowFunction/StaticArrowFunctionRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Assign\\PHPStormVarAnnotationRector' => $baseDir . '/rules/CodingStyle/Rector/Assign/PHPStormVarAnnotationRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Assign\\SplitDoubleAssignRector' => $baseDir . '/rules/CodingStyle/Rector/Assign/SplitDoubleAssignRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Catch_\\CatchExceptionNameMatchingTypeRector' => $baseDir . '/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassConst\\RemoveFinalFromConstRector' => $baseDir . '/rules/CodingStyle/Rector/ClassConst/RemoveFinalFromConstRector.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 ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91
|
||||
class ComposerAutoloaderInitdb94cf5b9d1c5a6e1da2724db76a582a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitdb94cf5b9d1c5a6e1da2724db76a582a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitdb94cf5b9d1c5a6e1da2724db76a582a', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5049e14e14f7b10d90943ba518db8e91::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit5049e14e14f7b10d90943ba518db8e91::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire5049e14e14f7b10d90943ba518db8e91($fileIdentifier, $file);
|
||||
composerRequiredb94cf5b9d1c5a6e1da2724db76a582a($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit5049e14e14f7b10d90943ba518db8e91
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire5049e14e14f7b10d90943ba518db8e91($fileIdentifier, $file)
|
||||
function composerRequiredb94cf5b9d1c5a6e1da2724db76a582a($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 ComposerStaticInit5049e14e14f7b10d90943ba518db8e91
|
||||
class ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -1734,7 +1734,6 @@ class ComposerStaticInit5049e14e14f7b10d90943ba518db8e91
|
|||
'Rector\\CodingStyle\\NodeFactory\\ArrayCallableToMethodCallFactory' => __DIR__ . '/../..' . '/rules/CodingStyle/NodeFactory/ArrayCallableToMethodCallFactory.php',
|
||||
'Rector\\CodingStyle\\Node\\NameImporter' => __DIR__ . '/../..' . '/rules/CodingStyle/Node/NameImporter.php',
|
||||
'Rector\\CodingStyle\\Rector\\ArrowFunction\\StaticArrowFunctionRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ArrowFunction/StaticArrowFunctionRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Assign\\PHPStormVarAnnotationRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Assign/PHPStormVarAnnotationRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Assign\\SplitDoubleAssignRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Assign/SplitDoubleAssignRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Catch_\\CatchExceptionNameMatchingTypeRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassConst\\RemoveFinalFromConstRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassConst/RemoveFinalFromConstRector.php',
|
||||
|
@ -3415,9 +3414,9 @@ class ComposerStaticInit5049e14e14f7b10d90943ba518db8e91
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5049e14e14f7b10d90943ba518db8e91::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5049e14e14f7b10d90943ba518db8e91::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5049e14e14f7b10d90943ba518db8e91::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitdb94cf5b9d1c5a6e1da2724db76a582a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user