8000 [TypeInfo] Add type alias support · symfony/symfony@0689038 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0689038

Browse files
committed
[TypeInfo] Add type alias support
1 parent ab6c611 commit 0689038

18 files changed

+303
-18
lines changed

src/Symfony/Component/TypeInfo/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Add `TypeFactoryTrait::fromValue()` method
99
* Deprecate constructing a `CollectionType` instance as a list that is not an array
1010
* Deprecate the third `$asList` argument of `TypeFactoryTrait::iterable()`, use `TypeFactoryTrait::list()` instead
11+
* Add type alias support in `TypeContext` and `StringTypeResolver`
1112

1213
7.2
1314
---

src/Symfony/Component/TypeInfo/Tests/Fixtures/AbstractDummy.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
abstract class AbstractDummy

src/Symfony/Component/TypeInfo/Tests/Fixtures/Dummy.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
final class Dummy extends AbstractDummy

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyBackedEnum.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
enum DummyBackedEnum: string

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyCollection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
final class DummyCollection implements \IteratorAggregate

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyEnum.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
enum DummyEnum

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyExtendingStdClass.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
final class DummyExtendingStdClass extends \stdClass

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithPhpDoc.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

14+
/**
15+
* @phpstan-type CustomInt = int
16+
* @psalm-type PsalmCustomInt = int
17+
*/
518
final class DummyWithPhpDoc
619
{
720
/**
821
* @var array<Dummy>
922
*/
1023
public mixed $arrayOfDummies = [];
1124

25+
/**
26+
* @var CustomInt
27+
*/
28+
public mixed $aliasedInt;
29+
1230
/**
1331
* @param bool $promoted
1432
*/

src/Symfony/Component/TypeInfo/Tests/Fixtures/DummyWithTemplates.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
413

514
/**
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\TypeInfo\Tests\Fixtures;
13+
14+
/**
15+
* @phpstan-type CustomString = string
16+
* @phpstan-import-type CustomInt from DummyWithPhpDoc
17+
* @phpstan-import-type CustomInt from DummyWithPhpDoc as AliasedCustomInt
18+
*
19+
* @psalm-type PsalmCustomString = string
20+
* @psalm-import-type PsalmCustomInt from DummyWithPhpDoc
21+
* @psalm-import-type PsalmCustomInt from DummyWithPhpDoc as PsalmAliasedCustomInt
22+
*/
23+
final class DummyWithTypeAliases
24+
{
25+
/**
26+
* @var CustomString
27+
*/
28+
public mixed $localAlias;
29+
30+
/**
31+
* @var CustomInt
32+
*/
33+
public mixed $externalAlias;
34+
35+
/**
36+
* @var AliasedCustomInt
37+
*/
38+
public mixed $aliasedExternalAlias;
39+
40+
/**
41+
* @var PsalmCustomString
42+
*/
43+
public mixed $psalmLocalAlias;
44+
45+
/**
46+
* @var PsalmCustomInt
47+
*/
48+
public mixed $psalmExternalAlias;
49+
50+
/**
51+
* @var PsalmAliasedCustomInt
52+
*/
53+
public mixed $psalmOtherAliasedExternalAlias;
54+
}
55+
56+
/**
57+
* @phpstan-import-type Invalid from DummyWithTypeAliases
58+
*/
59+
final class DummyWithInvalidTypeAliasImport
60+
{
61+
62+
}

0 commit comments

Comments
 (0)
0