[ 'code' => 'fooFoo(); break; case B::class: $a->barBar(); break; }', ], 'getClassExteriorArgClassConsts' => [ 'code' => 'getMessage(); break; case LogicException::class: $e->getMessage(); break; } } ', ], 'switchGetClassVar' => [ 'code' => 'foo(); break; } }', ], 'getTypeArg' => [ 'code' => ' [ 'code' => 'a !== null: return $obj->a; // definitely not null case !is_null($obj->b): return $obj->b; // definitely not null default: throw new \InvalidArgumentException("$obj->a or $obj->b must be set"); } }', ], 'switchMoTruthy' => [ 'code' => 'a: return $obj->a; // definitely not null case $obj->b: return $obj->b; // definitely not null default: throw new \InvalidArgumentException("$obj->a or $obj->b must be set"); } }', ], 'switchWithBadBreak' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ '$x' => 'bool', '$y' => 'bool', ], ], 'continueIsBreak' => [ 'code' => ' [ 'code' => ' [ 'code' => 'maybeReturnsDT(); if (!is_null($dt)) { $dt = $dt->format(\DateTime::ISO8601); } break; } class A { public function maybeReturnsDT(): ?\DateTimeInterface { return rand(0,1) ? new \DateTime("now") : null; } }', ], 'issetInFallthrough' => [ 'code' => ' 2) { echo "$x is large"; } break; } }', ], 'switchManyGetClass' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ '$a' => 'bool', '$b' => 'int', ], ], 'switchVarConditionalReAssignment' => [ 'code' => ' [ '$a' => 'bool', ], ], 'moreThan30Cases' => [ 'code' => ' [ 'code' => ' $predefined_constants * * @return string|null */ function getGlobalConstType( ?string $fq_const_name, string $const_name, array $predefined_constants ) { if ($const_name === "STDERR" || $const_name === "STDOUT" || $const_name === "STDIN" ) { return "hello"; } if (isset($predefined_constants[$fq_const_name]) || isset($predefined_constants[$const_name]) ) { switch ($const_name) { case "PHP_MAJOR_VERSION": case "PHP_ZTS": return "int"; case "PHP_FLOAT_EPSILON": case "PHP_FLOAT_MAX": case "PHP_FLOAT_MIN": return "float"; } if ($fq_const_name && isset($predefined_constants[$fq_const_name])) { return "mixed"; } return "hello"; } return null; }' ], 'evenLongerSwitch' => [ 'code' => ' [ 'code' => 'format("Y") === "2020": $a->format("d-m-Y"); }' ], 'evenWorseSwitch' => [ 'code' => ' [ 'code' => ' [ 'code' => 'a = new A(); } /** @psalm-suppress MixedArgument */ switch (get_class($this->a)) { case B::class: echo "here"; } } }', ], 'noCrashOnComplicatedCases' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' 'InvalidNullableReturnType', ], 'switchReturnTypeWithFallthroughAndConditionalBreak' => [ 'code' => ' 'InvalidNullableReturnType', ], 'switchReturnTypeWithNoDefault' => [ 'code' => ' 'InvalidNullableReturnType', ], 'getClassArgWrongClass' => [ 'code' => 'barBar(); break; }', 'error_message' => 'UndefinedMethod', ], 'getClassMissingClass' => [ 'code' => ' 'UndefinedClass', ], 'getTypeNotAType' => [ 'code' => ' 'UnevaluatedCode', ], 'getTypeArgWrongArgs' => [ 'code' => ' 'InvalidScalarArgument', ], 'switchBadMethodCallInCase' => [ 'code' => ' 'InvalidScalarArgument', ], 'continueIsNotBreak' => [ 'code' => ' 'ContinueOutsideLoop', ], 'defaultAboveCaseThatBreaks' => [ 'code' => ' 'InvalidReturnType', ], 'SKIPPED-switchManyGetClassWithRepetitionWithProperLineNumber' => [ 'code' => ' 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:10', 'ignored_issues' => ['ParadoxicalCondition'], ], 'repeatedCaseValue' => [ 'code' => ' 'ParadoxicalCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:7', ], 'impossibleCaseValue' => [ 'code' => ' 'TypeDoesNotContainType - src' . DIRECTORY_SEPARATOR . 'somefile.php:11', ], 'impossibleCaseDefault' => [ 'code' => ' 'ParadoxicalCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:11', ], 'breakWithoutSettingVar' => [ 'code' => ' 'PossiblyUndefinedVariable', ], 'getClassExteriorArgStringType' => [ 'code' => ' 'TypeDoesNotContainType', ], 'paradoxInFunctionCall' => [ 'code' => ' 'ParadoxicalCondition' ], 'loopWithSwitchDoesntReturnFirstCase' => [ 'code' => ' 'InvalidReturnType' ], 'clearDependentTypeWhenAssigning' => [ 'code' => 'bar(); } }', 'error_message' => 'UndefinedMethod' ], ]; } }