[ '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"])) { }', ], '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(""); $doc->getElementsByTagName("node")[0];' ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { 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 - Cannot access ' . 'value on variable $params using offset value of', ], 'missingArrayOffsetAfterUnset' => [ ' "value", "b" => "value"]; unset($x["a"]); echo $x["a"];', 'error_message' => 'InvalidArrayOffset', ], ]; } }