staticTypeMapper = $staticTypeMapper; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add known return type to arrow function', [new CodeSample(<<<'CODE_SAMPLE' fn () => []; CODE_SAMPLE , <<<'CODE_SAMPLE' fn (): array => []; CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [ArrowFunction::class]; } /** * @param ArrowFunction $node */ public function refactor(Node $node) : ?Node { if ($node->returnType !== null) { return null; } $type = $this->nodeTypeResolver->getNativeType($node->expr); if ($type->isVoid()->yes()) { return null; } $returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN); if (!$returnTypeNode instanceof Node) { return null; } $node->returnType = $returnTypeNode; return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::ARROW_FUNCTION; } }