mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
namespace Psalm\Tests;
|
|
|
|
class ForeachTest extends TestCase
|
|
{
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function providerFileCheckerInvalidCodeParse()
|
|
{
|
|
return [
|
|
'continueOutsideLoop' => [
|
|
'<?php
|
|
continue;',
|
|
'error_message' => 'ContinueOutsideLoop',
|
|
],
|
|
'invalidIterator' => [
|
|
'<?php
|
|
foreach (5 as $a) {
|
|
|
|
}',
|
|
'error_message' => 'InvalidIterator',
|
|
],
|
|
'rawObjectIteration' => [
|
|
'<?php
|
|
class A {
|
|
/** @var ?string */
|
|
public $foo;
|
|
}
|
|
|
|
class B extends A {}
|
|
|
|
function bar(A $a) : void {}
|
|
|
|
$arr = [];
|
|
|
|
if (rand(0, 10) > 5) {
|
|
$arr[] = new A;
|
|
} else {
|
|
$arr = new B;
|
|
}
|
|
|
|
foreach ($arr as $a) {
|
|
bar($a);
|
|
}',
|
|
'error_message' => 'RawObjectIteration',
|
|
],
|
|
];
|
|
}
|
|
}
|