Skip to content

Commit 15e6297

Browse files
committed
Merge branch '2.x' into improve-array-to-string-conversion
2 parents a402408 + fcadea7 commit 15e6297

17 files changed

Lines changed: 237 additions & 21 deletions

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PseudoTypes/NeverReturn.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'never-return'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NeverReturn extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'never-return';
35+
}
36+
}

src/PseudoTypes/NeverReturns.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'never-returns'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NeverReturns extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'never-returns';
35+
}
36+
}

src/PseudoTypes/NoReturn.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Never_;
19+
20+
/**
21+
* Value Object representing the type 'no-return'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NoReturn extends Never_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Never_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'no-return';
35+
}
36+
}

src/PseudoTypes/NonEmptyArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __toString(): string
3939
}
4040

4141
if ($this->keyType) {
42-
return 'non-empty-array<' . $this->keyType . ',' . $this->valueType . '>';
42+
return 'non-empty-array<' . $this->keyType . ', ' . $this->valueType . '>';
4343
}
4444

4545
return 'non-empty-array<' . $this->valueType . '>';

src/TypeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
use phpDocumentor\Reflection\PseudoTypes\LiteralString;
4141
use phpDocumentor\Reflection\PseudoTypes\LowercaseString;
4242
use phpDocumentor\Reflection\PseudoTypes\NegativeInteger;
43+
use phpDocumentor\Reflection\PseudoTypes\NeverReturn;
44+
use phpDocumentor\Reflection\PseudoTypes\NeverReturns;
4345
use phpDocumentor\Reflection\PseudoTypes\NonEmptyArray;
4446
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4547
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
@@ -48,6 +50,7 @@
4850
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
4951
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
5052
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
53+
use phpDocumentor\Reflection\PseudoTypes\NoReturn;
5154
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
5255
use phpDocumentor\Reflection\PseudoTypes\NumericString;
5356
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -182,6 +185,9 @@ final class TypeResolver
182185
'parent' => Parent_::class,
183186
'iterable' => Iterable_::class,
184187
'never' => Never_::class,
188+
'never-return' => NeverReturn::class,
189+
'never-returns' => NeverReturns::class,
190+
'no-return' => NoReturn::class,
185191
'list' => List_::class,
186192
'non-empty-list' => NonEmptyList::class,
187193
'non-falsy-string' => NonFalsyString::class,

src/Types/AbstractList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __toString(): string
8484
}
8585

8686
if ($this->keyType) {
87-
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
87+
return 'array<' . $this->keyType . ', ' . $this->valueType . '>';
8888
}
8989

9090
if (

src/Types/Iterable_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __toString(): string
3030
}
3131

3232
if ($this->keyType) {
33-
return 'iterable<' . $this->keyType . ',' . $this->valueType . '>';
33+
return 'iterable<' . $this->keyType . ', ' . $this->valueType . '>';
3434
}
3535

3636
return 'iterable<' . $this->valueType . '>';

src/Types/Never_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @psalm-immutable
2525
*/
26-
final class Never_ implements Type
26+
class Never_ implements Type
2727
{
2828
/**
2929
* Returns a rendered output of the Type as it would be used in a DocBlock.

tests/unit/CollectionResolverTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public function testResolvingArrayCollectionWithKey(): void
102102
{
103103
$fixture = new TypeResolver();
104104

105-
$resolvedType = $fixture->resolve('array<string,object|array>', new Context(''));
105+
$resolvedType = $fixture->resolve('array<string, object|array>', new Context(''));
106106

107107
$this->assertInstanceOf(Array_::class, $resolvedType);
108-
$this->assertSame('array<string,object|array>', (string) $resolvedType);
108+
$this->assertSame('array<string, object|array>', (string) $resolvedType);
109109

110110
$valueType = $resolvedType->getValueType();
111111

@@ -127,7 +127,7 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace(): void
127127
$resolvedType = $fixture->resolve('array<string, object|array>', new Context(''));
128128

129129
$this->assertInstanceOf(Array_::class, $resolvedType);
130-
$this->assertSame('array<string,object|array>', (string) $resolvedType);
130+
$this->assertSame('array<string, object|array>', (string) $resolvedType);
131131

132132
$valueType = $resolvedType->getValueType();
133133

@@ -170,16 +170,16 @@ public function testResolvingCollectionOfCollection(): void
170170
public function testGoodArrayCollectionKey(): void
171171
{
172172
$fixture = new TypeResolver();
173-
$resolvedType = $fixture->resolve('array<array-key,string>', new Context(''));
173+
$resolvedType = $fixture->resolve('array<array-key, string>', new Context(''));
174174

175175
$this->assertInstanceOf(Array_::class, $resolvedType);
176-
$this->assertSame('array<array-key,string>', (string) $resolvedType);
176+
$this->assertSame('array<array-key, string>', (string) $resolvedType);
177177

178178
$fixture = new TypeResolver();
179-
$resolvedType = $fixture->resolve('array<class-string,string>', new Context(''));
179+
$resolvedType = $fixture->resolve('array<class-string, string>', new Context(''));
180180

181181
$this->assertInstanceOf(Array_::class, $resolvedType);
182-
$this->assertSame('array<class-string,string>', (string) $resolvedType);
182+
$this->assertSame('array<class-string, string>', (string) $resolvedType);
183183
}
184184

185185
public function testMissingStartCollection(): void
@@ -218,7 +218,7 @@ public function testResolvingCollectionAsArray(): void
218218
$resolvedType = $fixture->resolve('array<string,float>', new Context(''));
219219

220220
$this->assertInstanceOf(Array_::class, $resolvedType);
221-
$this->assertSame('array<string,float>', (string) $resolvedType);
221+
$this->assertSame('array<string, float>', (string) $resolvedType);
222222

223223
$valueType = $resolvedType->getValueType();
224224

0 commit comments

Comments
 (0)