[ 'code' => ' [], 'ignored_issues' => ['EmptyArrayAccess'], ], 'issetWithMultipleAssignments' => [ 'code' => ' 2) { $arr = [5 => [3 => "hello"]]; } if (isset($arr[$a = 5][$b = 3])) { } echo $a; echo $b;', 'assertions' => [], 'ignored_issues' => ['MixedArrayAccess'], ], 'isset' => [ 'code' => ' [ '$a' => 'mixed|null', ], 'ignored_issues' => ['MixedAssignment'], ], 'nullCoalesce' => [ 'code' => ' [ '$a' => 'mixed|null', ], 'ignored_issues' => ['MixedAssignment'], ], 'nullCoalesceWithGoodVariable' => [ 'code' => ' 5 ? "hello" : null; $a = $b ?? null;', 'assertions' => [ '$a' => 'null|string', ], ], 'issetKeyedOffset' => [ 'code' => ' [ '$foo[\'a\']' => 'mixed|string', ], 'ignored_issues' => [], ], 'issetKeyedOffsetORFalse' => [ 'code' => ' "bar"] : false; if (isset($bar["foo"])) { takesString($bar["foo"]); }', 'assertions' => [], 'ignored_issues' => ['PossiblyInvalidArrayAccess'], ], 'nullCoalesceKeyedOffset' => [ 'code' => ' [ '$foo[\'a\']' => 'mixed|string', ], 'ignored_issues' => ['MixedAssignment'], ], 'noRedundantConditionOnMixed' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], ], 'testUnset' => [ 'code' => ' [ 'code' => ' [ "foo" => "bar", ], "groups" => [ "foo" => "bar", "hide" => rand() % 2 > 0, ], ]; foreach ($arr as $item) { if (!isset($item["hide"]) || !$item["hide"]) {} }', ], 'issetPropertyAffirmsObject' => [ 'code' => 'id)) { return $a; } return new A(); }', ], 'issetVariableKeysWithoutChange' => [ 'code' => ' [ 'code' => ' $arr */ function foo(array $arr) : int { $b = rand(0, 3); if (!isset($arr[$b])) { throw new \Exception("bad"); } return $arr[$b]; }', ], 'issetWithCalculatedKeyAndEqualComparison' => [ 'code' => ' $array */ $array = []; function sameString(string $string): string { return $string; } if (isset($array[sameString("key")]) === false) { throw new \LogicException("No such key"); } $value = $array[sameString("key")]; ', 'assertions' => [ '$value' => 'string', ], ], 'issetArrayOffsetConditionalCreationWithInt' => [ 'code' => ' $arr */ function foo(array $arr) : string { if (!isset($arr[0])) { $arr[0] = "hello"; } return $arr[0]; }', ], 'issetArrayOffsetConditionalCreationWithVariable' => [ 'code' => ' $arr */ function foo(array $arr) : string { $b = 5; if (!isset($arr[$b])) { $arr[$b] = "hello"; } return $arr[$b]; }', ], 'noExceptionOnBracketString' => [ 'code' => ' [ 'code' => 'b)) { return $arr[1]->b; } throw new \Exception("bad"); }', ], 'allowUnknownAdditionToInt' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => '> $arr */ function foo(array $arr, string $k) : void { if (!isset($arr[$k])) { return; } if ($arr[$k][0]) {} }', ], 'mixedArrayIsset' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], ], 'mixedArrayIssetGetStringVar' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArgument'], ], 'noParadoxOnMultipleNotIssets' => [ 'code' => ' [ 'code' => ' rand(0,1) ? new DateTime : null, "two" => rand(0,1) ? new DateTime : null, "three" => new DateTime ]; if (!(isset($foo["one"]) || isset($foo["two"]))) { exit; } echo $foo["one"]->format("Y");', 'assertions' => [], 'ignored_issues' => ['PossiblyNullReference'], ], 'notIssetOneOrOtherWithoutAssert' => [ 'code' => ' rand(0,1) ? new DateTime : null, "two" => rand(0,1) ? new DateTime : null, "three" => new DateTime ]; $a = isset($foo["one"]) || isset($foo["two"]); echo $foo["one"]->format("Y");', 'assertions' => [], 'ignored_issues' => ['PossiblyNullReference'], ], 'notIssetOneOrOtherWithAssert' => [ 'code' => ' rand(0,1) ? new DateTime : null, "two" => rand(0,1) ? new DateTime : null, "three" => new DateTime ]; assert(isset($foo["one"]) || isset($foo["two"])); echo $foo["one"]->format("Y");', 'assertions' => [], 'ignored_issues' => ['PossiblyNullReference'], ], 'assertArrayAfterIssetStringOffset' => [ 'code' => ' [ 'code' => ' $val, "text" => $text]; } return $radio; }', 'assertions' => [], 'ignored_issues' => ['MixedAssignment'], ], 'assertAfterIsset' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment'], ], 'noCrashAfterIsset' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArrayOffset', 'InvalidArrayOffset'], ], 'sessionNullCoalesce' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'c])) { return; } if ($s !== "bar" && isset($a[$b->c])) { // do something } else { // something else } }', ], 'issetOnNestedObjectlikeOneLevel' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' 1, B::class => 2, C::class => 3, ]; public function foo(string $s) : int { $a = static::class; if (!isset(self::MAP[$a])) { throw new \Exception("bad"); } return self::MAP[$a]; } } class A extends P {} class B extends P {} class C extends P {}' ], 'accessAfterArrayExistsStaticClass' => [ 'code' => ' 1, B::class => 2, C::class => 3, ]; public function foo(string $s) : int { if (!isset(self::MAP[static::class])) { throw new \Exception("bad"); } return self::MAP[static::class]; } } class A extends P {} class B extends P {} class C extends P {}' ], 'issetCreateTKeyedArrayWithType' => [ 'code' => ' [ 'code' => ' [ 'code' => 's ?? false)) { return "foo"; } return "bar"; }', ], 'issetOnNullableObjectWithIsset' => [ 'code' => 's) ? $a->s : false)) { return "foo"; } return "bar"; }', ], 'issetOnMethodCallInsideFunctionCall' => [ 'code' => 'foo() ?? ""); }' ], 'issetOnMethodCallInsideMethodCall' => [ 'code' => 'foo() ?? ""); }', ], 'methodCallAfterIsset' => [ 'code' => 'foo)) { return; } if (rand(0, 1)) { $this->foo = new B; } else { $this->foo = new B; } $this->foo->bar(); } }' ], 'issetOnArrayOfArraysReturningStringInElse' => [ 'code' => '> */ $tokens = []; if (isset($tokens[$i]["a"])) { return "hello"; } else { return $tokens[$i]["b"]; } }', ], 'issetOnArrayOfObjectsAssertingOnIssetValue' => [ 'code' => ' */ $tokens = []; if (isset($tokens[$i]->name) && $tokens[$i]->name === "hello") {} }', ], 'issetOnArrayOfObjectsAssertingOnNotIssetValue' => [ 'code' => ' */ $tokens = []; if (!isset($tokens[$i])) { if (rand(0, 1)) { if (rand(0, 1)) { $tokens[$i] = new A(); } else { return; } } else { return; } } echo $tokens[$i]->name; }', ], 'issetOnArrayOfMixed' => [ 'code' => ' [ 'code' => ' */ $tokens = []; if (!isset($tokens[$i]["a"])) { echo $tokens[$i]["b"]; } }', ], 'issetOnArrayOfArrayOfStrings' => [ 'code' => '> */ $tokens = []; if (!isset($tokens[$i]["a"])) { echo $tokens[$i]["b"]; } }', ], 'noMixedMethodCallAfterIsset' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => [], 'php_version' => '8.0' ], 'assertComplex' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' 'UndefinedMethod', ], 'issetVariableKeysWithChange' => [ 'code' => ' 'NullArrayAccess', ], 'issetAdditionalVarWithSealedTKeyedArray' => [ 'code' => ' "bat"]; if (isset($params[self::FOO])) { return true; } return false; } }', 'error_message' => 'InvalidArrayOffset', ], 'listDestructuringErrorSuppress' => [ 'code' => ' 'NullableReturnStatement', ], 'undefinedVarInNullCoalesce' => [ 'code' => ' 'UndefinedVariable' ], 'issetNullVar' => [ 'code' => ' 'TypeDoesNotContainType', ], 'stringIsAlwaysSet' => [ 'code' => ' 'TypeDoesNotContainNull' ], 'issetOnArrayOfArraysReturningString' => [ 'code' => ' */ $tokens = []; if (!isset($tokens[$i]["a"])) { return $tokens[$i]["a"]; } return "hello"; }', 'error_message' => 'PossiblyUndefinedArrayOffset', ], 'accessAfterIssetCheckOnFalsableArray' => [ 'code' => ' "hello"] : []); } function foo() : void { $arr = returnPossiblyFalseArray(); /** @psalm-suppress PossiblyInvalidArrayAccess */ if (!isset($arr["b"])) {} echo $arr["b"]; }', 'error_message' => 'PossiblyInvalidArrayAccess', ], 'issetOnStaticProperty' => [ 'code' => ' 'RedundantPropertyInitializationCheck', ], 'negatedIssetOnStaticProperty' => [ 'code' => ' 'RedundantPropertyInitializationCheck', ], ]; } }