[ 'code' => ' [ '$a' => 'mixed|null', ], 'ignored_issues' => ['MixedAssignment'], ], 'emptyArrayVar' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], ], 'removeEmptyArray' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'getMessage() === "hello") { return "hello"; } elseif (empty($a)) { return "goodbye"; } return $a->getMessage(); }', ], 'noFalsyLeak' => [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArrayAccess'], ], 'dontBleedEmptyAfterExtract' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MixedArgument'], ], 'emptyTKeyedArray' => [ 'code' => ' [ "foo" => "bar", ], "groups" => [ "foo" => "bar", "hide" => rand(0, 5), ], ]; foreach ($arr as $item) { if (empty($item["hide"]) || $item["hide"] === 3) {} }', ], 'alwaysBoolResult' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MissingParamType'], ], 'canBeNonEmptyArray' => [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MissingParamType', 'MixedArgument'], ], 'multipleEmptiesInCondition' => [ 'code' => ' $o */ function foo(array $o) : void { if (empty($o[0]) && empty($o[1])) {} }', ], 'multipleEmptiesInConditionWithMixedOffset' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [], 'ignored_issues' => ['MixedAssignment', 'MissingParamType', 'MixedArgument', 'MixedArrayOffset', 'MixedArrayAccess'], ], 'possiblyEmptyIterable' => [ 'code' => ' [ 'code' => ' $data */ function bat(array $data) : void { if (!empty($data["foo"])) { if (empty($data[Foo::BAR])) {} } } /** * @param array $data */ function baz(array $data) : void { if (!empty($data[0])) { if (empty($data[Foo::ONE])) {} } }', ], 'doubleEmptyCheckTwoArrays' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => 'b)) {} }', ], 'allowNumericEmpty' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' 0 ? $str : "string"; }', ], 'SKIPPED-strlenRighthandWithGreaterZero' => [ 'code' => ' [ 'code' => '= 1 ? $str : "string"; }', ], 'SKIPPED-strlenRighthandWithGreaterEqualsOne' => [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ 'code' => ' [ // #8163 'code' => ' */ $arr = [1]; assert(count($arr) === $c); ', 'assertions' => ['$arr===' => 'non-empty-list'], ], 'SKIPPED-countWithIntRange' => [ // #8163 'code' => ' */ $c = 1; /** @var list */ $arr = [1]; assert(count($arr) === $c); ', 'assertions' => ['$arr===' => 'non-empty-list'], ], 'SKIPPED-countEmptyWithIntRange' => [ // #8163 'code' => ' */ $c = 1; /** @var list */ $arr = [1]; assert(count($arr) === $c); ', 'assertions' => ['$arr===' => 'list'], ], 'issue-9205-1' => [ 'code' => <<<'PHP' [ '$lastLabel===' => 'string', ], ], 'issue-9205-2' => [ 'code' => <<<'PHP' 0) { exit; } PHP, 'assertions' => [ '$x===' => 'string', // perhaps this should be improved in future ], ], 'issue-9205-3' => [ 'code' => <<<'PHP' [ '$x===' => 'string', // can't be improved really ], ], 'issue-9205-4' => [ 'code' => <<<'PHP' [ '$x===' => 'string', // can be improved ], ], 'issue-9349' => [ 'code' => <<<'PHP' [ '$str===' => 'non-falsy-string', // can't be improved ], ], 'issue-9349-2' => [ 'code' => <<<'PHP' [ 'code' => <<<'PHP' [ '$a===' => 'string', // can't be improved ], ], 'issue-9341-1' => [ 'code' => <<<'PHP' 2) { exit; } PHP, 'assertions' => [ '$GLOBALS[\'sql_query\']===' => 'string', ], ], ]; } public function providerInvalidCodeParse(): iterable { return [ 'preventImpossibleEmpty' => [ 'code' => ' 'UndefinedVariable', ], 'reconciliationForMixed' => [ 'code' => ' 'RedundantCondition', 'ignored_issues' => ['MixedAssignment', 'MissingParamType'], ], 'preventEmptyOnBool' => [ 'code' => ' 'InvalidArgument', ], 'preventEmptyCreatingArray' => [ 'code' => ' 'MixedReturnTypeCoercion', ], 'preventEmptyEquivalentCreatingArray' => [ 'code' => ' 'MixedReturnTypeCoercion', ], 'SKIPPED-preventStrlenGreaterMinusOne' => [ 'code' => ' -1 ? $str : "string"; }', 'error_message' => 'LessSpecificReturnStatement', ], 'SKIPPED-preventRighthandStrlenGreaterMinusOne' => [ 'code' => ' 'LessSpecificReturnStatement', ], 'SKIPPED-preventStrlenGreaterEqualsZero' => [ 'code' => '= 0 ? $str : "string"; }', 'error_message' => 'LessSpecificReturnStatement', ], 'SKIPPED-preventStrlenEqualsZero' => [ 'code' => ' 'InvalidReturnStatement', ], 'SKIPPED-preventStrlenLessThanOne' => [ 'code' => ' 'InvalidReturnStatement', ], 'SKIPPED-preventStrlenLessEqualsZero' => [ 'code' => ' 'InvalidReturnStatement', ], 'SKIPPED-preventStrlenWithConcatenatedString' => [ 'code' => ' 2 ? $str : "string"; }', 'error_message' => 'LessSpecificReturnStatement', ], ]; } }