Skip to content

Commit

Permalink
Fix few static errors (#5899)
Browse files Browse the repository at this point in the history
* cleanup phsptan errors

* misc

* cleanup errors

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
TomasVotruba and actions-user committed May 19, 2024
1 parent 196b2d0 commit 7d65537
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"symplify/easy-ci": "^11.3",
"symplify/easy-coding-standard": "^12.1",
"symplify/phpstan-extensions": "^11.4",
"symplify/phpstan-rules": "^12.5.2",
"symplify/phpstan-rules": "^12.6.1",
"symplify/rule-doc-generator": "^12.1.10",
"symplify/vendor-patches": "^11.2",
"tomasvotruba/class-leak": "^0.2.13",
Expand Down
26 changes: 1 addition & 25 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ parameters:
# regex
- rules/Php70/EregToPcreTransformer.php

# resolve later with configurable types
- '#On passing a constant, the method should have an enum type\. See https\://phpstan\.org/writing\-php\-code/phpdoc\-types\#literals\-and\-constants#'

-
message: '#@\\ini_set\(.*\)" is forbidden to use#'
path: bin/rector.php
Expand All @@ -230,15 +227,6 @@ parameters:
message: '#New objects with "\$fullyQualifiedObjectType" name are overridden\. This can lead to unwanted bugs, please pick a different name to avoid it#'
path: src/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php

-
message: '#Relative file path ".+" is not allowed, use absolute one with __DIR__#'
paths:
- bin/rector.php
- src/Bootstrap/RectorConfigsResolver.php
- tests/FileSystem/FilesFinder/FilesFinderTest.php
- tests/Skipper/Skipper/SkipperTest.php
- src/Console/Command/CustomRuleCommand.php

# phpdoc node traversing
-
message: '#Use explicit names over dynamic ones#'
Expand Down Expand Up @@ -277,10 +265,6 @@ parameters:
paths:
- rules-tests/*/config/*

- '#Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) expects class\-string<object>, string given#'

- '#Parameter \#3 \$nodeClass of method Rector\\Tests\\BetterPhpDocParser\\PhpDocParser\\TagValueNodeReprint\\TagValueNodeReprintTest\:\:doTestPrintedPhpDocInfo\(\) expects class\-string<PhpParser\\Node>, string given#'

# trusted items
- '#Parameter \#1 \$nodes of method PhpParser\\PrettyPrinterAbstract\:\:pCommaSeparatedMultiline\(\) expects array<PhpParser\\Node>, array<PhpParser\\Node\\Expr\\ArrayItem\|null> given#'

Expand All @@ -292,11 +276,7 @@ parameters:
- '#Parameter \#1 \$suffix of method PHPUnit\\Framework\\Assert\:\:assertStringEndsWith\(\) expects non\-empty\-string, string given#'

-
message: '#Function "function_exists\(\)" cannot be used/left in the code#'
path: src/functions/node_helper.php

-
message: '#Function "dump_node\(\)" cannot be used/left in the code\: #'
message: '#Function "(function_exists|dump_node)\(\)" cannot be used/left in the code#'
path: src/functions/node_helper.php

# false positive on enums
Expand All @@ -322,10 +302,6 @@ parameters:
message: '#Function "function_exists\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
path: tests/debug_functions.php

-
message: '#Do not name "d", shorter than 2 chars#'
path: tests/debug_functions.php

# method signature kept for symmetry of hasParentClassMethod() with getParentClassMethod()
-
message: '#Parameters should use "PhpParser\\Node\\Stmt\\ClassMethod" types as the only types passed to this method#'
Expand Down
4 changes: 4 additions & 0 deletions rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ReflectionProvider;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\Php81\Enum\AttributeName;
use Rector\PhpAttribute\Enum\DocTagNodeState;

final readonly class PhpAttributeAnalyzer
Expand All @@ -41,6 +42,9 @@ public function hasPhpAttribute(Property | ClassLike | ClassMethod | Param $node
return false;
}

/**
* @param AttributeName::* $attributeClass
*/
public function hasInheritedPhpAttribute(Class_ $class, string $attributeClass): bool
{
$className = (string) $this->nodeNameResolver->getName($class);
Expand Down
5 changes: 5 additions & 0 deletions src/Caching/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Caching;

use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Caching\Enum\CacheKey;

final readonly class Cache
{
Expand All @@ -14,13 +15,17 @@ public function __construct(
}

/**
* @param CacheKey::* $variableKey
* @return mixed|null
*/
public function load(string $key, string $variableKey)
{
return $this->cacheStorage->load($key, $variableKey);
}

/**
* @param CacheKey::* $variableKey
*/
public function save(string $key, string $variableKey, mixed $data): void
{
$this->cacheStorage->save($key, $variableKey, $data);
Expand Down
2 changes: 2 additions & 0 deletions src/NodeNameResolver/NodeNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Rector\NodeAnalyzer\CallAnalyzer;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\ValueObject\MethodName;

final class NodeNameResolver
{
Expand Down Expand Up @@ -71,6 +72,7 @@ public function isNames(Node $node, array $names): bool

/**
* @param Node|Node[] $node
* @param MethodName::*|string $name
*/
public function isName(Node | array $node, string $name): bool
{
Expand Down
4 changes: 4 additions & 0 deletions src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Php81\Enum\AttributeName;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\AttributeArrayNameInliner;

Expand All @@ -39,6 +40,9 @@ public function createFromSimpleTag(AnnotationToAttribute $annotationToAttribute
return $this->createFromClass($annotationToAttribute->getAttributeClass());
}

/**
* @param AttributeName::*|string $attributeClass
*/
public function createFromClass(string $attributeClass): AttributeGroup
{
$fullyQualified = new FullyQualified($attributeClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function test(string $filePath): void
{
[$fileContents, $nodeClass, $tagValueNodeClasses] = FixtureSplitter::split($filePath);

/** @var class-string<Node> $nodeClass */
$nodeClass = trim($nodeClass);
$tagValueNodeClasses = $this->splitListByEOL($tagValueNodeClasses);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Tests\NodeTypeResolver\StaticTypeMapper;

use PHPStan\Type\Type;
use Iterator;
use PhpParser\Node;
use PhpParser\Node\Identifier;
Expand All @@ -29,6 +30,9 @@ protected function setUp(): void
$this->staticTypeMapper = $this->make(StaticTypeMapper::class);
}

/**
* @param class-string<Type> $expectedType
*/
#[DataProvider('provideData')]
public function testMapPHPStanPhpDocTypeNodeToPHPStanType(TypeNode $typeNode, string $expectedType): void
{
Expand Down

0 comments on commit 7d65537

Please sign in to comment.