1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 08:49:52 +01:00
psalm/tests/TypeCombinationTest.php

958 lines
30 KiB
PHP
Raw Normal View History

2016-06-16 02:16:40 +02:00
<?php
2016-07-26 00:37:44 +02:00
namespace Psalm\Tests;
2016-06-16 02:16:40 +02:00
2020-11-22 00:11:29 +01:00
use Psalm\Internal\Type\TypeCombiner;
2021-12-04 21:55:53 +01:00
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
2019-03-23 19:27:54 +01:00
use Psalm\Type;
2021-12-13 16:28:14 +01:00
use Psalm\Type\Atomic;
2016-06-16 02:16:40 +02:00
2022-12-19 19:24:03 +01:00
use function array_reverse;
class TypeCombinationTest extends TestCase
2016-06-16 02:16:40 +02:00
{
2021-12-04 21:55:53 +01:00
use ValidCodeAnalysisTestTrait;
2017-01-13 20:07:23 +01:00
/**
* @dataProvider providerTestValidTypeCombination
2020-01-30 05:55:27 +01:00
* @param non-empty-list<string> $types
2017-01-13 20:07:23 +01:00
*/
public function testValidTypeCombination(string $expected, array $types): void
2016-06-16 02:16:40 +02:00
{
2019-10-09 00:44:46 +02:00
$converted_types = [];
foreach ($types as $type) {
$converted_type = self::getAtomic($type);
2022-10-03 15:13:47 +02:00
/** @psalm-suppress InaccessibleProperty */
2020-03-15 04:54:42 +01:00
$converted_type->from_docblock = true;
2019-10-09 00:44:46 +02:00
$converted_types[] = $converted_type;
}
2017-05-27 02:05:57 +02:00
$this->assertSame(
$expected,
2022-12-18 17:15:15 +01:00
TypeCombiner::combine($converted_types)->getId(),
);
2022-12-19 19:24:03 +01:00
$this->assertSame(
$expected,
TypeCombiner::combine(array_reverse($converted_types))->getId(),
);
2016-06-16 02:16:40 +02:00
}
public function providerValidCodeParse(): iterable
{
return [
'multipleValuedArray' => [
'code' => '<?php
class A {}
class B {}
$var = [];
$var[] = new A();
2017-05-27 02:05:57 +02:00
$var[] = new B();',
],
'preventLiteralAndClassString' => [
'code' => '<?php
/**
* @param "array"|class-string $type_name
*/
function foo(string $type_name) : bool {
return $type_name === "array";
}',
],
'NeverTwice' => [
'code' => '<?php
/** @return no-return */
function other() {
throw new Exception();
}
rand(0,1) ? die() : other();',
],
2021-10-18 21:51:36 +02:00
'ArrayAndTraversableNotIterable' => [
'code' => '<?php declare(strict_types=1);
2021-10-18 21:51:36 +02:00
2021-10-18 22:00:51 +02:00
/** @param mixed $identifier */
function isNullIdentifier($identifier): bool
2021-10-18 21:51:36 +02:00
{
if ($identifier instanceof \Traversable || is_array($identifier)) {
expectsTraversableOrArray($identifier);
}
return false;
}
/** @param Traversable|array<array-key, mixed> $_a */
function expectsTraversableOrArray($_a): void
{
}
',
],
'emptyStringNumericStringDontCombine' => [
'code' => '<?php
/**
* @param numeric-string $arg
* @return void
*/
function takesNumeric($arg) {}
$b = rand(0, 10);
$a = $b < 5 ? "" : (string) $b;
if ($a !== "") {
takesNumeric($a);
}
/** @var ""|numeric-string $c */
if (is_numeric($c)) {
takesNumeric($c);
}',
],
'emptyStringNumericStringDontCombineNegation' => [
'code' => '<?php
/**
* @param ""|"hello" $arg
* @return void
*/
function takesLiteralString($arg) {}
/** @var ""|numeric-string $c */
if (!is_numeric($c)) {
takesLiteralString($c);
}',
],
'tooLongLiteralShouldBeNonFalsyString' => [
'code' => '<?php
$x = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";',
'assertions' => [
'$x===' => 'non-falsy-string',
2024-01-13 17:12:41 +01:00
],
],
'loopNonFalsyWithZeroShouldBeNonEmpty' => [
'code' => '<?php
/**
* @psalm-suppress InvalidReturnType
* @return string[]
*/
function getStringArray() {}
$x = array();
foreach (getStringArray() as $id) {
$x[] = "0";
$x[] = "some_" . $id;
}',
'assertions' => [
'$x===' => 'list<non-empty-string>',
],
],
'loopNonLowercaseLiteralWithNonEmptyLowercaseShouldBeNonEmptyAndNotLowercase' => [
'code' => '<?php
/**
* @psalm-suppress InvalidReturnType
* @return int[]
*/
function getIntArray() {}
$x = array();
foreach (getIntArray() as $id) {
$x[] = "TEXT";
$x[] = "some_" . $id;
}',
'assertions' => [
'$x===' => 'list<non-empty-string>',
],
],
];
}
/**
* @return array<string,array{string,non-empty-list<string>}>
*/
public function providerTestValidTypeCombination(): array
{
return [
2022-12-19 19:24:03 +01:00
'complexArrayFallback1' => [
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>|null, ...<string, mixed>}',
[
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: null}&array<string, mixed>',
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>}&array<string, mixed>',
],
],
'complexArrayFallback2' => [
2023-04-21 15:58:05 +02:00
'list{0?: 0|a, 1?: 0|a, ...<a>}',
2022-12-19 19:24:03 +01:00
[
'list<a>',
'list{0, 0}',
],
],
'intOrString' => [
'int|string',
[
'int',
2017-05-27 02:05:57 +02:00
'string',
],
],
'mixedOrNull' => [
'mixed|null',
[
'mixed',
'null',
],
],
'mixedOrNever' => [
2018-12-20 02:01:27 +01:00
'mixed',
[
'never',
2018-12-20 02:01:27 +01:00
'mixed',
],
],
'mixedOrObject' => [
'mixed|object',
[
'mixed',
'object',
],
],
'mixedOrEmptyArray' => [
2021-10-13 19:37:47 +02:00
'array<never, never>|mixed',
[
'mixed',
2021-10-13 19:37:47 +02:00
'array<never, never>',
],
],
2017-12-09 21:51:38 +01:00
'falseTrueToBool' => [
'bool',
[
'false',
'true',
],
],
'trueFalseToBool' => [
'bool',
[
'true',
'false',
],
],
'trueBoolToBool' => [
'bool',
[
'true',
'bool',
],
],
'boolTrueToBool' => [
'bool',
[
'bool',
'true',
],
],
'intOrTrueOrFalseToBool' => [
'bool|int',
2017-12-09 21:51:38 +01:00
[
'int',
'false',
'true',
],
],
'intOrBoolOrTrueToBool' => [
'bool|int',
2017-12-09 21:51:38 +01:00
[
'int',
'bool',
'true',
],
],
'intOrTrueOrBoolToBool' => [
'bool|int',
2017-12-09 21:51:38 +01:00
[
'int',
'true',
'bool',
],
],
'arrayOfIntOrString' => [
'array<array-key, int|string>',
[
'array<int>',
2017-05-27 02:05:57 +02:00
'array<string>',
],
],
'arrayOfIntOrAlsoString' => [
'array<array-key, int>|string',
[
'array<int>',
2017-05-27 02:05:57 +02:00
'string',
],
],
'emptyArrays' => [
2021-10-13 19:37:47 +02:00
'array<never, never>',
[
2021-10-13 19:37:47 +02:00
'array<never, never>',
'array<never, never>',
2017-05-27 02:05:57 +02:00
],
],
'arrayStringOrEmptyArray' => [
'array<array-key, string>',
[
'array<never>',
2017-05-27 02:05:57 +02:00
'array<string>',
],
],
'arrayMixedOrString' => [
'array<array-key, mixed|string>',
[
'array<mixed>',
2017-05-27 02:05:57 +02:00
'array<string>',
],
],
'arrayMixedOrStringKeys' => [
2020-02-22 17:28:24 +01:00
'array<array-key, string>',
[
'array<int|string,string>',
2017-05-27 02:05:57 +02:00
'array<mixed,string>',
],
],
'arrayMixedOrEmpty' => [
'array<array-key, mixed>',
[
'array<never>',
2017-05-27 02:05:57 +02:00
'array<mixed>',
],
],
'arrayBigCombination' => [
'array<array-key, float|int|string>',
[
'array<int|float>',
2017-05-27 02:05:57 +02:00
'array<string>',
],
],
'arrayTraversableToIterable' => [
'iterable<array-key|mixed, mixed>',
[
'array',
'Traversable',
],
],
'arrayIterableToIterable' => [
'iterable<mixed, mixed>',
[
'array',
'iterable',
],
],
'iterableArrayToIterable' => [
'iterable<mixed, mixed>',
[
'iterable',
'array',
],
],
'traversableIterableToIterable' => [
'iterable<mixed, mixed>',
[
'Traversable',
'iterable',
],
],
'iterableTraversableToIterable' => [
'iterable<mixed, mixed>',
[
'iterable',
'Traversable',
],
],
'arrayTraversableToIterableWithParams' => [
'iterable<int, bool|string>',
[
'array<int, string>',
'Traversable<int, bool>',
],
],
'arrayIterableToIterableWithParams' => [
'iterable<int, bool|string>',
[
'array<int, string>',
'iterable<int, bool>',
],
],
'iterableArrayToIterableWithParams' => [
'iterable<int, bool|string>',
[
'iterable<int, string>',
'array<int, bool>',
],
],
'traversableIterableToIterableWithParams' => [
'iterable<int, bool|string>',
[
'Traversable<int, string>',
'iterable<int, bool>',
],
],
'iterableTraversableToIterableWithParams' => [
'iterable<int, bool|string>',
[
'iterable<int, string>',
'Traversable<int, bool>',
],
],
'arrayObjectAndParamsWithEmptyArray' => [
2021-10-13 19:37:47 +02:00
'ArrayObject<int, string>|array<never, never>',
[
'ArrayObject<int, string>',
2021-10-13 19:37:47 +02:00
'array<never, never>',
],
],
'emptyArrayWithArrayObjectAndParams' => [
2021-10-13 19:37:47 +02:00
'ArrayObject<int, string>|array<never, never>',
[
2021-10-13 19:37:47 +02:00
'array<never, never>',
'ArrayObject<int, string>',
2017-05-27 02:05:57 +02:00
],
],
2023-06-12 15:24:30 +02:00
'emptyArrayAndFalse' => [
'array<never, never>|false',
[
'array<never, never>',
2023-06-12 15:29:22 +02:00
'false',
],
2023-06-12 15:24:30 +02:00
],
'emptyArrayAndTrue' => [
'array<never, never>|true',
[
'array<never, never>',
2023-06-12 15:29:22 +02:00
'true',
],
2023-06-12 15:24:30 +02:00
],
'emptyArrayWithTrueAndFalse' => [
'array<never, never>|bool',
[
'array<never, never>',
'true',
2023-06-12 15:29:22 +02:00
'false',
],
2023-06-12 15:24:30 +02:00
],
'falseDestruction' => [
'bool',
[
'false',
2017-05-27 02:05:57 +02:00
'bool',
],
],
'onlyFalse' => [
'false',
[
2017-05-27 02:05:57 +02:00
'false',
],
],
'onlyTrue' => [
'true',
[
'true',
],
],
'falseFalseDestruction' => [
'false',
[
'false',
2017-05-27 02:05:57 +02:00
'false',
],
],
'aAndAOfB' => [
'A|A<B>',
[
'A',
2017-05-27 02:05:57 +02:00
'A<B>',
],
],
'combineObjectType1' => [
'array{a?: int, b?: string}',
[
'array{a: int}',
'array{b: string}',
2017-05-27 02:05:57 +02:00
],
],
'combineObjectType2' => [
'array{a: int|string, b?: string}',
[
'array{a: int}',
'array{a: string,b: string}',
2017-05-27 02:05:57 +02:00
],
],
'combineObjectTypeWithIntKeyedArray' => [
"array<'a'|int, int|string>",
[
'array{a: int}',
'array<int, string>',
],
],
'combineNestedObjectTypeWithTKeyedArrayIntKeyedArray' => [
"array{a: array<'a'|int, int|string>}",
[
'array{a: array{a: int}}',
'array{a: array<int, string>}',
],
],
'combineIntKeyedObjectTypeWithNestedIntKeyedArray' => [
"array<int, array<'a'|int, int|string>>",
[
'array<int, array{a:int}>',
'array<int, array<int, string>>',
],
],
'combineNestedObjectTypeWithNestedIntKeyedArray' => [
"array<'a'|int, array<'a'|int, int|string>>",
[
'array{a: array{a: int}}',
'array<int, array<int, string>>',
],
],
'combinePossiblyUndefinedKeys' => [
'array{a: bool, b?: mixed, d?: mixed}',
[
'array{a: false, b: mixed}',
'array{a: true, d: mixed}',
'array{a: true, d: mixed}',
],
],
'combinePossiblyUndefinedKeysAndString' => [
'array{a: string, b?: int}|string',
[
'array{a: string, b?: int}',
'string',
],
],
'combineMixedArrayWithTKeyedArray' => [
2020-04-11 23:50:24 +02:00
'array<array-key, mixed>',
[
'array{a: int}',
'array',
],
],
'traversableAorB' => [
'Traversable<mixed, A|B>',
[
'Traversable<A>',
'Traversable<B>',
],
],
'iterableAorB' => [
'iterable<mixed, A|B>',
[
'iterable<A>',
'iterable<B>',
],
],
'FooAorB' => [
'Foo<A>|Foo<B>',
[
'Foo<A>',
'Foo<B>',
],
],
'traversableOfMixed' => [
'Traversable<mixed, mixed>',
[
'Traversable',
'Traversable<mixed, mixed>',
],
],
'traversableAndIterator' => [
'Traversable&Iterator',
[
'Traversable&Iterator',
'Traversable&Iterator',
],
],
'traversableOfMixedAndIterator' => [
'Traversable<mixed, mixed>&Iterator',
[
'Traversable<mixed, mixed>&Iterator',
'Traversable<mixed, mixed>&Iterator',
],
],
'objectLikePlusArrayEqualsArray' => [
"array<'a'|'b'|'c', 1|2|3>",
[
'array<"a"|"b"|"c", 1|2|3>',
'array{a: 1|2, b: 2|3, c: 1|3}',
],
],
'combineClosures' => [
'Closure(A):void|Closure(B):void',
[
'Closure(A):void',
'Closure(B):void',
],
],
'combineClassStringWithString' => [
'string',
[
'class-string',
'string',
],
],
'combineClassStringWithFalse' => [
'class-string|false',
[
'class-string',
'false',
],
],
'combineRefinedClassStringWithString' => [
'string',
[
'class-string<Exception>',
'string',
],
],
'combineRefinedClassStrings' => [
'class-string<Exception>|class-string<Iterator>',
[
'class-string<Exception>',
'class-string<Iterator>',
],
],
'combineClassStringsWithLiteral' => [
'class-string',
[
'class-string',
'Exception::class',
],
],
'combineClassStringWithNumericString' => [
'class-string|numeric-string',
[
'class-string',
'numeric-string',
],
],
'combineRefinedClassStringWithNumericString' => [
'class-string<Exception>|numeric-string',
[
'class-string<Exception>',
'numeric-string',
],
],
'combineClassStringWithTraitString' => [
'class-string|trait-string',
[
'class-string',
'trait-string',
],
],
'combineRefinedClassStringWithTraitString' => [
'class-string<Exception>|trait-string',
[
'class-string<Exception>',
'trait-string',
],
],
2020-01-02 22:59:12 +01:00
'combineCallableAndCallableString' => [
'callable',
[
'callable',
'callable-string',
],
],
'combineCallableStringAndCallable' => [
'callable',
[
'callable-string',
2022-12-18 17:15:15 +01:00
'callable',
2020-01-02 22:59:12 +01:00
],
],
'combineCallableAndCallableObject' => [
'callable',
[
'callable',
'callable-object',
],
],
'combineCallableObjectAndCallable' => [
'callable',
[
'callable-object',
2022-12-18 17:15:15 +01:00
'callable',
2020-01-02 22:59:12 +01:00
],
],
'combineCallableAndCallableArray' => [
'callable',
[
'callable',
'callable-array',
],
],
'combineCallableArrayAndCallable' => [
'callable',
[
'callable-array',
2022-12-18 17:15:15 +01:00
'callable',
2020-01-02 22:59:12 +01:00
],
],
'combineCallableArrayAndArray' => [
2020-04-11 23:50:24 +02:00
'array<array-key, mixed>',
[
'callable-array{class-string, string}',
'array',
],
],
2020-04-11 23:50:24 +02:00
'combineGenericArrayAndMixedArray' => [
2020-04-09 15:27:14 +02:00
'array<array-key, int|mixed>',
2020-04-11 23:50:24 +02:00
[
'array<string, int>',
'array<array-key, mixed>',
],
],
'combineTKeyedArrayAndArray' => [
2020-04-11 23:50:24 +02:00
'array<array-key, mixed>',
2020-04-09 15:27:14 +02:00
[
'array{hello: int}',
2020-04-09 15:27:14 +02:00
'array<array-key, mixed>',
],
],
'combineTKeyedArrayAndNestedArray' => [
2020-04-11 23:50:24 +02:00
'array<array-key, mixed>',
2020-04-09 15:27:14 +02:00
[
'array{hello: array{goodbye: int}}',
2020-04-09 15:27:14 +02:00
'array<array-key, mixed>',
],
],
'combineNumericStringWithLiteralString' => [
'numeric-string',
[
'numeric-string',
'"1"',
],
],
'combineLiteralStringWithNumericString' => [
'numeric-string',
[
'"1"',
'numeric-string',
],
],
'combineNonEmptyListWithTKeyedArrayList' => [
2023-04-21 15:58:05 +02:00
'list{null|string, ...<string>}',
2020-07-22 05:16:56 +02:00
[
'non-empty-list<string>',
2022-12-18 17:15:15 +01:00
'array{null}',
2020-07-22 05:16:56 +02:00
],
],
2020-07-27 01:09:26 +02:00
'combineZeroAndPositiveInt' => [
'int<0, max>',
2020-07-27 01:09:26 +02:00
[
'0',
'positive-int',
],
],
'combinePositiveIntAndZero' => [
'int<0, max>',
2020-07-27 01:09:26 +02:00
[
'positive-int',
'0',
],
],
'combinePositiveIntAndMinusOne' => [
'int<-1, max>',
2020-07-27 01:09:26 +02:00
[
'positive-int',
'-1',
],
],
'combinePositiveIntZeroAndMinusOne' => [
'int<-1, max>',
[
'0',
'positive-int',
'-1',
],
],
2020-07-27 01:09:26 +02:00
'combineMinusOneAndPositiveInt' => [
'int<-1, max>',
2020-07-27 01:09:26 +02:00
[
'-1',
'positive-int',
],
],
'combineZeroMinusOneAndPositiveInt' => [
'int<-1, max>',
2020-07-27 01:09:26 +02:00
[
'0',
'-1',
'positive-int',
],
],
'combineZeroOneAndPositiveInt' => [
'int<0, max>',
2020-07-27 01:09:26 +02:00
[
'0',
'1',
'positive-int',
],
],
'combinePositiveIntOneAndZero' => [
'int<0, max>',
2020-07-27 01:09:26 +02:00
[
'positive-int',
'1',
'0',
],
],
'combinePositiveInts' => [
'int<1, max>',
2020-07-27 01:09:26 +02:00
[
'positive-int',
'positive-int',
],
],
'combineNonEmptyArrayAndKeyedArray' => [
'array<int, int>',
[
'non-empty-array<int, int>',
'array{0?:int}',
2022-12-18 17:15:15 +01:00
],
],
'combineNonEmptyStringAndLiteral' => [
'non-empty-string',
[
'non-empty-string',
'"foo"',
2022-12-18 17:15:15 +01:00
],
],
'combineLiteralAndNonEmptyString' => [
'non-empty-string',
[
'"foo"',
2022-12-18 17:15:15 +01:00
'non-empty-string',
],
],
'combineTruthyStringAndNonEmptyString' => [
'non-empty-string',
[
'truthy-string',
2022-12-18 17:15:15 +01:00
'non-empty-string',
],
],
'combineNonFalsyNonEmptyString' => [
'non-empty-string',
[
'non-falsy-string',
2022-12-18 17:15:15 +01:00
'non-empty-string',
],
],
'combineNonEmptyNonFalsyString' => [
'non-empty-string',
[
'non-empty-string',
2022-12-18 17:15:15 +01:00
'non-falsy-string',
],
],
'combineNonEmptyStringAndNumericString' => [
'non-empty-string',
[
'non-empty-string',
2022-12-18 17:15:15 +01:00
'numeric-string',
],
],
'combineNumericStringAndNonEmptyString' => [
'non-empty-string',
[
'numeric-string',
2022-12-18 17:15:15 +01:00
'non-empty-string',
],
],
'combineNonEmptyLowercaseAndNonFalsyString' => [
'non-empty-string',
[
'non-falsy-string',
'non-empty-lowercase-string',
2022-12-18 17:15:15 +01:00
],
],
'combineNonEmptyAndEmptyScalar' => [
'scalar',
[
'non-empty-scalar',
'empty-scalar',
2022-12-18 17:15:15 +01:00
],
],
'combineLiteralStringAndNonspecificLiteral' => [
'literal-string',
[
'literal-string',
'"foo"',
2022-12-18 17:15:15 +01:00
],
],
'combineNonspecificLiteralAndLiteralString' => [
'literal-string',
[
'"foo"',
'literal-string',
2022-12-18 17:15:15 +01:00
],
],
'combineLiteralIntAndNonspecificLiteral' => [
'literal-int',
[
'literal-int',
'5',
2022-12-18 17:15:15 +01:00
],
],
'combineNonspecificLiteralAndLiteralInt' => [
'literal-int',
[
'5',
'literal-int',
2022-12-18 17:15:15 +01:00
],
],
'combineNonspecificLiteralAndPositiveInt' => [
'int',
[
'positive-int',
'literal-int',
2022-12-18 17:15:15 +01:00
],
],
'combinePositiveAndLiteralInt' => [
'int',
[
'literal-int',
'positive-int',
2022-12-18 17:15:15 +01:00
],
],
'combineNonEmptyStringAndNonEmptyNonSpecificLiteralString' => [
'non-empty-string',
[
'non-empty-literal-string',
'non-empty-string',
],
],
'combineNonEmptyNonSpecificLiteralStringAndNonEmptyString' => [
'non-empty-string',
[
'non-empty-string',
'non-empty-literal-string',
],
],
'nonFalsyStringAndFalsyLiteral' => [
'non-empty-string',
[
'non-falsy-string',
'"0"',
],
],
'unionOfClassStringAndClassStringWithIntersection' => [
'class-string<IFoo>',
[
'class-string<IFoo>',
'class-string<IFoo & IBar>',
],
],
];
}
private static function getAtomic(string $string): Atomic
2016-06-28 20:28:45 +02:00
{
return Type::parseString($string)->getSingleAtomic();
2016-06-28 20:28:45 +02:00
}
2016-06-16 02:16:40 +02:00
}