-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CallableType and ClosureType::describe() - use phpdoc-parser Printer …
…for better precision
- Loading branch information
1 parent
413079d
commit 30f60c1
Showing
7 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,13 @@ | |
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode; | ||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; | ||
use PHPStan\PhpDocParser\Ast\Type\TypeNode; | ||
use PHPStan\PhpDocParser\Printer\Printer; | ||
use PHPStan\Reflection\ClassMemberAccessAnswerer; | ||
use PHPStan\Reflection\Native\NativeParameterReflection; | ||
use PHPStan\Reflection\ParameterReflection; | ||
use PHPStan\Reflection\ParametersAcceptor; | ||
use PHPStan\Reflection\PassedByReference; | ||
use PHPStan\Reflection\Php\DummyParameter; | ||
use PHPStan\ShouldNotHappenException; | ||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\Generic\TemplateType; | ||
|
@@ -29,8 +32,6 @@ | |
use function array_map; | ||
use function array_merge; | ||
use function count; | ||
use function implode; | ||
use function sprintf; | ||
|
||
/** @api */ | ||
class CallableType implements CompoundType, ParametersAcceptor | ||
|
@@ -176,19 +177,23 @@ public function describe(VerbosityLevel $level): string | |
{ | ||
return $level->handle( | ||
static fn (): string => 'callable', | ||
fn (): string => sprintf( | ||
'callable(%s): %s', | ||
implode(', ', array_map( | ||
static fn (ParameterReflection $param): string => sprintf( | ||
'%s%s%s', | ||
$param->isVariadic() ? '...' : '', | ||
$param->getType()->describe($level), | ||
$param->isOptional() && !$param->isVariadic() ? '=' : '', | ||
), | ||
$this->getParameters(), | ||
)), | ||
$this->returnType->describe($level), | ||
), | ||
function (): string { | ||
$printer = new Printer(); | ||
$selfWithoutParameterNames = new self( | ||
array_map(static fn (ParameterReflection $p): ParameterReflection => new DummyParameter( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mvorisek
Contributor
|
||
'', | ||
$p->getType(), | ||
$p->isOptional() && !$p->isVariadic(), | ||
PassedByReference::createNo(), | ||
$p->isVariadic(), | ||
$p->getDefaultValue(), | ||
), $this->parameters), | ||
$this->returnType, | ||
$this->variadic, | ||
); | ||
|
||
return $printer->print($selfWithoutParameterNames->toPhpDocNode()); | ||
}, | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
phpstan/phpstan#9009 (comment)
$this
should be always dumped with the class name as when$this
is dumped normally