1313use PHPStan \PhpDocParser \Parser \TokenIterator ;
1414use PHPStan \Reflection \ReflectionProvider ;
1515use PHPStan \Rules \Rule ;
16- use PHPStan \ShouldNotHappenException ;
1716
1817/**
1918 * @implements Rule<Class_>
2019 */
2120final class NotShouldPhpdocReturnIfExistTypeHint implements Rule
2221{
23-
2422 public function __construct (
2523 private readonly ReflectionProvider $ reflectionProvider ,
2624 private readonly PhpDocParser $ parser ,
@@ -33,9 +31,6 @@ public function getNodeType(): string
3331 return Class_::class;
3432 }
3533
36- /**
37- * @throws ShouldNotHappenException
38- */
3934 public function processNode (Node $ node , Scope $ scope ): array
4035 {
4136 $ fullyQualifiedClassName = $ node ->namespacedName ?->toString();
@@ -54,14 +49,13 @@ public function processNode(Node $node, Scope $scope): array
5449 continue ;
5550 }
5651
57- $ doc = (string )$ method ->getDocComment ();
52+ $ doc = (string ) $ method ->getDocComment ();
5853 if ($ doc === '' ) {
5954 continue ;
6055 }
6156
62-
6357 $ returnType = $ method ->getReturnType ();
64- if ($ returnType === null || !method_exists ($ returnType , 'getName ' )) {
58+ if ($ returnType === null || ! method_exists ($ returnType , 'getName ' )) {
6559 return [];
6660 }
6761
@@ -76,10 +70,13 @@ public function processNode(Node $node, Scope $scope): array
7670 if ($ tag ->value instanceof ReturnTagValueNode) {
7771 $ value = $ tag ->value ->type ->name ;
7872 if ($ value === $ returnTypeName
79- && $ reflection ->getName () === $ method ->getBetterReflection ()->getLocatedSource ()->getName ()) {
73+ && $ reflection ->getName () === $ method ->getBetterReflection ()
74+ ->getLocatedSource ()
75+ ->getName ()) {
8076 $ errors [] = \PHPStan \Rules \RuleErrorBuilder::message (
8177 'PhpDoc attribute @return for method ' . $ method ->getName () . ' can be remove '
82- )->line ((int )$ method ->getStartLine ())->build ();
78+ )->line ((int ) $ method ->getStartLine ())
79+ ->build ();
8380 }
8481 }
8582 }
0 commit comments