Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider optional keys in ConstantArrayType removeFirst and removeLast
- Loading branch information
Showing
5 changed files
with
146 additions
and
21 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
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,53 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace ArrayPop; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function nonEmpty(array $arr): void | ||
{ | ||
/** @var non-empty-array<string> $arr */ | ||
assertType('string', array_pop($arr)); | ||
assertType('array<string>', $arr); | ||
} | ||
|
||
public function normalArrays(array $arr): void | ||
{ | ||
/** @var array<int, string> $arr */ | ||
assertType('string|null', array_pop($arr)); | ||
assertType('array<int, string>', $arr); | ||
} | ||
|
||
public function compoundTypes(array $arr): void | ||
{ | ||
/** @var string[]|int[] $arr */ | ||
assertType('int|string|null', array_pop($arr)); | ||
assertType('array<int|string>', $arr); | ||
} | ||
|
||
public function constantArrays(array $arr): void | ||
{ | ||
/** @var array{a: 0, b: 1, c: 2} $arr */ | ||
assertType('2', array_pop($arr)); | ||
assertType('array{a: 0, b: 1}', $arr); | ||
} | ||
|
||
public function constantArraysWithOptionalKeys(array $arr): void | ||
{ | ||
/** @var array{a?: 0, b: 1, c: 2} $arr */ | ||
assertType('0|2', array_pop($arr)); // should be 2 | ||
assertType('array{a?: 0, b: 1}', $arr); | ||
|
||
/** @var array{a: 0, b?: 1, c: 2} $arr */ | ||
assertType('1|2', array_pop($arr)); // should be 2 | ||
assertType('array{a: 0, b?: 1}', $arr); | ||
|
||
/** @var array{a: 0, b: 1, c?: 2} $arr */ | ||
assertType('1|2', array_pop($arr)); | ||
assertType('array{a: 0, b?: 1}', $arr); | ||
} | ||
|
||
} |
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,53 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace ArrayShift; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function nonEmpty(array $arr): void | ||
{ | ||
/** @var non-empty-array<string> $arr */ | ||
assertType('string', array_shift($arr)); | ||
assertType('array<string>', $arr); | ||
} | ||
|
||
public function normalArrays(array $arr): void | ||
{ | ||
/** @var array<int, string> $arr */ | ||
assertType('string|null', array_shift($arr)); | ||
assertType('array<int, string>', $arr); | ||
} | ||
|
||
public function compoundTypes(array $arr): void | ||
{ | ||
/** @var string[]|int[] $arr */ | ||
assertType('int|string|null', array_shift($arr)); | ||
assertType('array<int|string>', $arr); | ||
} | ||
|
||
public function constantArrays(array $arr): void | ||
{ | ||
/** @var array{a: 0, b: 1, c: 2} $arr */ | ||
assertType('0', array_shift($arr)); | ||
assertType('array{b: 1, c: 2}', $arr); | ||
} | ||
|
||
public function constantArraysWithOptionalKeys(array $arr): void | ||
{ | ||
/** @var array{a?: 0, b: 1, c: 2} $arr */ | ||
assertType('1', array_shift($arr)); // should be 0|1 | ||
assertType('array{b?: 1, c: 2}', $arr); | ||
|
||
/** @var array{a: 0, b?: 1, c: 2} $arr */ | ||
assertType('0', array_shift($arr)); | ||
assertType('array{b?: 1, c: 2}', $arr); | ||
|
||
/** @var array{a: 0, b: 1, c?: 2} $arr */ | ||
assertType('0', array_shift($arr)); | ||
assertType('array{b: 1, c?: 2}', $arr); | ||
} | ||
|
||
} |