,error_levels?:string[]}> */ public function providerValidCodeParse() { return [ 'instanceOfStringOffset' => [ 'fooFoo(); } }', ], 'instanceOfIntOffset' => [ 'fooFoo(); } }', ], 'notEmptyStringOffset' => [ ' $a */ function bar (array $a): string { if ($a["bat"]) { return $a["bat"]; } return "blah"; }', ], 'issetPropertyStringOffset' => [ ' */ public $arr = []; } $a = new A(); if (!isset($a->arr["bat"]) || strlen($a->arr["bat"])) { }', ], 'issetPropertyStringOffsetUndefinedClass' => [ 'arr["bat"]) || strlen($a->arr["bat"])) { }', 'assertions' => [], 'error_levels' => ['MixedArgument'], ], 'notEmptyIntOffset' => [ ' $a */ function bar (array $a): string { if ($a[0]) { return $a[0]; } return "blah"; }', ], 'ignorePossiblyNullArrayAccess' => [ ' [], 'error_levels' => ['PossiblyNullArrayAccess'], ], 'ignoreEmptyArrayAccess' => [ ' [ '$x' => 'mixed', ], 'error_levels' => ['EmptyArrayAccess', 'MixedAssignment'], ], 'objectLikeWithoutKeys' => [ ' [ ' "01", "02" => "02"]; foreach ($array as $key => $value) { $len = strlen($key); }', ], 'listAssignmentKeyOffset' => [ ' [ ' [ ' "value"]; unset($x["a"]); $x[] = 5; takesInt($x[0]);', ], 'domNodeListAccessible' => [ 'loadXML(""); $e = $doc->getElementsByTagName("node")[0];', [ '$e' => 'null|DOMElement', ], ], 'getOnArrayAcccess' => [ ' $a */ function foo(ArrayAccess $a) : string { return $a[0]; }', ], 'mixedKeyMixedOffset' => [ ' [], 'error_levels' => ['MixedArgument', 'MixedArrayOffset', 'MissingParamType'], ], 'suppressPossiblyUndefinedStringArrayOffet' => [ ' $elt] = $entry; strlen($elt); strlen($entry["a"]);', 'assertions' => [], 'error_levels' => ['PossiblyUndefinedArrayOffset'], ], 'noRedundantConditionOnMixedArrayAccess' => [ ' */ $b = []; /** @var array */ $c = []; /** @var array */ $d = []; if (!empty($d[0]) && !isset($c[$d[0]])) { if (isset($b[$d[0]])) {} }', [], 'error_levels' => ['MixedArrayOffset'], ], 'noEmptyArrayAccessInLoop' => [ ' [ ' */ public $arr = []; } /** @var array */ $as = []; if (!$as || !$as[0] instanceof B || !$as[0]->arr ) { return null; } $b = $as[0]->arr;', ], 'arrayAccessAfterPassByref' => [ ' [ ' $_) {} if ($i === "hello") {} if ($i !== "hello") {} if ($i === 5) {} if ($i !== 5) {} if (is_string($i)) {} if (is_int($i)) {} foreach ($arr as $i => $_) {} if ($i === "hell") { $i = "hellp"; } if ($i === "hel") {} }', ], 'arrayKeyChecksAfterDefinition' => [ ' $_) {} if ($i === "hell") { $i = "hellp"; } if ($i === "hel") {} }', ], 'allowMixedTypeCoercionArrayKeyAccess' => [ ' $i * @param array $arr */ function foo(array $i, array $arr) : void { foreach ($i as $j => $k) { echo $arr[$j]; } }', 'assertions' => [], 'error_levels' => ['MixedTypeCoercion'], ], 'allowNegativeStringOffset' => [ ' [ ' 1, "b" => [ "c" => "a", ] ); if (rand(0, 1)) { $params = getArray(); } echo $params["b"]["c"];', [], ['MixedArrayAccess', 'MixedArgument'], ], ]; } /** * @return iterable */ public function providerInvalidCodeParse() { return [ 'invalidArrayAccess' => [ ' 'InvalidArrayAccess', ], 'invalidArrayOffset' => [ ' 'InvalidArrayOffset', ], 'possiblyInvalidArrayOffsetWithInt' => [ ' 2 ? ["a" => 5] : "hello"; $y = $x[0];', 'error_message' => 'PossiblyInvalidArrayOffset', ], 'possiblyInvalidArrayOffsetWithString' => [ ' 2 ? ["a" => 5] : "hello"; $y = $x["a"];', 'error_message' => 'PossiblyInvalidArrayOffset', ], 'possiblyInvalidArrayAccessWithNestedArray' => [ '>|string * @return string */ function return_array() { return rand() % 5 > 3 ? [["key" => 3.5]] : "key:3.5"; } $result = return_array(); $v = $result[0]["key"];', 'error_message' => 'PossiblyInvalidArrayOffset', ], 'possiblyInvalidArrayAccess' => [ ' 5 ? 5 : ["hello"]; echo $a[0];', 'error_message' => 'PossiblyInvalidArrayAccess', ], 'mixedArrayAccess' => [ ' 'MixedArrayAccess', 'error_level' => ['MixedAssignment'], ], 'mixedArrayOffset' => [ ' 'MixedArrayOffset', 'error_level' => ['MixedAssignment'], ], 'nullArrayAccess' => [ ' 'NullArrayAccess', ], 'possiblyNullArrayAccess' => [ ' 'PossiblyNullArrayAccess', ], 'specificErrorMessage' => [ ' "value"]; echo $params["fieldName"];', 'error_message' => 'InvalidArrayOffset - src' . DIRECTORY_SEPARATOR . 'somefile.php:3:26 - Cannot access ' . 'value on variable $params using offset value of', ], 'missingArrayOffsetAfterUnset' => [ ' "value", "b" => "value"]; unset($x["a"]); echo $x["a"];', 'error_message' => 'InvalidArrayOffset', ], 'noImpossibleStringAccess' => [ ' 'InvalidArrayOffset', ], 'mixedKeyStdClassOffset' => [ ' 'InvalidArrayOffset', ], 'toStringOffset' => [ ' "bar"]; echo $a[new Foo];', 'error_message' => 'InvalidArrayOffset', ], 'possiblyUndefinedIntArrayOffet' => [ ' 'PossiblyUndefinedArrayOffset', ], 'possiblyUndefinedStringArrayOffet' => [ ' $elt] = $entry;', 'error_message' => 'PossiblyUndefinedArrayOffset', ], 'possiblyInvalidMixedArrayOffset' => [ ' 'PossiblyInvalidArrayOffset', ], 'possiblyInvalidMixedUnionArrayOffset' => [ ' 'PossiblyInvalidArrayOffset', 'error_level' => ['MixedArrayAssignment'], ], 'arrayAccessOnIterable' => [ ' 'InvalidArrayAccess', ], 'arrayKeyCannotBeBool' => [ ' $_) {} if ($i === false) {} }', 'error_message' => 'TypeDoesNotContainType', ], 'arrayKeyCannotBeFloat' => [ ' $_) {} if ($i === 4.0) {} }', 'error_message' => 'TypeDoesNotContainType', ], 'arrayKeyCannotBeObject' => [ ' $_) {} if ($i === new stdClass) {} }', 'error_message' => 'TypeDoesNotContainType', ], 'forbidNegativeStringOffsetOutOfRange' => [ ' 'InvalidArrayOffset', ], 'emptyStringAccess' => [ ' 'InvalidArrayOffset', ], 'recogniseBadVar' => [ ' 'UndefinedGlobalVariable', ], ]; } }