1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Split up LoopScopeTest into block-specific tests

This commit is contained in:
Matthew Brown 2018-11-09 19:54:10 -05:00
parent ead7d62d48
commit 461a9667b5
4 changed files with 676 additions and 600 deletions

191
tests/Loop/DoTest.php Normal file
View File

@ -0,0 +1,191 @@
<?php
namespace Psalm\Tests\Loop;
use Psalm\Tests\Traits;
class DoTest extends \Psalm\Tests\TestCase
{
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'doWhileVar' => [
'<?php
$worked = false;
do {
$worked = true;
}
while (rand(0,100) === 10);',
'assertions' => [
'$worked' => 'bool',
],
],
'doWhileUndefinedVar' => [
'<?php
do {
$result = rand(0,1);
} while (!$result);',
],
'doWhileVarAndBreak' => [
'<?php
/** @return void */
function foo(string $b) {}
do {
if (null === ($a = rand(0, 1) ? "hello" : null)) {
break;
}
foo($a);
}
while (rand(0,100) === 10);',
],
'doWhileWithNotEmptyCheck' => [
'<?php
class A {
/** @var A|null */
public $a;
public function __construct() {
$this->a = rand(0, 1) ? new A : null;
}
}
function takesA(A $a): void {}
$a = new A();
do {
takesA($a);
$a = $a->a;
} while ($a);',
'assertions' => [
'$a' => 'null',
],
],
'doWhileWithMethodCall' => [
'<?php
class A {
public function getParent(): ?A {
return rand(0, 1) ? new A() : null;
}
}
$a = new A();
do {
$a = $a->getParent();
} while ($a);',
'assertions' => [
'$a' => 'null',
],
],
'doWhileFirstGood' => [
'<?php
do {
$done = rand(0, 1) > 0;
} while (!$done);',
],
'doWhileWithIfException' => [
'<?php
class A
{
/**
* @var null|A
*/
public $parent;
public static function foo(A $a) : void
{
do {
if ($a->parent === null) {
throw new \Exception("bad");
}
$a = $a->parent;
} while (rand(0,1));
}
}',
],
'doWhileWithIfExceptionOutside' => [
'<?php
class A
{
/**
* @var null|A
*/
public $parent;
public static function foo(A $a) : void
{
if ($a->parent === null) {
throw new \Exception("bad");
}
do {
$a = $a->parent;
} while ($a->parent && rand(0, 1));
}
}',
],
'doWhileDefinedVar' => [
'<?php
$value = null;
do {
$count = rand(0, 1);
$value = 6;
} while ($count);',
],
'invalidateBothByRefAssignmentsInDo' => [
'<?php
function foo(?string &$i) : void {}
function bar(?string &$i) : void {}
$c = null;
do {
if (!$c) {
foo($c);
} else {
bar($c);
}
} while (rand(0, 1));',
],
'doParentCall' => [
'<?php
class A {
/** @return A|false */
public function getParent() {
return rand(0, 1) ? new A : false;
}
}
$a = new A();
do {
$a = $a->getParent();
} while ($a !== false);',
],
'doWithContinue' => [
'<?php
do {
if (rand(0, 1)) {
continue;
}
} while (rand(0, 1));',
],
'noEmptyArrayAccessComplaintInsideDo' => [
'<?php
$foo = [];
do {
if (isset($foo["bar"])) {}
$foo["bar"] = "bat";
} while (rand(0, 1));',
],
];
}
}

115
tests/Loop/ForTest.php Normal file
View File

@ -0,0 +1,115 @@
<?php
namespace Psalm\Tests\Loop;
use Psalm\Tests\Traits;
class ForTest extends \Psalm\Tests\TestCase
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'implicitFourthLoop' => [
'<?php
function test(): int {
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
$x = $y;
$y = $z;
$z = 5;
}
return $x;
}',
],
'falseToBoolInContinueAndBreak' => [
'<?php
$a = false;
for ($i = 0; $i < 4; $i++) {
$j = rand(0, 10);
if ($j === 2) {
$a = true;
continue;
}
if ($j === 3) {
$a = true;
break;
}
}',
'assignments' => [
'$a' => 'bool',
],
],
'forLoopwithOKChange' => [
'<?php
$j = 5;
for ($i = $j; $i < 4; $i++) {
$j = 9;
}',
],
'preventNegativeZeroScrewingThingsUp' => [
'<?php
function foo() : void {
$v = [1 => 0];
for ($d = 0; $d <= 10; $d++) {
for ($k = -$d; $k <= $d; $k += 2) {
if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) {
$x = $v[$k+1];
} else {
$x = $v[$k-1] + 1;
}
$v[$k] = $x;
}
}
}'
],
];
}
/**
* @return array
*/
public function providerFileCheckerInvalidCodeParse()
{
return [
'possiblyUndefinedArrayInWhileAndForeach' => [
'<?php
for ($i = 0; $i < 4; $i++) {
while (rand(0,10) === 5) {
$array[] = "hello";
}
}
echo $array;',
'error_message' => 'PossiblyUndefinedGlobalVariable - src' . DIRECTORY_SEPARATOR . 'somefile.php:4 - Possibly undefined ' .
'global variable $array, first seen on line 4',
],
'forLoopInvalidation' => [
'<?php
for ($i = 0; $i < 4; $i++) {
foreach ([1, 2, 3] as $i) {}
}',
'error_message' => 'LoopInvalidation',
],
'forInfiniteNoBreak' => [
'<?php
for (;;) {
$a = "hello";
}
echo $a;',
'error_message' => 'UndefinedGlobalVariable',
],
];
}
}

View File

@ -1,7 +1,9 @@
<?php
namespace Psalm\Tests;
namespace Psalm\Tests\Loop;
class LoopScopeTest extends TestCase
use Psalm\Tests\Traits;
class ForeachTest extends \Psalm\Tests\TestCase
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
@ -88,150 +90,6 @@ class LoopScopeTest extends TestCase
$moo = $foo;
}',
],
'whileVar' => [
'<?php
$worked = false;
while (rand(0,100) === 10) {
$worked = true;
}',
'assertions' => [
'$worked' => 'bool',
],
],
'doWhileVar' => [
'<?php
$worked = false;
do {
$worked = true;
}
while (rand(0,100) === 10);',
'assertions' => [
'$worked' => 'bool',
],
],
'doWhileUndefinedVar' => [
'<?php
do {
$result = rand(0,1);
} while (!$result);',
],
'doWhileVarAndBreak' => [
'<?php
/** @return void */
function foo(string $b) {}
do {
if (null === ($a = rand(0, 1) ? "hello" : null)) {
break;
}
foo($a);
}
while (rand(0,100) === 10);',
],
'objectValueWithTwoTypes' => [
'<?php
class B {}
class A {
/** @var A|B */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): new B();
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a instanceof A) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'B',
],
],
'objectValueWithInstanceofProperty' => [
'<?php
class B {}
class A {
/** @var A|B */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): new B();
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a->parent instanceof A) {
$a = $a->parent;
}
$b = $a->parent;',
'assertions' => [
'$a' => 'A',
'$b' => 'A|B',
],
],
'objectValueNullable' => [
'<?php
class A {
/** @var ?A */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): null;
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'null',
],
],
'objectValueWithAnd' => [
'<?php
class A {
/** @var ?A */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): null;
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a && rand(0, 10) > 5) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'A|null',
],
],
'secondLoopWithNotNullCheck' => [
'<?php
/** @return void **/
@ -344,20 +202,6 @@ class LoopScopeTest extends TestCase
$a = $i;
}',
],
'implicitFourthLoop' => [
'<?php
function test(): int {
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
$x = $y;
$y = $z;
$z = 5;
}
return $x;
}',
],
'unsetInLoop' => [
'<?php
$a = null;
@ -439,15 +283,6 @@ class LoopScopeTest extends TestCase
return $merged;
}',
],
'loopWithNoParadox' => [
'<?php
$a = ["b", "c", "d"];
array_pop($a);
while ($a) {
$letter = array_pop($a);
if (!$a) {}
}',
],
'loopWithIfElseNoParadox' => [
'<?php
$a = [];
@ -703,27 +538,6 @@ class LoopScopeTest extends TestCase
'$a' => 'bool',
],
],
'falseToBoolInContinueAndBreak' => [
'<?php
$a = false;
for ($i = 0; $i < 4; $i++) {
$j = rand(0, 10);
if ($j === 2) {
$a = true;
continue;
}
if ($j === 3) {
$a = true;
break;
}
}',
'assignments' => [
'$a' => 'bool',
],
],
'falseToBoolAfterContinueAndBreak' => [
'<?php
$a = false;
@ -751,21 +565,6 @@ class LoopScopeTest extends TestCase
echo $a;
}',
],
'noRedundantConditionInWhileAssignment' => [
'<?php
class A {
/** @var ?int */
public $bar;
}
function foo(): ?A {
return rand(0, 1) ? new A : null;
}
while ($a = foo()) {
if ($a->bar) {}
}',
],
'noRedundantConditionAfterIsNumeric' => [
'<?php
$ids = [];
@ -791,26 +590,6 @@ class LoopScopeTest extends TestCase
'MixedAssignment', 'MixedArrayAccess',
],
],
'whileTrue' => [
'<?php
while (true) {
$a = "hello";
break;
}
while (1) {
$b = 5;
break;
}
for(;;) {
$c = true;
break;
}',
'assertions' => [
'$a' => 'string',
'$b' => 'int',
'$c' => 'true',
],
],
'foreachLoopWithOKManipulation' => [
'<?php
$list = [1, 2, 3];
@ -818,13 +597,6 @@ class LoopScopeTest extends TestCase
$i = 5;
}',
],
'forLoopwithOKChange' => [
'<?php
$j = 5;
for ($i = $j; $i < 4; $i++) {
$j = 9;
}',
],
'foreachLoopDuplicateList' => [
'<?php
$list = [1, 2, 3];
@ -832,158 +604,6 @@ class LoopScopeTest extends TestCase
foreach ($list as $j) {}
}',
],
'whileWithNotEmptyCheck' => [
'<?php
class A {
/** @var A|null */
public $a;
public function __construct() {
$this->a = rand(0, 1) ? new A : null;
}
}
function takesA(A $a): void {}
$a = new A();
while ($a) {
takesA($a);
$a = $a->a;
};',
'assertions' => [
'$a' => 'null',
],
],
'doWhileWithNotEmptyCheck' => [
'<?php
class A {
/** @var A|null */
public $a;
public function __construct() {
$this->a = rand(0, 1) ? new A : null;
}
}
function takesA(A $a): void {}
$a = new A();
do {
takesA($a);
$a = $a->a;
} while ($a);',
'assertions' => [
'$a' => 'null',
],
],
'doWhileWithMethodCall' => [
'<?php
class A {
public function getParent(): ?A {
return rand(0, 1) ? new A() : null;
}
}
$a = new A();
do {
$a = $a->getParent();
} while ($a);',
'assertions' => [
'$a' => 'null',
],
],
'doWhileFirstGood' => [
'<?php
do {
$done = rand(0, 1) > 0;
} while (!$done);',
],
'doWhileWithIfException' => [
'<?php
class A
{
/**
* @var null|A
*/
public $parent;
public static function foo(A $a) : void
{
do {
if ($a->parent === null) {
throw new \Exception("bad");
}
$a = $a->parent;
} while (rand(0,1));
}
}',
],
'doWhileWithIfExceptionOutside' => [
'<?php
class A
{
/**
* @var null|A
*/
public $parent;
public static function foo(A $a) : void
{
if ($a->parent === null) {
throw new \Exception("bad");
}
do {
$a = $a->parent;
} while ($a->parent && rand(0, 1));
}
}',
],
'whileInstanceOf' => [
'<?php
class A {
/** @var null|A */
public $parent;
}
class B extends A {}
$a = new A();
while ($a->parent instanceof B) {
$a = $a->parent;
}',
],
'whileInstanceOfAndNotEmptyCheck' => [
'<?php
class A {
/** @var null|A */
public $parent;
}
class B extends A {}
$a = (new A())->parent;
$foo = rand(0, 1) ? "hello" : null;
if (!$foo) {
while ($a instanceof B && !$foo) {
$a = $a->parent;
$foo = rand(0, 1) ? "hello" : null;
}
}',
],
'doWhileDefinedVar' => [
'<?php
$value = null;
do {
$count = rand(0, 1);
$value = 6;
} while ($count);',
],
'arrayKeyJustSetInLoop' => [
'<?php
$a = null;
@ -999,152 +619,6 @@ class LoopScopeTest extends TestCase
}
}',
],
'noRedundantConditionAfterArrayAssignment' => [
'<?php
$data = ["a" => false];
while (!$data["a"]) {
if (rand() % 2 > 0) {
$data = ["a" => true];
}
}',
],
'additionSubtractionOps' => [
'<?php
$a = 0;
while (rand(0, 1)) {
if (rand(0, 1)) {
$a++;
} elseif ($a) {
$a--;
}
}'
],
'invalidateBothByRefAssignments' => [
'<?php
function foo(?string &$i) : void {}
function bar(?string &$i) : void {}
$c = null;
while (rand(0, 1)) {
if (!$c) {
foo($c);
} else {
bar($c);
}
}',
],
'invalidateBothByRefAssignmentsInDo' => [
'<?php
function foo(?string &$i) : void {}
function bar(?string &$i) : void {}
$c = null;
do {
if (!$c) {
foo($c);
} else {
bar($c);
}
} while (rand(0, 1));',
],
'applyLoopConditionalAfterIf' => [
'<?php
class Obj {}
class A extends Obj {
/** @var A|null */
public $foo;
}
class B extends Obj {}
function foo(Obj $node) : void {
while ($node instanceof A
|| $node instanceof B
) {
if (!$node instanceof B) {
$node = $node->foo;
}
}
}',
],
'shouldBeFine' => [
'<?php
class Obj {}
class A extends Obj {
/** @var A|null */
public $foo;
}
class B extends Obj {
/** @var A|null */
public $foo;
}
class C extends Obj {
/** @var A|C|null */
public $bar;
}
function takesA(A $a) : void {}
function foo(Obj $node) : void {
while ($node instanceof A
|| $node instanceof B
|| ($node instanceof C && $node->bar instanceof A)
) {
if (!$node instanceof C) {
$node = $node->foo;
} else {
$node = $node->bar;
}
}
}',
],
'doParentCall' => [
'<?php
class A {
/** @return A|false */
public function getParent() {
return rand(0, 1) ? new A : false;
}
}
$a = new A();
do {
$a = $a->getParent();
} while ($a !== false);',
],
'doWithContinue' => [
'<?php
do {
if (rand(0, 1)) {
continue;
}
} while (rand(0, 1));',
],
'comparisonAfterContinue' => [
'<?php
$foo = null;
while (rand(0, 1)) {
if (rand(0, 1)) {
$foo = 1;
continue;
}
$a = rand(0, 1);
if ($a === $foo) {}
}',
],
'noEmptyArrayAccessComplaintInsideDo' => [
'<?php
$foo = [];
do {
if (isset($foo["bar"])) {}
$foo["bar"] = "bat";
} while (rand(0, 1));',
],
'updateExistingValueAfterLoopContinue' => [
'<?php
$i = false;
@ -1157,23 +631,6 @@ class LoopScopeTest extends TestCase
}
if ($i) {}',
],
'preventNegativeZeroScrewingThingsUp' => [
'<?php
function foo() : void {
$v = [1 => 0];
for ($d = 0; $d <= 10; $d++) {
for ($k = -$d; $k <= $d; $k += 2) {
if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) {
$x = $v[$k+1];
} else {
$x = $v[$k-1] + 1;
}
$v[$k] = $x;
}
}
}'
],
];
}
@ -1211,18 +668,6 @@ class LoopScopeTest extends TestCase
'error_message' => 'PossiblyUndefinedGlobalVariable - src' . DIRECTORY_SEPARATOR . 'somefile.php:3 - Possibly undefined ' .
'global variable $array, first seen on line 3',
],
'possiblyUndefinedArrayInWhileAndForeach' => [
'<?php
for ($i = 0; $i < 4; $i++) {
while (rand(0,10) === 5) {
$array[] = "hello";
}
}
echo $array;',
'error_message' => 'PossiblyUndefinedGlobalVariable - src' . DIRECTORY_SEPARATOR . 'somefile.php:4 - Possibly undefined ' .
'global variable $array, first seen on line 4',
],
'possiblyUndefinedVariableInForeach' => [
'<?php
foreach ([1, 2, 3, 4] as $b) {
@ -1326,24 +771,6 @@ class LoopScopeTest extends TestCase
}',
'error_message' => 'RedundantCondition',
],
'whileTrueNoBreak' => [
'<?php
while (true) {
$a = "hello";
}
echo $a;',
'error_message' => 'UndefinedGlobalVariable',
],
'forInfiniteNoBreak' => [
'<?php
for (;;) {
$a = "hello";
}
echo $a;',
'error_message' => 'UndefinedGlobalVariable',
],
'foreachLoopInvalidation' => [
'<?php
$list = [1, 2, 3];
@ -1352,29 +779,6 @@ class LoopScopeTest extends TestCase
}',
'error_message' => 'LoopInvalidation',
],
'forLoopInvalidation' => [
'<?php
for ($i = 0; $i < 4; $i++) {
foreach ([1, 2, 3] as $i) {}
}',
'error_message' => 'LoopInvalidation',
],
'invalidateByRefAssignmentWithRedundantCondition' => [
'<?php
function foo(?string $i) : void {}
function bar(?string $i) : void {}
$c = null;
while (rand(0, 1)) {
if (!$c) {
foo($c);
} else {
bar($c);
}
}',
'error_message' => 'RedundantCondition',
],
];
}
}

366
tests/Loop/WhileTest.php Normal file
View File

@ -0,0 +1,366 @@
<?php
namespace Psalm\Tests\Loop;
use Psalm\Tests\Traits;
class WhileTest extends \Psalm\Tests\TestCase
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'whileVar' => [
'<?php
$worked = false;
while (rand(0,100) === 10) {
$worked = true;
}',
'assertions' => [
'$worked' => 'bool',
],
],
'objectValueWithTwoTypes' => [
'<?php
class B {}
class A {
/** @var A|B */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): new B();
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a instanceof A) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'B',
],
],
'objectValueWithInstanceofProperty' => [
'<?php
class B {}
class A {
/** @var A|B */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): new B();
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a->parent instanceof A) {
$a = $a->parent;
}
$b = $a->parent;',
'assertions' => [
'$a' => 'A',
'$b' => 'A|B',
],
],
'objectValueNullable' => [
'<?php
class A {
/** @var ?A */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): null;
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'null',
],
],
'objectValueWithAnd' => [
'<?php
class A {
/** @var ?A */
public $parent;
public function __construct() {
$this->parent = rand(0, 1) ? new A(): null;
}
}
function makeA(): A {
return new A();
}
$a = makeA();
while ($a && rand(0, 10) > 5) {
$a = $a->parent;
}',
'assertions' => [
'$a' => 'A|null',
],
],
'loopWithNoParadox' => [
'<?php
$a = ["b", "c", "d"];
array_pop($a);
while ($a) {
$letter = array_pop($a);
if (!$a) {}
}',
],
'noRedundantConditionInWhileAssignment' => [
'<?php
class A {
/** @var ?int */
public $bar;
}
function foo(): ?A {
return rand(0, 1) ? new A : null;
}
while ($a = foo()) {
if ($a->bar) {}
}',
],
'whileTrue' => [
'<?php
while (true) {
$a = "hello";
break;
}
while (1) {
$b = 5;
break;
}
for(;;) {
$c = true;
break;
}',
'assertions' => [
'$a' => 'string',
'$b' => 'int',
'$c' => 'true',
],
],
'whileWithNotEmptyCheck' => [
'<?php
class A {
/** @var A|null */
public $a;
public function __construct() {
$this->a = rand(0, 1) ? new A : null;
}
}
function takesA(A $a): void {}
$a = new A();
while ($a) {
takesA($a);
$a = $a->a;
};',
'assertions' => [
'$a' => 'null',
],
],
'whileInstanceOf' => [
'<?php
class A {
/** @var null|A */
public $parent;
}
class B extends A {}
$a = new A();
while ($a->parent instanceof B) {
$a = $a->parent;
}',
],
'whileInstanceOfAndNotEmptyCheck' => [
'<?php
class A {
/** @var null|A */
public $parent;
}
class B extends A {}
$a = (new A())->parent;
$foo = rand(0, 1) ? "hello" : null;
if (!$foo) {
while ($a instanceof B && !$foo) {
$a = $a->parent;
$foo = rand(0, 1) ? "hello" : null;
}
}',
],
'noRedundantConditionAfterArrayAssignment' => [
'<?php
$data = ["a" => false];
while (!$data["a"]) {
if (rand() % 2 > 0) {
$data = ["a" => true];
}
}',
],
'additionSubtractionOps' => [
'<?php
$a = 0;
while (rand(0, 1)) {
if (rand(0, 1)) {
$a++;
} elseif ($a) {
$a--;
}
}'
],
'invalidateBothByRefAssignments' => [
'<?php
function foo(?string &$i) : void {}
function bar(?string &$i) : void {}
$c = null;
while (rand(0, 1)) {
if (!$c) {
foo($c);
} else {
bar($c);
}
}',
],
'applyLoopConditionalAfterIf' => [
'<?php
class Obj {}
class A extends Obj {
/** @var A|null */
public $foo;
}
class B extends Obj {}
function foo(Obj $node) : void {
while ($node instanceof A
|| $node instanceof B
) {
if (!$node instanceof B) {
$node = $node->foo;
}
}
}',
],
'shouldBeFine' => [
'<?php
class Obj {}
class A extends Obj {
/** @var A|null */
public $foo;
}
class B extends Obj {
/** @var A|null */
public $foo;
}
class C extends Obj {
/** @var A|C|null */
public $bar;
}
function takesA(A $a) : void {}
function foo(Obj $node) : void {
while ($node instanceof A
|| $node instanceof B
|| ($node instanceof C && $node->bar instanceof A)
) {
if (!$node instanceof C) {
$node = $node->foo;
} else {
$node = $node->bar;
}
}
}',
],
'comparisonAfterContinue' => [
'<?php
$foo = null;
while (rand(0, 1)) {
if (rand(0, 1)) {
$foo = 1;
continue;
}
$a = rand(0, 1);
if ($a === $foo) {}
}',
],
];
}
/**
* @return array
*/
public function providerFileCheckerInvalidCodeParse()
{
return [
'whileTrueNoBreak' => [
'<?php
while (true) {
$a = "hello";
}
echo $a;',
'error_message' => 'UndefinedGlobalVariable',
],
'invalidateByRefAssignmentWithRedundantCondition' => [
'<?php
function foo(?string $i) : void {}
function bar(?string $i) : void {}
$c = null;
while (rand(0, 1)) {
if (!$c) {
foo($c);
} else {
bar($c);
}
}',
'error_message' => 'RedundantCondition',
],
];
}
}