- Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
With this code sample:
public function testDynamicMethodReturnTypeExtensions( string $typeClass, bool $nullable, string $class = null, string $expression ) { $this->assertTypes( __DIR__ . '/data/dynamic-method-return-types.php', $typeClass, $nullable, $class, $expression, [ new class() implements DynamicMethodReturnTypeExtension { public static function getClass(): string { return \DynamicMethodReturnTypesNamespace\EntityManager::class; } public function isMethodSupported(MethodReflection $methodReflection): bool { return in_array($methodReflection->getName(), ['getByPrimary'], true); } public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type { $args = $methodCall->args; if (count($args) === 0) { return $methodReflection->getReturnType(); } $arg = $args[0]->value; if (!($arg instanceof \PhpParser\Node\Expr\ClassConstFetch)) { return $methodReflection->getReturnType(); } if (!($arg->class instanceof \PhpParser\Node\Name)) { return $methodReflection->getReturnType(); } return new ObjectType((string) $arg->class, false); } }, ] ); }
CodeSniffer reports wrong indentation on some lines in the anonymous class. It stops complaining when I format the code like this:
public function testDynamicMethodReturnTypeExtensions( string $typeClass, bool $nullable, string $class = null, string $expression ) { $this->assertTypes( __DIR__ . '/data/dynamic-method-return-types.php', $typeClass, $nullable, $class, $expression, [ new class() implements DynamicMethodReturnTypeExtension { public static function getClass(): string { return \DynamicMethodReturnTypesNamespace\EntityManager::class; } public function isMethodSupported(MethodReflection $methodReflection): bool { return in_array($methodReflection->getName(), ['getByPrimary'], true); } public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type { $args = $methodCall->args; if (count($args) === 0) { return $methodReflection->getReturnType(); } $arg = $args[0]->value; if (!($arg instanceof \PhpParser\Node\Expr\ClassConstFetch)) { return $methodReflection->getReturnType(); } if (!($arg->class instanceof \PhpParser\Node\Name)) { return $methodReflection->getReturnType(); } return new ObjectType((string) $arg->class, false); } }, ] );
Which looks wrong to me.