Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes phpstan/phpstan#2420 Closes phpstan/phpstan#2718 Closes phpstan/phpstan#3126 Closes phpstan/phpstan#4586 Closes phpstan/phpstan#4887
- Loading branch information
1 parent
edc1e71
commit c17a331
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Bug2420; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
const CONFIG = [ | ||
0 => false, | ||
1 => false, | ||
]; | ||
|
||
public function sayHello(int $key): void | ||
{ | ||
$config = self::CONFIG[$key] ?? true; | ||
assertType('bool', $config); | ||
} | ||
} | ||
|
||
class HelloWorld2 | ||
{ | ||
const CONFIG = [ | ||
0 => ['foo' => false], | ||
1 => ['foo' => false], | ||
]; | ||
|
||
public function sayHello(int $key): void | ||
{ | ||
$config = self::CONFIG[$key]['foo'] ?? true; | ||
assertType('bool', $config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Bug2218; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo() | ||
{ | ||
$fun = function (): array { | ||
return [ | ||
['group_id' => 'a', 'user_id' => 'id1'], | ||
['group_id' => 'a', 'user_id' => 'id2'], | ||
['group_id' => 'a', 'user_id' => 'id3'], | ||
['group_id' => 'b', 'user_id' => 'id4'], | ||
['group_id' => 'b', 'user_id' => 'id5'], | ||
['group_id' => 'b', 'user_id' => 'id6'], | ||
]; | ||
}; | ||
|
||
$orders = $fun(); | ||
|
||
$result = []; | ||
foreach ($orders as $order) { | ||
assertType('bool', isset($result[$order['group_id']]['users'])); | ||
if (isset($result[$order['group_id']]['users'])) { | ||
$result[$order['group_id']]['users'][] = $order['user_id']; | ||
continue; | ||
} | ||
|
||
$result[$order['group_id']] = [ | ||
'users' => [ | ||
$order['user_id'], | ||
], | ||
]; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Bug3126; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param array<int,string> $input | ||
*/ | ||
function failure(array $input): void { | ||
$results = []; | ||
|
||
foreach ($input as $keyOne => $layerOne) { | ||
assertType('bool', isset($results[$keyOne]['name'])); | ||
if(isset($results[$keyOne]['name']) === false) { | ||
$results[$keyOne]['name'] = $layerOne; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param array<int,string> $input | ||
*/ | ||
function no_failure(array $input): void { | ||
$results = []; | ||
|
||
foreach ($input as $keyOne => $layerOne) { | ||
if(isset($results[$keyOne]) === false) { | ||
$results[$keyOne] = $layerOne; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Bug4586; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(): void | ||
{ | ||
assertType('bool', isset($_SESSION)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Bug4887; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
assertType('bool', isset($_SESSION)); | ||
|
||
$foo = ['$_REQUEST' => $_REQUEST, | ||
'$_COOKIE' => $_COOKIE, | ||
'$_SERVER' => $_SERVER, | ||
'$GLOBALS' => $GLOBALS, | ||
'$SESSION' => isset($_SESSION) ? $_SESSION : NULL]; | ||
|
||
foreach ($foo as $data) | ||
{ | ||
assertType('bool', is_array($data)); | ||
} |