Skip to content

Commit

Permalink
remove unmatched errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 1, 2021
1 parent 8c3443b commit 402cc1d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\NodeTypeResolver\TypeAnalyzer;

use Countable;
use PhpParser\Node;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -55,7 +54,7 @@ public function isCountableType(Node $node): bool
private function isCountableObjectType(Type $type): bool
{
$countableObjectTypes = [
new ObjectType(Countable::class),
new ObjectType('Countable'),
new ObjectType('SimpleXMLElement'),
new ObjectType('ResourceBundle'),
];
Expand Down
40 changes: 18 additions & 22 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ parameters:
# broken
- '#Parameter \#2 \$name of method Rector\\NodeNameResolver\\NodeNameResolver\:\:isName\(\) expects string, string\|null given#'

- '#Parameter \#1 \$funcCall of method Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\AbstractMatchAndRefactor\:\:createStrStartsWithValueObjectFromFuncCall\(\) expects PhpParser\\Node\\Expr\\FuncCall, PhpParser\\Node\\Expr given#'

# mostly strings in tests
- '#Method Rector\\Naming\\Naming\\PropertyNaming\:\:resolveShortClassName\(\) should return string but returns string\|null#'

Expand Down Expand Up @@ -232,7 +230,6 @@ parameters:
- packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php # 108
- rules/coding-style/src/Rector/ClassMethod/YieldClassMethodToArrayClassMethodRector.php # 47
- rules/php70/src/EregToPcreTransformer.php # 66
- rules/type-declaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php # 82

# trait in trait call
- '#Parameter \#1 \$expr of class PhpParser\\Node\\Stmt\\Expression constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|PhpParser\\Node\\Stmt given#'
Expand Down Expand Up @@ -437,8 +434,6 @@ parameters:
paths:
- rules/removing-static/tests/Rector/Property/DesiredPropertyClassMethodTypeToDynamicRector/config/some_config.php

- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or abstract service instead#'

# buggy phpstan clas-string
- '#Method (.*?) should return class\-string but returns string#'

Expand Down Expand Up @@ -504,7 +499,6 @@ parameters:
# known values
- '#Method Rector\\Testing\\Finder\\RectorsFinder\:\:findClassesInDirectoriesByName\(\) should return array<class\-string\> but returns array<int, \(int\|string\)\>#'
- '#Property PhpParser\\Node\\Param\:\:\$type \(PhpParser\\Node\\Identifier\|PhpParser\\Node\\Name\|PhpParser\\Node\\NullableType\|PhpParser\\Node\\UnionType\|null\) does not accept PhpParser\\Node#'
- '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated with method "getFunctionLikePhpDocInfo\(\)" in "Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PHPUnitDataProviderParamTypeInferer" class\. Use unique content or abstract service instead#'

-
message: '#"%s" in sprintf\(\) format must be quoted#'
Expand All @@ -517,7 +511,6 @@ parameters:
path: rules/symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php

- '#Property Rector\\Core\\PhpParser\\Node\\AssignAndBinaryMap\:\:\$binaryOpToAssignClasses \(array<class\-string<PhpParser\\Node\\Expr\\BinaryOp\>, class\-string<PhpParser\\Node\\Expr\\BinaryOp\>\>\) does not accept array#'
- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\RemovingStatic\\Rector\\Class_\\NewUniqueObjectToEntityFactoryRector" class\. Use unique content or abstract service instead#'
- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\RemovingStatic\\Rector\\Class_\\PassFactoryToUniqueObjectRector" class\. Use unique content or abstract service instead#'

-
Expand Down Expand Up @@ -558,9 +551,6 @@ parameters:

- '#Method Rector\\TypeDeclaration\\PhpParserTypeAnalyzer\:\:unwrapNullableAndToString\(\) should return string but returns string\|null#'

# @todo resolve in next PR!!! (Feb 2021)
- '#Function "array_filter\(\)" cannot be used/left in the code#'
- '#Cognitive complexity for "Rector\\CodeQuality\\Rector\\Isset_\\IssetOnPropertyObjectToPropertyExistsRector\:\:refactor\(\)" is 11, keep it under 9#'
- '#Cognitive complexity for "Rector\\DeadCode\\UnusedNodeResolver\\ClassUnusedPrivateClassMethodResolver\:\:filterOutParentAbstractMethods\(\)" is 10, keep it under 9#'

# known types
Expand All @@ -576,11 +566,6 @@ parameters:
paths:
- rules/restoration/src/ClassMap/ExistingClassesProvider.php

# false positives
-
message: '#Empty array passed to foreach#'
paths:
- rules/transform/src/Rector/New_/NewToConstructorInjectionRector.php
-
message: '#Parameter \#1 \$types of method Rector\\Defluent\\NodeAnalyzer\\FluentCallStaticTypeResolver\:\:filterOutAlreadyPresentParentClasses\(\) expects array<class\-string\>, array<int, string\> given#'
paths:
Expand All @@ -594,15 +579,26 @@ parameters:
paths:
- packages/read-write/src/Guard/VariableToConstantGuard.php

- '#Cognitive complexity for "Rector\\NetteCodeQuality\\FormControlTypeResolver\\MagicNetteFactoryInterfaceFormControlTypeResolver\:\:resolve\(\)" is 11, keep it under 9#'
- '#Cognitive complexity for "Rector\\NetteCodeQuality\\FormControlTypeResolver\\MagicNetteFactoryInterfaceFormControlTypeResolver\:\:resolve\(\)" is 12, keep it under 9#'
- '#Content of method "matchAssignExprToPropertyName\(\)" is duplicated with method "matchAssignExprToPropertyName\(\)" in "Rector\\TypeDeclaration\\AlreadyAssignDetector\\ConstructorAssignDetector" class\. Use unique content or abstract service instead#'

# make more tolerand, e.g. at least 2-3 lines
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\AbstractPropertyConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\MatchPropertyTypeConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\UnderscoreCamelCaseConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\UnderscoreCamelCaseConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\UnderscoreCamelCaseConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\BoolPropertyConflictingNameGuard" class\. Use unique content or abstract service instead#'
- '#Content of method "isConflicting\(\)" is duplicated with method "isConflicting\(\)" in "Rector\\Naming\\Guard\\PropertyConflictingNameGuard\\BoolPropertyConflictingNameGuard" class\. Use unique content or abstract service instead#'


-
message: '#Offset 0 does not exist on array<PhpParser\\Node\\Stmt\>\|null#'
paths:
- rules/naming/src/Naming/PropertyNaming.php

-
message: '#Parameter \#1 \$value of function count expects array\|Countable, array<PhpParser\\Node\\Stmt\>\|null given#'
paths:
- rules/naming/src/Naming/PropertyNaming.php

-
message: '#Use quoted string in constructor "new PHPStan\\Type\\ObjectType\(\)" argument on position 0 instead of "\:\:class\. It prevent scoping of the class in building prefixed package#'
paths:
- packages/node-type-resolver/tests

- '#Content of method "configure\(\)" is duplicated with method "configure\(\)" in "Rector\\Composer\\Rector\\AddPackageToRequireComposerRector" class\. Use unique content or abstract service instead#'
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace Rector\DoctrineCodeQuality\Rector\Class_;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\ClassDependencyManipulator;
Expand Down Expand Up @@ -105,7 +102,7 @@ public function refactor(Node $node): ?Node
}

$parentClassName = $node->getAttribute(AttributeKey::PARENT_CLASS_NAME);
if ($parentClassName !== EntityRepository::class) {
if ($parentClassName !== 'Doctrine\ORM\EntityManagerInterface') {
return null;
}

Expand All @@ -123,15 +120,19 @@ public function refactor(Node $node): ?Node
$node->extends = null;

// add $repository property
$this->classInsertManipulator->addPropertyToClass($node, 'repository', new ObjectType(EntityRepository::class));
$this->classInsertManipulator->addPropertyToClass(
$node,
'repository',
new ObjectType('Doctrine\ORM\EntityRepository')
);

// add $entityManager and assign to constuctor
$repositoryAssign = $this->repositoryAssignFactory->create($node);

$this->classDependencyManipulator->addConstructorDependencyWithCustomAssign(
$node,
'entityManager',
new ObjectType(EntityManagerInterface::class),
new ObjectType('Doctrine\ORM\EntityManagerInterface'),
$repositoryAssign
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Rector\AbstractRector;
use Rector\DowngradePhp70\Contract\Rector\DowngradeReturnDeclarationRectorInterface;
use Traversable;

abstract class AbstractDowngradeReturnDeclarationRector extends AbstractRector implements DowngradeReturnDeclarationRectorInterface
{
Expand Down Expand Up @@ -68,7 +67,7 @@ private function decorateFunctionLikeWithReturnTagValueNode(FunctionLike $functi

$type = $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionLike->returnType);
if ($type instanceof IterableType) {
$type = new UnionType([$type, new IntersectionType([new ObjectType(Traversable::class)])]);
$type = new UnionType([$type, new IntersectionType([new ObjectType('Traversable')])]);
}

$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $type);
Expand Down
9 changes: 2 additions & 7 deletions rules/naming/src/Naming/PropertyNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,11 @@ private function filterClassMethodsWithPropertyFetchReturnOnly(
$currentName = $this->nodeNameResolver->getName($property);

return array_filter($prefixedClassMethods, function (ClassMethod $classMethod) use ($currentName): bool {
$stmts = $classMethod->stmts;
if ($stmts === null) {
if (count($classMethod->stmts) === 0) {
return false;
}

if (! array_key_exists(0, $stmts)) {
return false;
}

$return = $stmts[0];
$return = $classMethod->stmts[0];
if (! $return instanceof Return_) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Rector\NetteKdyby\ValueObject\EventAndListenerTree;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -129,7 +128,7 @@ public function refactor(Node $node): ?Node
$classLike = $node->getAttribute(AttributeKey::CLASS_NODE);
$this->addConstructorDependencyToClass(
$classLike,
new FullyQualifiedObjectType(EventDispatcherInterface::class),
new FullyQualifiedObjectType('Symfony\Contracts\EventDispatcher\EventDispatcherInterface'),
'eventDispatcher'
);

Expand Down
3 changes: 1 addition & 2 deletions rules/symfony2/src/Rector/MethodCall/AddFlashRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Rector\Core\Rector\AbstractRector;
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symfony\Component\HttpFoundation\Request;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -79,7 +78,7 @@ public function refactor(Node $node): ?Node

if (! $this->fluentChainMethodCallNodeAnalyzer->isTypeAndChainCalls(
$node,
new ObjectType(Request::class),
new ObjectType('Symfony\Component\HttpFoundation\Request'),
['getSession', 'getFlashBag', 'add']
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer;

use DateTimeInterface;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\BooleanType;
use PHPStan\Type\FloatType;
Expand Down Expand Up @@ -73,11 +72,11 @@ public function __construct(TypeFactory $typeFactory, PhpDocInfoFactory $phpDocI
'varbinary' => new StringType(),
'set' => new StringType(),
// date time objects
'date' => new ObjectType(DateTimeInterface::class),
'datetime' => new ObjectType(DateTimeInterface::class),
'timestamp' => new ObjectType(DateTimeInterface::class),
'time' => new ObjectType(DateTimeInterface::class),
'year' => new ObjectType(DateTimeInterface::class),
'date' => new ObjectType('DateTimeInterface'),
'datetime' => new ObjectType('DateTimeInterface'),
'timestamp' => new ObjectType('DateTimeInterface'),
'time' => new ObjectType('DateTimeInterface'),
'year' => new ObjectType('DateTimeInterface'),
];
$this->phpDocInfoFactory = $phpDocInfoFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;

use Iterator;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
Expand Down Expand Up @@ -86,7 +85,7 @@ public function inferFunctionLike(FunctionLike $functionLike): Type
// @see https://www.php.net/manual/en/language.types.iterable.php
$types[] = new IterableType(new MixedType(), new MixedType());
} else {
$types[] = new ObjectType(Iterator::class);
$types[] = new ObjectType('Iterator');
}

return $this->typeFactory->createMixedPassedOrUnionType($types);
Expand Down
1 change: 0 additions & 1 deletion src/NodeManipulator/ClassMethodAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private function filterOutMultiAssigns(array $readOnlyVariableAssigns): array
{
return array_filter($readOnlyVariableAssigns, function (Assign $assign): bool {
$parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE);

return ! $parentNode instanceof Assign;
});
}
Expand Down
3 changes: 1 addition & 2 deletions utils/phpstan-extensions/config/rector-rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ services:
arguments:
stringArgPositionsByType:
PhpParser\Node\Name\FullyQualified: [0]
PHPStan\Type\ObjectType: [0]

-
class: Symplify\PHPStanRules\Rules\ClassNameRespectsParentSuffixRule
Expand Down Expand Up @@ -223,8 +224,6 @@ services:
- 'spl_autoload_register'
- 'spl_autoload_unregister'
- array_walk
# creates messy nested logic
- array_filter
# there are handled in ReflectionProvider->has*()
- 'class_exists'
- 'interface_exists'
Expand Down

0 comments on commit 402cc1d

Please sign in to comment.