> */ public function getNodeTypes() : array { return [If_::class]; } /** * @param If_ $node */ public function refactor(Node $node) : ?Node { if ($node->cond instanceof BooleanNot && $this->isNullableNonScalarType($node->cond->expr)) { $node->cond = new Identical($node->cond->expr, $this->nodeFactory->createNull()); return $node; } if ($this->isNullableNonScalarType($node->cond)) { $node->cond = new NotIdentical($node->cond, $this->nodeFactory->createNull()); return $node; } return null; } private function isNullableNonScalarType(Expr $expr) : bool { $nativeType = $this->nodeTypeResolver->getNativeType($expr); // is non-nullable? if (!TypeCombinator::containsNull($nativeType)) { return \false; } if (!$nativeType instanceof UnionType) { return \false; } // is array? foreach ($nativeType->getTypes() as $subType) { if ($subType->isArray()->yes()) { return \false; } } $nativeType = TypeCombinator::removeNull($nativeType); return !$nativeType->isScalar()->yes(); } }