exactCompareFactory = $exactCompareFactory; } public function getRuleDefinition() : RuleDefinition { $errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\\Rules\\BooleansInConditions\\BooleanInTernaryOperatorRule'); return new RuleDefinition($errorMessage, [new ConfiguredCodeSample(<<<'CODE_SAMPLE' final class ArrayCompare { public function run(array $data) { return $data ? 1 : 2; } } CODE_SAMPLE , <<<'CODE_SAMPLE' final class ArrayCompare { public function run(array $data) { return $data !== [] ? 1 : 2; } } CODE_SAMPLE , [self::TREAT_AS_NON_EMPTY => \false])]); } /** * @return array> */ public function getNodeTypes() : array { return [Ternary::class]; } /** * @param Ternary $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Ternary { // skip short ternary if (!$node->if instanceof Expr) { return null; } $exprType = $scope->getType($node->cond); $expr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($exprType, $node->cond, $this->treatAsNonEmpty); if (!$expr instanceof Expr) { return null; } $node->cond = $expr; return $node; } }