valueResolver = $valueResolver; $this->staticTypeMapper = $staticTypeMapper; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Make implicit nullable param to explicit', [new CodeSample(<<<'CODE_SAMPLE' function foo(string $param = null) {} CODE_SAMPLE , <<<'CODE_SAMPLE' function foo(?string $param = null) {} CODE_SAMPLE )]); } public function getNodeTypes() : array { return [Param::class]; } /** * @param Param $node */ public function refactor(Node $node) : ?Param { if (!$node->type instanceof Node) { return null; } if (!$node->default instanceof ConstFetch || !$this->valueResolver->isNull($node->default)) { return null; } $nodeType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node->type); if (TypeCombinator::containsNull($nodeType)) { return null; } $newNodeType = TypeCombinator::addNull($nodeType); $node->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newNodeType, TypeKind::PARAM); return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_IMPLICIT_NULLABLE_PARAM_TYPE; } }