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#4906 Closes phpstan/phpstan#4165 Closes phpstan/phpstan#4910 Closes phpstan/phpstan#3703
- Loading branch information
1 parent
f206515
commit c728038
Showing
6 changed files
with
164 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,36 @@ | ||
<?php | ||
|
||
namespace Bug4165; | ||
|
||
interface Client | ||
{ | ||
/** | ||
* @return 'int'|'stg'|'prd' | ||
*/ | ||
public function env(): string; | ||
} | ||
|
||
final class ComparisonKeysBuilder | ||
{ | ||
private Client $client; | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* @phpstan-return array<'int'|'stg'|'prd', int> | ||
*/ | ||
public function __invoke(): array | ||
{ | ||
$result = [ | ||
'int' => 3, | ||
'stg' => 4, | ||
'prd' => 5 | ||
]; | ||
|
||
$result[$this->client->env()] = 42; | ||
|
||
return $result; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Bug3703; | ||
|
||
class Foo { | ||
/** | ||
* @var array<string, array<string, int[]>> | ||
*/ | ||
public $bar; | ||
|
||
public function doFoo() | ||
{ | ||
$foo = new self(); | ||
// Should not be allowed (missing string key) | ||
$foo->bar['foo']['bar'][] = 'ok'; | ||
|
||
// Should not be allowed (value should be array) | ||
$foo->bar['foo']['bar'] = 1; | ||
|
||
// Should not be allowed | ||
$foo->bar['ok'] = 'ok'; | ||
} | ||
|
||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Bug4906; | ||
|
||
class Connection | ||
{ | ||
/** | ||
* @var array<string,mixed> | ||
* @phpstan-var array<string,mixed> | ||
* @psalm-var Params | ||
*/ | ||
private $params; | ||
} | ||
|
||
class HelloWorld | ||
{ | ||
/** | ||
* @var array<string,mixed> | ||
*/ | ||
private $connectionParameters; | ||
|
||
private function overrideConnectionParameters(): void | ||
{ | ||
$overrideConnectionParameters = \Closure::bind(function (array $connectionParameters) { | ||
foreach ($connectionParameters as $parameterKey => $parameterValue) { | ||
$this->params[$parameterKey] = $parameterValue; | ||
} | ||
}, $this, Connection::class); | ||
$overrideConnectionParameters($this->connectionParameters); | ||
} | ||
|
||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Bug4910; | ||
|
||
class Facing{ | ||
public const NORTH = 2; | ||
public const SOUTH = 3; | ||
public const WEST = 4; | ||
public const EAST = 5; | ||
} | ||
|
||
/** | ||
* @phpstan-type VineAcceptedFaces Facing::NORTH|Facing::EAST|Facing::SOUTH|Facing::WEST | ||
*/ | ||
class Vine{ | ||
/** | ||
* @var int[] | ||
* @phpstan-var array<VineAcceptedFaces, VineAcceptedFaces> | ||
*/ | ||
protected $faces = []; | ||
|
||
/** | ||
* @param int[] $faces | ||
* @phpstan-param list<VineAcceptedFaces> $faces | ||
* @return $this | ||
*/ | ||
public function setFaces(array $faces) : self{ | ||
$uniqueFaces = []; | ||
foreach($faces as $face){ | ||
if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){ | ||
throw new \InvalidArgumentException("Facing can only be north, east, south or west"); | ||
} | ||
$uniqueFaces[$face] = $face; | ||
} | ||
|
||
$this->faces = $uniqueFaces; | ||
return $this; | ||
} | ||
} |