Skip to content

Commit

Permalink
Around PHPStan 1.12.4 handling on ParametersAcceptors with non-native…
Browse files Browse the repository at this point in the history
… return type (by docblock) (#6341)
  • Loading branch information
samsonasik authored Oct 1, 2024
1 parent a11fc61 commit 697b37b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ parameters:
message: '#Function "var_dump\(\)" cannot be used/left in the code#'
path: src/functions/node_helper.php

-
message: '#Function "method_exists\(\)" cannot be used/left in the code#'
path: rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php

# lack of generic array in nikic/php-parser
- '#Method (.*?) should return array<PhpParser\\Node\\(.*?)\> but returns array<PhpParser\\Node\>#'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\SomeExternalCaller;

final class SkipExternalCallerReturnDoc
{
public function getData(SomeExternalCaller $someExternalCaller, $x)
{
return $someExternalCaller->getData($x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public function getName(): string
{
return 'Yesman';
}

/**
* @return string
*/
public function getData($data)
{
return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public function resolveMethodCallReturnType(MethodCall | StaticCall | FuncCall $
$returnType = $parametersAcceptorWithPhpDocs->getNativeReturnType();
} else {
$returnType = $parametersAcceptorWithPhpDocs->getReturnType();

// around PHPStan 1.12.4+ handling
if (method_exists($parametersAcceptorWithPhpDocs, 'getNativeReturnType')) {
$nativeReturnType = $parametersAcceptorWithPhpDocs->getNativeReturnType();
if ($nativeReturnType instanceof MixedType && ! $nativeReturnType->isExplicitMixed()) {
$returnType = $nativeReturnType;
}
}
}

if ($returnType instanceof MixedType) {
Expand Down

0 comments on commit 697b37b

Please # to comment.