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;
|
2019-03-23 19:27:54 +01:00
|
|
|
use Psalm\Type;
|
2016-06-16 02:16:40 +02:00
|
|
|
|
2021-06-08 04:55:21 +02:00
|
|
|
use function array_values;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class TypeCombinationTest extends TestCase
|
2016-06-16 02:16:40 +02:00
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
2017-01-02 21:31:18 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @dataProvider providerTestValidTypeCombination
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-04-25 05:45:02 +02:00
|
|
|
* @param string $expected
|
2020-01-30 05:55:27 +01:00
|
|
|
* @param non-empty-list<string> $types
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function testValidTypeCombination($expected, $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);
|
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-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
|
2017-05-27 02:05:57 +02:00
|
|
|
$this->assertSame(
|
2017-04-25 05:45:02 +02:00
|
|
|
$expected,
|
2020-11-22 00:11:29 +01:00
|
|
|
TypeCombiner::combine($converted_types)->getId()
|
2017-04-25 05:45:02 +02:00
|
|
|
);
|
2016-06-16 02:16:40 +02:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2019-03-01 21:55:20 +01:00
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
2017-04-25 05:45:02 +02:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2017-04-25 05:45:02 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'multipleValuedArray' => [
|
|
|
|
'<?php
|
|
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
$var = [];
|
|
|
|
$var[] = new A();
|
2017-05-27 02:05:57 +02:00
|
|
|
$var[] = new B();',
|
|
|
|
],
|
2019-01-29 16:34:31 +01:00
|
|
|
'preventLiteralAndClassString' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @param "array"|class-string $type_name
|
|
|
|
*/
|
|
|
|
function foo(string $type_name) : bool {
|
|
|
|
return $type_name === "array";
|
|
|
|
}',
|
|
|
|
],
|
2021-05-13 00:46:37 +02:00
|
|
|
'NeverTwice' => [
|
|
|
|
'<?php
|
|
|
|
/** @return no-return */
|
|
|
|
function other() {
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
|
|
|
|
rand(0,1) ? die() : other();',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-30 05:55:27 +01:00
|
|
|
* @return array<string,array{string,non-empty-list<string>}>
|
2017-04-25 05:45:02 +02:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerTestValidTypeCombination(): array
|
2017-04-25 05:45:02 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'intOrString' => [
|
|
|
|
'int|string',
|
|
|
|
[
|
|
|
|
'int',
|
2017-05-27 02:05:57 +02:00
|
|
|
'string',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2018-12-08 19:18:55 +01:00
|
|
|
'mixedOrNull' => [
|
|
|
|
'mixed|null',
|
|
|
|
[
|
|
|
|
'mixed',
|
|
|
|
'null',
|
|
|
|
],
|
|
|
|
],
|
2018-12-20 02:01:27 +01:00
|
|
|
'mixedOrEmpty' => [
|
|
|
|
'mixed',
|
|
|
|
[
|
|
|
|
'empty',
|
|
|
|
'mixed',
|
|
|
|
],
|
|
|
|
],
|
2018-12-08 19:18:55 +01:00
|
|
|
'mixedOrObject' => [
|
|
|
|
'mixed|object',
|
|
|
|
[
|
|
|
|
'mixed',
|
|
|
|
'object',
|
|
|
|
],
|
|
|
|
],
|
2018-12-14 18:30:13 +01:00
|
|
|
'mixedOrEmptyArray' => [
|
2018-12-14 21:10:10 +01:00
|
|
|
'array<empty, empty>|mixed',
|
2018-12-14 18:30:13 +01:00
|
|
|
[
|
|
|
|
'mixed',
|
|
|
|
'array<empty, empty>',
|
|
|
|
],
|
|
|
|
],
|
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' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'bool|int',
|
2017-12-09 21:51:38 +01:00
|
|
|
[
|
|
|
|
'int',
|
|
|
|
'false',
|
|
|
|
'true',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'intOrBoolOrTrueToBool' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'bool|int',
|
2017-12-09 21:51:38 +01:00
|
|
|
[
|
|
|
|
'int',
|
|
|
|
'bool',
|
|
|
|
'true',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'intOrTrueOrBoolToBool' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'bool|int',
|
2017-12-09 21:51:38 +01:00
|
|
|
[
|
|
|
|
'int',
|
|
|
|
'true',
|
|
|
|
'bool',
|
|
|
|
],
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'arrayOfIntOrString' => [
|
2019-01-05 06:15:53 +01:00
|
|
|
'array<array-key, int|string>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<int>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<string>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayOfIntOrAlsoString' => [
|
2019-01-05 06:15:53 +01:00
|
|
|
'array<array-key, int>|string',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<int>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'string',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'emptyArrays' => [
|
|
|
|
'array<empty, empty>',
|
|
|
|
[
|
|
|
|
'array<empty,empty>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<empty,empty>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayStringOrEmptyArray' => [
|
2019-01-05 06:15:53 +01:00
|
|
|
'array<array-key, string>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<empty>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<string>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayMixedOrString' => [
|
2019-01-05 06:15:53 +01:00
|
|
|
'array<array-key, mixed|string>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<mixed>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<string>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayMixedOrStringKeys' => [
|
2020-02-22 17:28:24 +01:00
|
|
|
'array<array-key, string>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<int|string,string>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<mixed,string>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayMixedOrEmpty' => [
|
2019-01-05 06:15:53 +01:00
|
|
|
'array<array-key, mixed>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<empty>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<mixed>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'arrayBigCombination' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'array<array-key, float|int|string>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'array<int|float>',
|
2017-05-27 02:05:57 +02:00
|
|
|
'array<string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'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' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'iterable<int, bool|string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
[
|
|
|
|
'array<int, string>',
|
|
|
|
'Traversable<int, bool>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'arrayIterableToIterableWithParams' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'iterable<int, bool|string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
[
|
|
|
|
'array<int, string>',
|
|
|
|
'iterable<int, bool>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'iterableArrayToIterableWithParams' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'iterable<int, bool|string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
[
|
|
|
|
'iterable<int, string>',
|
|
|
|
'array<int, bool>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'traversableIterableToIterableWithParams' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'iterable<int, bool|string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
[
|
|
|
|
'Traversable<int, string>',
|
|
|
|
'iterable<int, bool>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'iterableTraversableToIterableWithParams' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'iterable<int, bool|string>',
|
2019-01-25 20:43:08 +01:00
|
|
|
[
|
|
|
|
'iterable<int, string>',
|
|
|
|
'Traversable<int, bool>',
|
2019-01-26 22:58:49 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'arrayObjectAndParamsWithEmptyArray' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'ArrayObject<int, string>|array<empty, empty>',
|
2019-01-26 22:58:49 +01:00
|
|
|
[
|
|
|
|
'ArrayObject<int, string>',
|
|
|
|
'array<empty, empty>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'emptyArrayWithArrayObjectAndParams' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'ArrayObject<int, string>|array<empty, empty>',
|
2019-01-26 22:58:49 +01:00
|
|
|
[
|
|
|
|
'array<empty, empty>',
|
|
|
|
'ArrayObject<int, string>',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'falseDestruction' => [
|
|
|
|
'bool',
|
|
|
|
[
|
|
|
|
'false',
|
2017-05-27 02:05:57 +02:00
|
|
|
'bool',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'onlyFalse' => [
|
2017-12-15 22:36:42 +01:00
|
|
|
'false',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
2017-05-27 02:05:57 +02:00
|
|
|
'false',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2017-12-15 22:36:42 +01:00
|
|
|
'onlyTrue' => [
|
|
|
|
'true',
|
|
|
|
[
|
|
|
|
'true',
|
|
|
|
],
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'falseFalseDestruction' => [
|
2017-12-19 06:06:05 +01:00
|
|
|
'false',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'false',
|
2017-05-27 02:05:57 +02:00
|
|
|
'false',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'aAndAOfB' => [
|
2019-10-17 07:14:33 +02:00
|
|
|
'A|A<B>',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
|
|
|
'A',
|
2017-05-27 02:05:57 +02:00
|
|
|
'A<B>',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'combineObjectType1' => [
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a?: int, b?: string}',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: int}',
|
|
|
|
'array{b: string}',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'combineObjectType2' => [
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: int|string, b?: string}',
|
2017-04-25 05:45:02 +02:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: int}',
|
|
|
|
'array{a: string,b: string}',
|
2017-05-27 02:05:57 +02:00
|
|
|
],
|
|
|
|
],
|
2017-11-17 22:33:36 +01:00
|
|
|
'combineObjectTypeWithIntKeyedArray' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'array<"a"|int, int|string>',
|
2017-11-17 22:33:36 +01:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: int}',
|
2017-11-17 22:33:36 +01:00
|
|
|
'array<int, string>',
|
|
|
|
],
|
|
|
|
],
|
2020-08-30 17:44:14 +02:00
|
|
|
'combineNestedObjectTypeWithTKeyedArrayIntKeyedArray' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'array{a: array<"a"|int, int|string>}',
|
2017-11-17 22:33:36 +01:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: array{a: int}}',
|
|
|
|
'array{a: array<int, string>}',
|
2017-11-17 22:33:36 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineIntKeyedObjectTypeWithNestedIntKeyedArray' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'array<int, array<"a"|int, int|string>>',
|
2017-11-17 22:33:36 +01:00
|
|
|
[
|
|
|
|
'array<int, array{a:int}>',
|
|
|
|
'array<int, array<int, string>>',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineNestedObjectTypeWithNestedIntKeyedArray' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'array<"a"|int, array<"a"|int, int|string>>',
|
2017-11-17 22:33:36 +01:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: array{a: int}}',
|
2017-11-17 22:33:36 +01:00
|
|
|
'array<int, array<int, string>>',
|
|
|
|
],
|
|
|
|
],
|
2018-03-23 18:14:00 +01:00
|
|
|
'combinePossiblyUndefinedKeys' => [
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: bool, b?: mixed, d?: mixed}',
|
2018-03-23 18:14:00 +01:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: false, b: mixed}',
|
|
|
|
'array{a: true, d: mixed}',
|
|
|
|
'array{a: true, d: mixed}',
|
2018-03-23 18:14:00 +01:00
|
|
|
],
|
|
|
|
],
|
2018-04-02 20:36:33 +02:00
|
|
|
'combinePossiblyUndefinedKeysAndString' => [
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: string, b?: int}|string',
|
2018-04-02 20:36:33 +02:00
|
|
|
[
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: string, b?: int}',
|
2018-04-02 20:36:33 +02:00
|
|
|
'string',
|
|
|
|
],
|
|
|
|
],
|
2020-08-30 17:44:14 +02:00
|
|
|
'combineMixedArrayWithTKeyedArray' => [
|
2020-04-11 23:50:24 +02:00
|
|
|
'array<array-key, mixed>',
|
2019-06-21 02:13:36 +02:00
|
|
|
[
|
|
|
|
'array{a: int}',
|
|
|
|
'array',
|
|
|
|
],
|
|
|
|
],
|
2019-05-06 22:38:08 +02:00
|
|
|
'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>',
|
|
|
|
],
|
|
|
|
],
|
2019-05-08 19:23:47 +02:00
|
|
|
'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',
|
|
|
|
],
|
|
|
|
],
|
2019-05-13 17:00:17 +02:00
|
|
|
'objectLikePlusArrayEqualsArray' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'array<"a"|"b"|"c", 1|2|3>',
|
2019-05-13 17:00:17 +02:00
|
|
|
[
|
|
|
|
'array<"a"|"b"|"c", 1|2|3>',
|
2019-06-16 15:42:34 +02:00
|
|
|
'array{a: 1|2, b: 2|3, c: 1|3}',
|
2019-05-13 17:00:17 +02:00
|
|
|
],
|
|
|
|
],
|
2019-09-22 06:58:30 +02:00
|
|
|
'combineClosures' => [
|
|
|
|
'Closure(A):void|Closure(B):void',
|
|
|
|
[
|
|
|
|
'Closure(A):void',
|
|
|
|
'Closure(B):void',
|
|
|
|
],
|
|
|
|
],
|
2019-11-30 18:32:31 +01:00
|
|
|
'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>',
|
|
|
|
],
|
|
|
|
],
|
2019-12-02 05:03:09 +01:00
|
|
|
'combineClassStringsWithLiteral' => [
|
|
|
|
'class-string',
|
|
|
|
[
|
|
|
|
'class-string',
|
|
|
|
'Exception::class',
|
|
|
|
],
|
|
|
|
],
|
2021-03-29 05:12:23 +02:00
|
|
|
'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',
|
|
|
|
'callable'
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineCallableAndCallableObject' => [
|
|
|
|
'callable',
|
|
|
|
[
|
|
|
|
'callable',
|
|
|
|
'callable-object',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineCallableObjectAndCallable' => [
|
|
|
|
'callable',
|
|
|
|
[
|
|
|
|
'callable-object',
|
|
|
|
'callable'
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineCallableAndCallableArray' => [
|
|
|
|
'callable',
|
|
|
|
[
|
|
|
|
'callable',
|
|
|
|
'callable-array',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineCallableArrayAndCallable' => [
|
|
|
|
'callable',
|
|
|
|
[
|
|
|
|
'callable-array',
|
|
|
|
'callable'
|
|
|
|
],
|
|
|
|
],
|
2020-03-09 15:56:37 +01:00
|
|
|
'combineCallableArrayAndArray' => [
|
2020-04-11 23:50:24 +02:00
|
|
|
'array<array-key, mixed>',
|
2020-03-09 15:56:37 +01:00
|
|
|
[
|
|
|
|
'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>',
|
|
|
|
],
|
|
|
|
],
|
2020-08-30 17:44:14 +02:00
|
|
|
'combineTKeyedArrayAndArray' => [
|
2020-04-11 23:50:24 +02:00
|
|
|
'array<array-key, mixed>',
|
2020-04-09 15:27:14 +02:00
|
|
|
[
|
|
|
|
'array{hello: int}',
|
|
|
|
'array<array-key, mixed>',
|
|
|
|
],
|
|
|
|
],
|
2020-08-30 17:44:14 +02:00
|
|
|
'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}}',
|
|
|
|
'array<array-key, mixed>',
|
|
|
|
],
|
|
|
|
],
|
2020-05-18 22:56:09 +02:00
|
|
|
'combineNumericStringWithLiteralString' => [
|
|
|
|
'numeric-string',
|
|
|
|
[
|
|
|
|
'numeric-string',
|
|
|
|
'"1"',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineLiteralStringWithNumericString' => [
|
|
|
|
'numeric-string',
|
|
|
|
[
|
|
|
|
'"1"',
|
|
|
|
'numeric-string',
|
|
|
|
],
|
|
|
|
],
|
2020-08-30 17:44:14 +02:00
|
|
|
'combineNonEmptyListWithTKeyedArrayList' => [
|
2020-07-22 05:16:56 +02:00
|
|
|
'array{0: null|string}<int, string>',
|
|
|
|
[
|
|
|
|
'non-empty-list<string>',
|
|
|
|
'array{null}'
|
|
|
|
],
|
|
|
|
],
|
2020-07-27 01:09:26 +02:00
|
|
|
'combineZeroAndPositiveInt' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'0|positive-int',
|
2020-07-27 01:09:26 +02:00
|
|
|
[
|
|
|
|
'0',
|
|
|
|
'positive-int',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combinePositiveIntAndZero' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'0|positive-int',
|
2020-07-27 01:09:26 +02:00
|
|
|
[
|
|
|
|
'positive-int',
|
|
|
|
'0',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combinePositiveIntAndMinusOne' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'positive-int',
|
|
|
|
'-1',
|
|
|
|
],
|
|
|
|
],
|
2020-11-22 00:26:13 +01:00
|
|
|
'combinePositiveIntZeroAndMinusOne' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'0',
|
|
|
|
'positive-int',
|
|
|
|
'-1',
|
|
|
|
],
|
|
|
|
],
|
2020-07-27 01:09:26 +02:00
|
|
|
'combineMinusOneAndPositiveInt' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'-1',
|
|
|
|
'positive-int',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineZeroMinusOneAndPositiveInt' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'0',
|
|
|
|
'-1',
|
|
|
|
'positive-int',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combineZeroOneAndPositiveInt' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'0|positive-int',
|
2020-07-27 01:09:26 +02:00
|
|
|
[
|
|
|
|
'0',
|
|
|
|
'1',
|
|
|
|
'positive-int',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combinePositiveIntOneAndZero' => [
|
2021-01-26 05:41:42 +01:00
|
|
|
'0|positive-int',
|
2020-07-27 01:09:26 +02:00
|
|
|
[
|
|
|
|
'positive-int',
|
|
|
|
'1',
|
|
|
|
'0',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'combinePositiveInts' => [
|
|
|
|
'positive-int',
|
|
|
|
[
|
|
|
|
'positive-int',
|
|
|
|
'positive-int',
|
|
|
|
],
|
|
|
|
],
|
2021-02-03 23:19:48 +01:00
|
|
|
'combineNonEmptyArrayAndKeyedArray' => [
|
2020-09-20 00:12:14 +02:00
|
|
|
'array<int, int>',
|
|
|
|
[
|
|
|
|
'non-empty-array<int, int>',
|
|
|
|
'array{0?:int}',
|
|
|
|
]
|
|
|
|
],
|
2021-02-03 23:19:48 +01:00
|
|
|
'combineNonEmptyStringAndLiteral' => [
|
2021-01-17 18:22:29 +01:00
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'non-empty-string',
|
|
|
|
'"foo"',
|
|
|
|
]
|
|
|
|
],
|
2021-02-03 23:19:48 +01:00
|
|
|
'combineLiteralAndNonEmptyString' => [
|
2021-01-17 18:22:29 +01:00
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'"foo"',
|
|
|
|
'non-empty-string'
|
|
|
|
]
|
|
|
|
],
|
2021-02-03 23:19:48 +01:00
|
|
|
'combineNonFalsyNonEmptyString' => [
|
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'non-falsy-string',
|
|
|
|
'non-empty-string'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combineNonEmptyNonFalsyString' => [
|
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'non-empty-string',
|
|
|
|
'non-falsy-string'
|
|
|
|
]
|
|
|
|
],
|
2021-02-03 23:40:41 +01:00
|
|
|
'combineNonEmptyStringAndNumericString' => [
|
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'non-empty-string',
|
|
|
|
'numeric-string'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combineNumericStringAndNonEmptyString' => [
|
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'numeric-string',
|
|
|
|
'non-empty-string'
|
|
|
|
]
|
|
|
|
],
|
2021-04-01 05:16:21 +02:00
|
|
|
'combineNonEmptyLowercaseAndNonFalsyString' => [
|
|
|
|
'non-empty-string',
|
|
|
|
[
|
|
|
|
'non-falsy-string',
|
|
|
|
'non-empty-lowercase-string',
|
|
|
|
]
|
|
|
|
],
|
2021-05-02 02:13:49 +02:00
|
|
|
'combineNonEmptyAndEmptyScalar' => [
|
|
|
|
'scalar',
|
|
|
|
[
|
|
|
|
'non-empty-scalar',
|
|
|
|
'empty-scalar',
|
|
|
|
]
|
|
|
|
],
|
2021-06-14 21:30:25 +02:00
|
|
|
'combineLiteralStringAndNonspecificLiteral' => [
|
|
|
|
'literal-string',
|
|
|
|
[
|
|
|
|
'literal-string',
|
|
|
|
'"foo"',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combineNonspecificLiteralAndLiteralString' => [
|
|
|
|
'literal-string',
|
|
|
|
[
|
|
|
|
'"foo"',
|
|
|
|
'literal-string',
|
|
|
|
]
|
|
|
|
],
|
2021-06-15 05:24:09 +02:00
|
|
|
'combineLiteralIntAndNonspecificLiteral' => [
|
|
|
|
'literal-int',
|
|
|
|
[
|
|
|
|
'literal-int',
|
|
|
|
'5',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combineNonspecificLiteralAndLiteralInt' => [
|
|
|
|
'literal-int',
|
|
|
|
[
|
|
|
|
'5',
|
|
|
|
'literal-int',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combineNonspecificLiteralAndPositiveInt' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'positive-int',
|
|
|
|
'literal-int',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'combinePositiveAndLiteralInt' => [
|
|
|
|
'int',
|
|
|
|
[
|
|
|
|
'literal-int',
|
|
|
|
'positive-int',
|
|
|
|
]
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2017-01-02 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2016-12-24 19:23:22 +01:00
|
|
|
/**
|
|
|
|
* @param string $string
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-12-24 19:23:22 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
private static function getAtomic($string): Type\Atomic
|
2016-06-28 20:28:45 +02:00
|
|
|
{
|
2020-01-04 18:20:26 +01:00
|
|
|
return array_values(Type::parseString($string)->getAtomicTypes())[0];
|
2016-06-28 20:28:45 +02:00
|
|
|
}
|
2016-06-16 02:16:40 +02:00
|
|
|
}
|