> */ public function getNodeTypes() : array { return [\PhpParser\Node\Stmt\Break_::class, \PhpParser\Node\Stmt\Continue_::class]; } /** * @param \PhpParser\Node $node */ public function refactor($node) : ?\PhpParser\Node { if ($node->num === null) { return null; } if ($node->num instanceof \PhpParser\Node\Scalar\LNumber) { $number = $this->valueResolver->getValue($node->num); if ($number > 1) { return null; } if ($number === 0) { $node->num = null; return $node; } return null; } if ($node->num instanceof \PhpParser\Node\Expr\Variable) { return $this->processVariableNum($node, $node->num); } return null; } /** * @param \PhpParser\Node\Stmt\Break_|\PhpParser\Node\Stmt\Continue_ $stmt */ private function processVariableNum($stmt, \PhpParser\Node\Expr\Variable $numVariable) : ?\PhpParser\Node { $staticType = $this->getType($numVariable); if ($staticType instanceof \PHPStan\Type\ConstantType) { if ($staticType instanceof \PHPStan\Type\Constant\ConstantIntegerType) { if ($staticType->getValue() === 0) { $stmt->num = null; return $stmt; } if ($staticType->getValue() > 0) { $stmt->num = new \PhpParser\Node\Scalar\LNumber($staticType->getValue()); return $stmt; } } return $stmt; } // remove variable $stmt->num = null; return null; } }