[CodingStyle] Move PHPStormVarAnnotationRector (#4985)

* [CodingStyle] Move PHPStormVarAnnotationRector

* [ci-review] Rector Rectify

* [DeadDocBlock] Move RemoveNonExistingVarAnnotationRector here (#4984)

* [DeadDocBlock] Move RemoveNonExistingVarAnnotationRector here

* [ci-review] Rector Rectify

Co-authored-by: rector-bot <tomas@getrector.org>

* [ci-review] Rector Rectify

* cleanup docs

* static fixes

* [ci-review] Rector Rectify

* remove duplicated

* multi use case

* misc

* [ci-review] Rector Rectify

* fixes

* remove order set, slow

* move UseMessageVariableForSprintfInSymfonyStyleRector from solid set to coding-style

* make unique-named variables to prevent accidental override and improve readability

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2020-12-25 14:20:13 +01:00 committed by GitHub
parent ec5daad132
commit cffd7ea0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 136 additions and 116 deletions

View File

@ -119,7 +119,6 @@
"Rector\\Order\\": "rules/order/src",
"Rector\\PHPOffice\\": "rules/php-office/src",
"Rector\\PHPStanStaticTypeMapper\\": "packages/phpstan-static-type-mapper/src",
"Rector\\PHPStan\\": "rules/phpstan/src",
"Rector\\PHPUnitSymfony\\": "rules/phpunit-symfony/src",
"Rector\\PHPUnit\\": "rules/phpunit/src",
"Rector\\PSR4\\": "rules/psr4/src",
@ -244,7 +243,6 @@
"Rector\\PHPStanExtensions\\Tests\\": "utils/phpstan-extensions/tests",
"Rector\\PHPStanStaticTypeMapper\\Tests\\": "packages/phpstan-static-type-mapper/tests",
"Rector\\StaticTypeMapper\\Tests\\": "packages/static-type-mapper/tests",
"Rector\\PHPStan\\Tests\\": "rules/phpstan/tests",
"Rector\\PHPUnitSymfony\\Tests\\": "rules/phpunit-symfony/tests",
"Rector\\PHPUnit\\Tests\\": "rules/phpunit/tests",
"Rector\\PSR4\\Tests\\": "rules/psr4/tests",

View File

@ -3,6 +3,7 @@
declare(strict_types=1);
use Rector\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector;
use Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector;
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
@ -21,6 +22,7 @@ use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
use Rector\CodingStyle\Rector\Function_\CamelCaseFunctionNamingToUnderscoreRector;
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
use Rector\CodingStyle\Rector\Include_\FollowRequireByDirRector;
use Rector\CodingStyle\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector;
use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector;
@ -35,6 +37,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(PHPStormVarAnnotationRector::class);
$services->set(NullableCompareToNullRector::class);
$services->set(BinarySwitchToIfElseRector::class);
$services->set(ConsistentImplodeRector::class);
@ -58,6 +61,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
$services->set(CallUserFuncCallToVariadicRector::class);
$services->set(VersionCompareFuncCallToConstantRector::class);
$services->set(UseMessageVariableForSprintfInSymfonyStyleRector::class);
$services->set(FunctionCallToConstantRector::class)
->call('configure', [[

View File

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
use Rector\PHPStan\Rector\Assign\PHPStormVarAnnotationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(PHPStormVarAnnotationRector::class);
};

View File

@ -2,7 +2,6 @@
declare(strict_types=1);
use Rector\CodingStyle\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector;
use Rector\SOLID\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector;
use Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\SOLID\Rector\Class_\MakeUnusedClassesWithChildrenAbstractRector;
@ -21,6 +20,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ChangeReadOnlyVariableWithDefaultValueToConstantRector::class);
$services->set(AddFalseDefaultToBoolPropertyRector::class);
$services->set(RepeatedLiteralToClassConstantRector::class);
$services->set(UseMessageVariableForSprintfInSymfonyStyleRector::class);
$services->set(MoveVariableDeclarationNearReferenceRector::class);
};

View File

@ -9882,7 +9882,7 @@ Remove `setTempDir()` on PHPExcel_Writer_Excel5
Change various `@var` annotation formats to one PHPStorm understands
- class: `Rector\PHPStan\Rector\Assign\PHPStormVarAnnotationRector`
- class: `Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector`
```diff
-$config = 5;

View File

@ -164,18 +164,15 @@ final class PhpDocInfo
{
$name = StaticAnnotationNaming::normalizeName($name);
/** @var AttributeAwareNodeInterface[]|PhpDocTagNode[] $tags */
/** @var PhpDocTagNode[]|AttributeAwareNodeInterface[] $tags */
$tags = $this->phpDocNode->getTags();
$tags = array_filter($tags, function (PhpDocTagNode $tag) use ($name): bool {
return $tag->name === $name;
});
// @todo add dynamic function type resolver to PHPStan, the same type on input is on output
$tags = array_values($tags);
/** @var PhpDocTagNode[]|AttributeAwareNodeInterface[] $tags */
return $tags;
return array_values($tags);
}
public function getParamType(string $name): Type

View File

@ -299,9 +299,7 @@ final class NodeRepository
return [];
}
/** @var string $propertyName */
$propertyName = $this->nodeNameResolver->getName($property);
return $this->parsedPropertyFetchNodeCollector->findPropertyFetchesByTypeAndName($className, $propertyName);
}

View File

@ -109,7 +109,6 @@ final class ParamTypeResolver implements NodeTypeResolverInterface
return new MixedType();
}
/** @var string $paramName */
$paramName = $this->nodeNameResolver->getName($param);
$paramStaticType = new MixedType();
@ -141,7 +140,6 @@ final class ParamTypeResolver implements NodeTypeResolverInterface
return new MixedType();
}
/** @var string $paramName */
$paramName = $this->nodeNameResolver->getName($param);
return $phpDocInfo->getParamType($paramName);
}

View File

@ -43,9 +43,9 @@ final class TemplateFinder
$filePaths[] = __DIR__ . '/../../templates/rules/__package__/tests/Rector/__Category__/__Name__/Source/extra_file.php.inc';
}
/** @var string[] $filePaths */
$filePaths = $this->addRuleAndTestCase($rectorRecipe, $filePaths);
/** @var string[] $filePaths */
$filePaths[] = $this->resolveFixtureFilePath();
$this->ensureFilePathsExists($filePaths);

View File

@ -406,11 +406,6 @@ final class SetList
*/
public const PHPSPEC_TO_PHPUNIT = __DIR__ . '/../../../../config/set/phpspec-to-phpunit.php';
/**
* @var string
*/
public const PHPSTAN = __DIR__ . '/../../../../config/set/phpstan.php';
/**
* @var string
*/

View File

@ -453,7 +453,7 @@ parameters:
- src/Rector/AbstractRector.php
- src/PhpParser/NodeTransformer.php
# playing around with doc block format
- rules/phpstan/src/Rector/Assign/PHPStormVarAnnotationRector.php
- rules/coding-style/src/Rector/Assign/PHPStormVarAnnotationRector.php
- rules/code-quality/src/Rector/Return_/SimplifyUselessVariableRector.php
- rules/dead-code/src/Rector/Expression/RemoveDeadStmtRector.php
- rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php

View File

@ -49,7 +49,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
SetList::SOLID,
SetList::PRIVATIZATION,
SetList::NAMING,
SetList::ORDER,
SetList::DEFLUENT,
SetList::TYPE_DECLARATION,
SetList::PHPUNIT_CODE_QUALITY,

View File

@ -69,8 +69,6 @@ CODE_SAMPLE
public function refactor(Node $node): ?Node
{
$names = $this->findNames($node);
/** @var Name[] $names */
if ($names === []) {
return null;
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\PHPStan\Rector\Assign;
namespace Rector\CodingStyle\Rector\Assign;
use Nette\Utils\Strings;
use PhpParser\Comment\Doc;
@ -18,7 +18,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/shopsys/shopsys/pull/524
* @see \Rector\PHPStan\Tests\Rector\Assign\PHPStormVarAnnotationRector\PHPStormVarAnnotationRectorTest
* @see \Rector\CodingStyle\Tests\Rector\Assign\PHPStormVarAnnotationRector\PHPStormVarAnnotationRectorTest
*/
final class PHPStormVarAnnotationRector extends AbstractRector
{

View File

@ -20,7 +20,7 @@ final class UseMessageVariableForSprintfInSymfonyStyleRector extends AbstractRec
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Decouple $message property from sprintf() calls in $this->smyfonyStyle->method()',
'Decouple $message property from sprintf() calls in $this->symfonyStyle->method()',
[
new CodeSample(
<<<'CODE_SAMPLE'

View File

@ -2,10 +2,10 @@
declare(strict_types=1);
namespace Rector\PHPStan\Tests\Rector\Assign\PHPStormVarAnnotationRector;
namespace Rector\CodingStyle\Tests\Rector\Assign\PHPStormVarAnnotationRector;
use Iterator;
use Rector\PHPStan\Rector\Assign\PHPStormVarAnnotationRector;
use Rector\CodingStyle\Rector\Assign\PHPStormVarAnnotationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -32,7 +32,7 @@ final class PreviousVariableAssignNodeFinder
$currentAssign = $assign;
$variableName = $this->nodeNameResolver->getName($assign->var);
$assign = $this->betterNodeFinder->findFirstPrevious($assign, function (Node $node) use (
return $this->betterNodeFinder->findFirstPrevious($assign, function (Node $node) use (
$variableName,
$currentAssign
): bool {
@ -47,8 +47,5 @@ final class PreviousVariableAssignNodeFinder
return $this->nodeNameResolver->isName($node->var, $variableName);
});
/** @var Assign|null $assign */
return $assign;
}
}

View File

@ -93,11 +93,13 @@ CODE_SAMPLE
*/
private function filterItemsWithSameKey(array $arrayItemsByKeys): array
{
/** @var ArrayItem[][] $arrayItemsByKeys */
$arrayItemsByKeys = array_filter($arrayItemsByKeys, function (array $arrayItems): bool {
return count($arrayItems) > 1;
});
/** @var ArrayItem[][] $arrayItemsByKeys */
return $arrayItemsByKeys;
return array_filter($arrayItemsByKeys, function (array $arrayItems): bool {
return count($arrayItems) > 1;
});
}
}

View File

@ -67,6 +67,7 @@ final class UnusedClassResolver
return $this->cachedUsedClassNames;
}
/** @var string[] $cachedUsedClassNames */
$cachedUsedClassNames = array_merge(
$this->getParamNodesClassNames(),
$this->getNewNodesClassNames(),
@ -76,7 +77,6 @@ final class UnusedClassResolver
$cachedUsedClassNames = $this->sortAndUniqueArray($cachedUsedClassNames);
/** @var string[] $cachedUsedClassNames */
$this->cachedUsedClassNames = $cachedUsedClassNames;
return $this->cachedUsedClassNames;

View File

@ -173,8 +173,7 @@ final class FluentChainMethodCallNodeAnalyzer
$methods = array_reverse($methods);
foreach ($methods as $method) {
$activeMethodName = $this->nodeNameResolver->getName($node->name);
if ($activeMethodName !== $method) {
if (! $this->nodeNameResolver->isName($node->name, $method)) {
return false;
}

View File

@ -60,8 +60,8 @@ final class FluentChainMethodCallRootExtractorTest extends AbstractKernelTestCas
$this->assertFalse($assignAndRootExpr->isFirstCallFactory());
$silentVariable = $assignAndRootExpr->getSilentVariable();
/** @var Variable $silentVariable */
$silentVariable = $assignAndRootExpr->getSilentVariable();
$this->assertInstanceOf(Variable::class, $silentVariable);
$this->assertIsString($silentVariable->name);

View File

@ -43,7 +43,6 @@ final class ConstructorAssignPropertyAnalyzer
return null;
}
/** @var string $propertyName */
$propertyName = $this->nodeNameResolver->getName($property);
return $this->betterNodeFinder->findFirst((array) $constructClassMethod->stmts, function (Node $node) use (

View File

@ -238,10 +238,8 @@ final class PropertyNaming
private function prolongIfTooShort(string $shortClassName, string $className): string
{
if (in_array($shortClassName, ['Factory', 'Repository'], true)) {
/** @var string $namespaceAbove */
$namespaceAbove = Strings::after($className, '\\', -2);
/** @var string $namespaceAbove */
$namespaceAbove = Strings::before($namespaceAbove, '\\');
$namespaceAbove = (string) Strings::after($className, '\\', -2);
$namespaceAbove = (string) Strings::before($namespaceAbove, '\\');
return lcfirst($namespaceAbove) . $shortClassName;
}

View File

@ -27,9 +27,9 @@ final class FunctionLikeFirstLevelStatementResolver
public function resolveFirstLevelStatement(Node $node): Node
{
$multiplierClosure = $this->matchMultiplierClosure($node);
/** @var ClassMethod|Closure|null $functionLike */
$functionLike = $multiplierClosure ?? $this->parentScopeFinder->find($node);
/** @var ClassMethod|Closure|null $functionLike */
if ($functionLike === null) {
throw new ShouldNotHappenException();
}

View File

@ -329,7 +329,6 @@ CODE_SAMPLE
/** @var string $presenterPart */
$presenterPart = Strings::after($presenterName, '\\', -1);
/** @var string $presenterPart */
$presenterPart = Strings::substring($presenterPart, 0, -Strings::length('Presenter'));
$presenterPart = StaticRectorStrings::camelCaseToDashes($presenterPart);

View File

@ -44,13 +44,13 @@ final class IsArrayAndDualCheckToAble
return null;
}
/** @var Instanceof_ $instanceOfNode */
$instanceOfNode = $twoNodeMatch->getFirstExpr();
/** @var Instanceof_ $instanceOf */
$instanceOf = $twoNodeMatch->getFirstExpr();
/** @var FuncCall $funcCallNode */
$funcCallNode = $twoNodeMatch->getSecondExpr();
/** @var FuncCall $funcCall */
$funcCall = $twoNodeMatch->getSecondExpr();
$instanceOfClass = $instanceOfNode->class;
$instanceOfClass = $instanceOf->class;
if ($instanceOfClass instanceof Expr) {
return null;
}
@ -58,26 +58,25 @@ final class IsArrayAndDualCheckToAble
if ((string) $instanceOfClass !== $type) {
return null;
}
$nodeNameResolverGetName = $this->nodeNameResolver->getName($funcCallNode);
if ($nodeNameResolverGetName !== 'is_array') {
if (! $this->nodeNameResolver->isName($funcCall, 'is_array')) {
return null;
}
// both use same var
if (! $funcCallNode->args[0]->value instanceof Variable) {
if (! $funcCall->args[0]->value instanceof Variable) {
return null;
}
/** @var Variable $firstVarNode */
$firstVarNode = $funcCallNode->args[0]->value;
$firstVarNode = $funcCall->args[0]->value;
if (! $instanceOfNode->expr instanceof Variable) {
if (! $instanceOf->expr instanceof Variable) {
return null;
}
/** @var Variable $secondVarNode */
$secondVarNode = $instanceOfNode->expr;
$secondVarNode = $instanceOf->expr;
// are they same variables
if ($firstVarNode->name !== $secondVarNode->name) {

View File

@ -268,51 +268,60 @@ CODE_SAMPLE
private function getNullSafeOnPrevAssignIsIf(If_ $if, Node $nextNode, ?Expr $expr): ?Expr
{
$prevIf = $if->getAttribute(AttributeKey::PREVIOUS_NODE);
if ($prevIf instanceof Expression && $this->ifManipulator->isIfCondUsingAssignIdenticalVariable(
$if,
$prevIf->expr
)) {
$start = $prevIf;
while ($prevIf instanceof Expression) {
$expr = $this->nullsafeManipulator->processNullSafeExpr($prevIf->expr->expr);
/** @var If_ $prevIf */
$prevIf = $prevIf->getAttribute(AttributeKey::PREVIOUS_NODE);
$prevIf = $prevIf->getAttribute(AttributeKey::PREVIOUS_NODE);
if (! $prevIf instanceof Expression) {
$start = $this->getStartNode($prevIf);
break;
}
}
if (! $expr instanceof NullsafeMethodCall && ! $expr instanceof NullsafePropertyFetch) {
return $expr;
}
/** @var Expr $expr */
$expr = $expr->var->getAttribute(AttributeKey::PARENT_NODE);
$expr = $this->getNullSafeAfterStartUntilBeforeEnd($start, $expr);
$expr = $this->nullsafeManipulator->processNullSafeExprResult($expr, $nextNode->expr->name);
if (! $prevIf instanceof Expression) {
return $expr;
}
return $expr;
if (! $this->ifManipulator->isIfCondUsingAssignIdenticalVariable($if, $prevIf->expr)) {
return $expr;
}
$start = $prevIf;
while ($prevIf instanceof Expression) {
$expressionNode = $prevIf->expr;
if (! $expressionNode instanceof Assign) {
return null;
}
$expr = $this->nullsafeManipulator->processNullSafeExpr($expressionNode->expr);
/** @var Node $prevPrevIf */
$prevPrevIf = $prevIf->getAttribute(AttributeKey::PREVIOUS_NODE);
/** @var Node $prevPrevPrevIf */
$prevPrevPrevIf = $prevPrevIf->getAttribute(AttributeKey::PREVIOUS_NODE);
if (! $prevPrevPrevIf instanceof Expression && $prevPrevPrevIf !== null) {
$start = $this->getPreviousIf($prevPrevPrevIf);
break;
}
$prevIf = $prevPrevPrevIf;
}
if (! $expr instanceof NullsafeMethodCall && ! $expr instanceof NullsafePropertyFetch) {
return $expr;
}
/** @var Expr $expr */
$expr = $expr->var->getAttribute(AttributeKey::PARENT_NODE);
$expr = $this->getNullSafeAfterStartUntilBeforeEnd($start, $expr);
return $this->nullsafeManipulator->processNullSafeExprResult($expr, $nextNode->expr->name);
}
private function getStartNode(Node $node): ?Node
private function getPreviousIf(Node $node): ?Node
{
/** @var If_ $start */
$start = $node->getAttribute(AttributeKey::NEXT_NODE);
/** @var If_ $if */
$if = $node->getAttribute(AttributeKey::NEXT_NODE);
/** @var Expression $start */
$start = $start->getAttribute(AttributeKey::NEXT_NODE);
/** @var Expression $expression */
$expression = $if->getAttribute(AttributeKey::NEXT_NODE);
/** @var If_ $start */
$start = $start->getAttribute(AttributeKey::NEXT_NODE);
/** @var Expression $nextExpression */
$nextExpression = $expression->getAttribute(AttributeKey::NEXT_NODE);
/** @var Expression $start */
return $start->getAttribute(AttributeKey::NEXT_NODE);
return $nextExpression->getAttribute(AttributeKey::NEXT_NODE);
}
private function getNullSafeAfterStartUntilBeforeEnd(?Node $node, ?Expr $expr): ?Expr

View File

@ -0,0 +1,42 @@
<?php
namespace Rector\Php80\Tests\Rector\If_\NullsafeOperatorRector\Fixture;
class SoooManyNullChecks
{
public function f($main)
{
$o2 = $main->mayFail1();
if ($o2 === null) {
return null;
}
$o3 = $o2->mayFail2();
if (null === $o3) {
return null;
}
$o4 = $o3->mayFail3();
if (null === $o4) {
return null;
}
return $o4->mayFail4();
}
}
?>
-----
<?php
namespace Rector\Php80\Tests\Rector\If_\NullsafeOperatorRector\Fixture;
class SoooManyNullChecks
{
public function f($main)
{
return $main->mayFail1()?->mayFail2()?->mayFail3()?->mayFail4();
}
}
?>

View File

@ -67,12 +67,12 @@ CODE_SAMPLE
return null;
}
/** @var MethodCall|null $getMockBuilderMethodCall */
$getMockBuilderMethodCall = $this->isName(
$node->var->name,
'disableOriginalConstructor'
) ? $node->var->var : $node->var;
/** @var MethodCall|null $getMockBuilderMethodCall */
if ($getMockBuilderMethodCall === null) {
return null;
}

View File

@ -33,9 +33,9 @@ final class ExistingClassesProvider
if ($this->existingClasses === []) {
$psr4Paths = $this->getPsr4PathFromComposerJson();
/** @var string[] $existingClasses */
$existingClasses = $this->findClassesInDirectories($psr4Paths);
/** @var string[] $existingClasses */
$existingClasses = array_merge($existingClasses, get_declared_classes());
$this->existingClasses = $existingClasses;

View File

@ -55,10 +55,9 @@ final class PropertyNodeParamTypeInferer extends AbstractTypeInferer implements
return null;
}
/** @var Assign $node */
/** @var Type|null $staticType */
$staticType = $this->nodeTypeResolver->getStaticType($node->var);
/** @var Type|null $staticType */
if ($staticType !== null) {
$propertyStaticTypes[] = $staticType;
}

View File

@ -4,9 +4,10 @@ sonar.projectKey=rectorphp_rector
# relative paths to source
# wildcards don't work :(
sonar.sources=src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,packages/file-system-rector/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,rules/phpstan/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,rules/solid/src,rules/sensio/src,packages/static-type-mapper/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,rules/polyfill/src,rules/generic/src
sonar.sources=src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,packages/file-system-rector/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,rules/solid/src,rules/sensio/src,packages/static-type-mapper/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,rules/polyfill/src,rules/generic/src
sonar.sources=src,rules/autodiscovery/src,rules/architecture/src,packages/attribute-aware-php-doc/src,packages/better-php-doc-parser/src,rules/cakephp/src,rules/code-quality/src,rules/coding-style/src,packages/console-differ/src,rules/dead-code/src,rules/doctrine/src,rules/doctrine-code-quality/src,packages/file-system-rector/src,rules/laravel/src,rules/legacy/src,rules/mysql-to-mysqli/src,rules/nette-tester-to-phpunit/src,rules/nette-to-symfony/src,rules/nette/src,packages/node-collector/src,packages/node-type-resolver/src,packages/node-name-resolver/src,packages/phpstan-static-type-mapper/src,rules/phpunit-symfony/src,rules/phpunit/src,rules/psr4/src,rules/php-spec-to-phpunit/src,rules/php52/src,rules/php53/src,rules/php54/src,rules/php55/src,rules/php56/src,rules/php70/src,rules/php71/src,rules/php72/src,rules/php73/src,rules/php74/src,rules/php80/src,rules/removing-static/src,rules/renaming/src,rules/restoration/src,rules/solid/src,rules/sensio/src,packages/static-type-mapper/src,rules/symfony-code-quality/src,rules/symfony-phpunit/src,rules/symfony/src,rules/twig/src,rules/type-declaration/src,packages/vendor-locker/src,packages/rector-generator/src,rules/strict-code-quality/src,rules/php-deglobalize/src,rules/phalcon/src,rules/doctrine-gedmo-to-knplabs/src,rules/polyfill/src,rules/generic/src
sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpstan/tests,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/node-documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,rules/polyfill/tests,rules/generic/tests
sonar.tests=tests,rules/autodiscovery/tests,rules/architecture/tests,packages/better-php-doc-parser/tests,rules/cakephp/tests,rules/code-quality/tests,rules/coding-style/tests,rules/dead-code/tests,rules/doctrine/tests,rules/doctrine-code-quality/tests,rules/laravel/tests,rules/legacy/tests,rules/mysql-to-mysqli/tests,rules/nette-tester-to-phpunit/tests,rules/nette-to-symfony/tests,rules/nette/tests,packages/node-type-resolver/tests,utils/phpstan-extensions/src,rules/phpunit-symfony/tests,rules/phpunit/tests,rules/psr4/tests,rules/php-spec-to-phpunit/tests,rules/php52/tests,rules/php53/tests,rules/php54/tests,rules/php55/tests,rules/php56/tests,rules/php70/tests,rules/php71/tests,rules/php72/tests,rules/php73/tests,rules/php74/tests,rules/php80/tests,rules/removing-static/tests,rules/renaming/tests,rules/restoration/tests,rules/solid/tests,rules/sensio/tests,rules/symfony-code-quality/tests,rules/symfony-phpunit/tests,rules/symfony/tests,rules/twig/tests,rules/type-declaration/tests,rules/strict-code-quality/tests,rules/php-deglobalize/tests,rules/phalcon/tests,utils/node-documentation-generator/src,utils/phpstan-attribute-type-syncer/src,utils/phpstan-type-mapper-checker/src,rules/doctrine-gedmo-to-knplabs/tests,rules/polyfill/tests,rules/generic/tests
# possibly manual operation needed :/
# https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/

View File

@ -78,9 +78,9 @@ final class ClassDependencyManipulator
?Type $type,
Assign $assign
): void {
/** @var ClassMethod|null $constructorMethod */
$constructorMethod = $class->getMethod(MethodName::CONSTRUCT);
/** @var ClassMethod|null $constructorMethod */
if ($constructorMethod !== null) {
$this->classMethodAssignManipulator->addParameterAndAssignToMethod(
$constructorMethod,

View File

@ -316,10 +316,12 @@ final class IfManipulator
if (! ($if instanceof If_ && $assign instanceof Assign)) {
return false;
}
if (! $if->cond instanceof Identical) {
return false;
}
return $this->betterStandardPrinter->areNodesEqual($this->getIfVar($if), $assign->var);
return $this->betterStandardPrinter->areNodesEqual($this->getIfCondVar($if), $assign->var);
}
public function isIfCondUsingAssignNotIdenticalVariable(If_ $if, Node $node): bool
@ -330,7 +332,7 @@ final class IfManipulator
if (! $if->cond instanceof NotIdentical) {
return false;
}
return ! $this->betterStandardPrinter->areNodesEqual($this->getIfVar($if), $node->var);
return ! $this->betterStandardPrinter->areNodesEqual($this->getIfCondVar($if), $node->var);
}
private function matchComparedAndReturnedNode(NotIdentical $notIdentical, Return_ $return): ?Expr
@ -391,10 +393,11 @@ final class IfManipulator
return ! (bool) $if->elseifs;
}
private function getIfVar(If_ $if): Node
private function getIfCondVar(If_ $if): Node
{
/** @var Identical|NotIdentical $ifCond */
$ifCond = $if->cond;
return $this->constFetchManipulator->isNull($ifCond->left) ? $ifCond->right : $ifCond->left;
}
}