Skip to content

Commit

Permalink
few static fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 19, 2024
1 parent 7d65537 commit 86059c4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ parameters:
- src/StaticTypeMapper/ValueObject/Type/*Type.php

# generics nullable bugs
- '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#'
-
message: '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#'
path: src/PhpParser/Node/BetterNodeFinder.php

- '#Method (.*?) should return array<T of PhpParser\\Node\> but returns array<PhpParser\\Node\>#'

- '#Property Rector\\PhpParser\\Node\\AssignAndBinaryMap\:\:\$binaryOpToAssignClasses \(array<class\-string<PhpParser\\Node\\Expr\\BinaryOp\>, class\-string<PhpParser\\Node\\Expr\\BinaryOp\>\>\) does not accept array#'
Expand Down Expand Up @@ -121,6 +124,8 @@ parameters:
# array_index on generic types
- '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory\:\:uniquateTypes\(\) should return array<TType of PHPStan\\Type\\Type\> but returns array<int, PHPStan\\Type\\Type\>#'

- '#Method Rector\\Arguments\\ArgumentDefaultValueReplacer\:\:processReplaces\(\) should return \(TCall of PhpParser\\Node\\Expr\\FuncCall\|PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\New_\|PhpParser\\Node\\Expr\\StaticCall\|PhpParser\\Node\\Stmt\\ClassMethod\)\|null but returns PhpParser\\Node\\Stmt\\ClassMethod\|null#'

# native filesystem calls, required for performance reasons
-
message: '#"@\\unlink\(\$tmpPath\)" is forbidden to use#'
Expand Down
15 changes: 13 additions & 2 deletions rules/Arguments/ArgumentDefaultValueReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\Arguments;

use PhpParser\BuilderHelpers;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ClassConstFetch;
Expand All @@ -27,10 +26,16 @@ public function __construct(
) {
}

/**
* @template TCall as (MethodCall|StaticCall|ClassMethod|FuncCall|New_)
*
* @param TCall $node
* @return TCall|null
*/
public function processReplaces(
MethodCall | StaticCall | ClassMethod | FuncCall | New_ $node,
ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue
): ?Node {
): MethodCall | StaticCall | ClassMethod | FuncCall | New_ |null {
if ($node instanceof ClassMethod) {
if (! isset($node->params[$replaceArgumentDefaultValue->getPosition()])) {
return null;
Expand Down Expand Up @@ -82,6 +87,12 @@ private function processParams(
return $classMethod;
}

/**
* @template TCall as (MethodCall|StaticCall|FuncCall|New_)
*
* @param TCall $expr
* @return TCall|null
*/
private function processArgs(
MethodCall | StaticCall | FuncCall | New_ $expr,
ReplaceArgumentDefaultValueInterface $replaceArgumentDefaultValue
Expand Down
1 change: 1 addition & 0 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(

/**
* @param array<string, string> $oldToNewClasses
* @return ($node is FullyQualified ? FullyQualified : \PhpParser\Node)
*/
public function renameNode(Node $node, array $oldToNewClasses, ?Scope $scope): ?Node
{
Expand Down
6 changes: 4 additions & 2 deletions src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ private function resolveNullableType(NullableType $nullableType): null|NullableT
/**
* @param TypeKind::* $typeKind
*/
private function mapNullabledType(Type $nullabledType, string $typeKind): ?Node
{
private function mapNullabledType(
Type $nullabledType,
string $typeKind
): NullableType|ComplexType|PhpParserUnionType|null {
// void cannot be nullable
if ($nullabledType->isVoid()->yes()) {
return null;
Expand Down
3 changes: 1 addition & 2 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeFinder;
Expand Down Expand Up @@ -134,7 +133,7 @@ public function find(Node | array $nodes, callable $filter): array
/**
* @api symfony
* @param Node[] $nodes
* @return ClassLike|null
* @return Class_|null
*/
public function findFirstNonAnonymousClass(array $nodes): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Tests\NodeTypeResolver\StaticTypeMapper;

use PHPStan\Type\Type;
use Iterator;
use PhpParser\Node;
use PhpParser\Node\Identifier;
Expand All @@ -17,6 +16,7 @@
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
Expand Down

0 comments on commit 86059c4

Please sign in to comment.