mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Simplified InArrayTest a bit
This commit is contained in:
parent
568a9e0412
commit
a4b6fbcbdf
@ -33,20 +33,16 @@ class InArrayTest extends \Psalm\Tests\TestCase
|
|||||||
/**
|
/**
|
||||||
* @param int|null $x
|
* @param int|null $x
|
||||||
* @param non-empty-list<int> $y
|
* @param non-empty-list<int> $y
|
||||||
* @return int|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
function assertInArray($x, $y) {
|
function assertInArray($x, $y) {
|
||||||
if (in_array($x, $y, true)) {
|
if (in_array($x, $y, true)) {
|
||||||
acceptInt($x);
|
return $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $x;
|
throw new \Exception();
|
||||||
}
|
}
|
||||||
/**
|
',
|
||||||
* @param int $x
|
|
||||||
*/
|
|
||||||
function acceptInt($x): void {
|
|
||||||
}',
|
|
||||||
],
|
],
|
||||||
'typeNotChangedAfterAssertionAgainstArrayOfMixed' => [
|
'typeNotChangedAfterAssertionAgainstArrayOfMixed' => [
|
||||||
'<?php
|
'<?php
|
||||||
@ -68,20 +64,15 @@ class InArrayTest extends \Psalm\Tests\TestCase
|
|||||||
/**
|
/**
|
||||||
* @param int|string|bool $x
|
* @param int|string|bool $x
|
||||||
* @param non-empty-list<int|string> $y
|
* @param non-empty-list<int|string> $y
|
||||||
* @return int|string|bool
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
function assertInArray($x, $y) {
|
function assertInArray($x, $y) {
|
||||||
if (in_array($x, $y, true)) {
|
if (in_array($x, $y, true)) {
|
||||||
acceptIntAndStr($x);
|
return $x;
|
||||||
}
|
}
|
||||||
|
throw new \Exception();
|
||||||
return $x;
|
|
||||||
}
|
}
|
||||||
/**
|
',
|
||||||
* @param int|string $x
|
|
||||||
*/
|
|
||||||
function acceptIntAndStr($x): void {
|
|
||||||
}',
|
|
||||||
],
|
],
|
||||||
'unionTypesReducedToIntersectionWithinAssertion' => [
|
'unionTypesReducedToIntersectionWithinAssertion' => [
|
||||||
'<?php
|
'<?php
|
||||||
@ -150,8 +141,8 @@ class InArrayTest extends \Psalm\Tests\TestCase
|
|||||||
'<?php
|
'<?php
|
||||||
/**
|
/**
|
||||||
* @param string|bool $x
|
* @param string|bool $x
|
||||||
* @param non-empty-list<\'a\'|\'b\'|int> $y
|
* @param non-empty-list<"a"|"b"|int> $y
|
||||||
* @return \'a\'|\'b\'
|
* @return "a"|"b"
|
||||||
*/
|
*/
|
||||||
function assertInArray($x, $y) {
|
function assertInArray($x, $y) {
|
||||||
if (in_array($x, $y, true)) {
|
if (in_array($x, $y, true)) {
|
||||||
@ -164,8 +155,8 @@ class InArrayTest extends \Psalm\Tests\TestCase
|
|||||||
'assertAgainstListOfLiteralsAndScalarUnionTypeHint' => [
|
'assertAgainstListOfLiteralsAndScalarUnionTypeHint' => [
|
||||||
'<?php
|
'<?php
|
||||||
/**
|
/**
|
||||||
* @param non-empty-list<\'a\'|\'b\'|int> $y
|
* @param non-empty-list<"a"|"b"|int> $y
|
||||||
* @return \'a\'|\'b\'
|
* @return "a"|"b"
|
||||||
*/
|
*/
|
||||||
function assertInArray(string|bool $x, $y) {
|
function assertInArray(string|bool $x, $y) {
|
||||||
if (in_array($x, $y, true)) {
|
if (in_array($x, $y, true)) {
|
||||||
@ -192,42 +183,32 @@ class InArrayTest extends \Psalm\Tests\TestCase
|
|||||||
/**
|
/**
|
||||||
* @param int|null $x
|
* @param int|null $x
|
||||||
* @param non-empty-list<mixed> $y
|
* @param non-empty-list<mixed> $y
|
||||||
* @return int|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
function assertInArray($x, $y) {
|
function assertInArray($x, $y) {
|
||||||
if (!in_array($x, $y, true)) {
|
if (!in_array($x, $y, true)) {
|
||||||
acceptInt($x);
|
return $x;
|
||||||
}
|
}
|
||||||
|
throw new \Exception();
|
||||||
return $x;
|
|
||||||
}
|
}
|
||||||
/**
|
',
|
||||||
* @param int $x
|
'error_message' => 'NullableReturnStatement',
|
||||||
*/
|
|
||||||
function acceptInt($x): void {
|
|
||||||
}',
|
|
||||||
'error_message' => 'PossiblyNullArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:39 - Argument 1 of acceptInt cannot be null, possibly null value provided',
|
|
||||||
],
|
],
|
||||||
'typeNotChangedAfterNegatedAssertionAgainstUnsealedArrayOfUnionType' => [
|
'typeNotChangedAfterNegatedAssertionAgainstUnsealedArrayOfUnionType' => [
|
||||||
'<?php
|
'<?php
|
||||||
/**
|
/**
|
||||||
* @param int|null $x
|
* @param int|null $x
|
||||||
* @param non-empty-list<int|null> $y
|
* @param non-empty-list<int|null> $y
|
||||||
* @return int|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
function assertInArray($x, $y) {
|
function assertInArray($x, $y) {
|
||||||
if (!in_array($x, $y, true)) {
|
if (!in_array($x, $y, true)) {
|
||||||
acceptInt($x);
|
return $x;
|
||||||
}
|
}
|
||||||
|
throw new \Exception();
|
||||||
return $x;
|
|
||||||
}
|
}
|
||||||
/**
|
',
|
||||||
* @param int $x
|
'error_message' => 'NullableReturnStatement',
|
||||||
*/
|
|
||||||
function acceptInt($x): void {
|
|
||||||
}',
|
|
||||||
'error_message' => 'PossiblyNullArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:39 - Argument 1 of acceptInt cannot be null, possibly null value provided',
|
|
||||||
],
|
],
|
||||||
'initialTypeRemainsOutsideOfAssertion' => [
|
'initialTypeRemainsOutsideOfAssertion' => [
|
||||||
'<?php
|
'<?php
|
||||||
|
Loading…
Reference in New Issue
Block a user