Skip to content

Commit

Permalink
[TypeDeclaration] Skip callable on AddArrayParamDocTypeRector (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 3, 2021
1 parent cc69e35 commit 89ca42d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ parameters:

- '#Class with base "StaticTypeMapper" name is already used in "Rector\\StaticTypeMapper\\StaticTypeMapper", "Rector\\PHPStanStaticTypeMapper\\TypeMapper\\StaticTypeMapper"\. Use unique name to make classes easy to recognize#'
- '#Class with base "UnionTypeMapper" name is already used in "Rector\\StaticTypeMapper\\PhpDocParser\\UnionTypeMapper", "Rector\\PHPStanStaticTypeMapper\\TypeMapper\\UnionTypeMapper"\. Use unique name to make classes easy to recognize#'
- '#Class with base "UnionTypeMapper" name is already used in "Rector\\PHPStanStaticTypeMapper\\TypeMapper\\UnionTypeMapper", "Rector\\StaticTypeMapper\\PhpDocParser\\UnionTypeMapper"\. Use unique name to make classes easy to recognize#'

# allowed for ease api
-
Expand Down Expand Up @@ -525,3 +526,8 @@ parameters:
- rules/Php74/Rector/LNumber/AddLiteralSeparatorToNumberRector.php

- '#^Cognitive complexity for "Rector\\CodingStyle\\Naming\\NameRenamer\:\:renameNameNode\(\)" is 13, keep it under 9$#'

-
message: '#The string value "" is repeated 6 times\. Refactor to enum to avoid typos and make clear allowed values#'
paths:
- packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTagRemover.php #45
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector\Fixture;

final class SkipCallable
{
/**
* @var callable
*/
private $callable;

public function __construct(callable $callable)
{
$this->callable = $callable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\ArrayType;
use PHPStan\Type\CallableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -107,6 +108,10 @@ public function refactor(Node $node): ?Node
continue;
}

if ($paramType instanceof CallableType) {
continue;
}

if ($this->paramAnalyzer->isNullable($param) && ! $paramType instanceof UnionType) {
$paramType = new UnionType([$paramType, new NullType()]);
}
Expand Down

0 comments on commit 89ca42d

Please sign in to comment.