Skip to content

Commit 9f4525f

Browse files
committed
CR Fix
1 parent d117644 commit 9f4525f

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

src/Types/GenericType.php renamed to src/PseudoTypes/Generic.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
* @link http://phpdoc.org
1212
*/
1313

14-
namespace phpDocumentor\Reflection\Types;
14+
namespace phpDocumentor\Reflection\PseudoTypes;
1515

1616
use phpDocumentor\Reflection\Fqsen;
1717
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Object_;
1819

1920
use function implode;
2021

@@ -23,11 +24,8 @@
2324
*
2425
* @psalm-immutable
2526
*/
26-
final class GenericType implements Type
27+
final class Generic extends Object_
2728
{
28-
/** @var Fqsen|null */
29-
private $fqsen;
30-
3129
/** @var Type[] */
3230
private $types;
3331

@@ -36,13 +34,9 @@ final class GenericType implements Type
3634
*/
3735
public function __construct(?Fqsen $fqsen, array $types)
3836
{
39-
$this->fqsen = $fqsen;
40-
$this->types = $types;
41-
}
37+
parent::__construct($fqsen);
4238

43-
public function getFqsen(): ?Fqsen
44-
{
45-
return $this->fqsen;
39+
$this->types = $types;
4640
}
4741

4842
/**

src/TypeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
2424
use phpDocumentor\Reflection\PseudoTypes\False_;
2525
use phpDocumentor\Reflection\PseudoTypes\FloatValue;
26+
use phpDocumentor\Reflection\PseudoTypes\Generic;
2627
use phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString;
2728
use phpDocumentor\Reflection\PseudoTypes\IntegerRange;
2829
use phpDocumentor\Reflection\PseudoTypes\IntegerValue;
@@ -60,7 +61,6 @@
6061
use phpDocumentor\Reflection\Types\Context;
6162
use phpDocumentor\Reflection\Types\Expression;
6263
use phpDocumentor\Reflection\Types\Float_;
63-
use phpDocumentor\Reflection\Types\GenericType;
6464
use phpDocumentor\Reflection\Types\Integer;
6565
use phpDocumentor\Reflection\Types\InterfaceString;
6666
use phpDocumentor\Reflection\Types\Intersection;
@@ -467,7 +467,7 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ
467467

468468
$types = $this->createTypesByTypeNodes($type->genericTypes, $context);
469469

470-
return new GenericType($mainType->getFqsen(), $types);
470+
return new Generic($mainType->getFqsen(), $types);
471471
}
472472
}
473473

src/Types/Object_.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
*
2929
* @psalm-immutable
3030
*/
31-
final class Object_ implements Type
31+
class Object_ implements Type
3232
{
3333
/** @var Fqsen|null */
34-
private $fqsen;
34+
protected $fqsen;
3535

3636
/**
3737
* Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'.

tests/unit/CollectionResolverTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
namespace phpDocumentor\Reflection;
1515

16+
use phpDocumentor\Reflection\PseudoTypes\Generic;
1617
use phpDocumentor\Reflection\PseudoTypes\List_;
1718
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
1819
use phpDocumentor\Reflection\Types\Array_;
1920
use phpDocumentor\Reflection\Types\Compound;
2021
use phpDocumentor\Reflection\Types\Context;
2122
use phpDocumentor\Reflection\Types\Float_;
22-
use phpDocumentor\Reflection\Types\GenericType;
2323
use phpDocumentor\Reflection\Types\Integer;
2424
use phpDocumentor\Reflection\Types\Nullable;
2525
use phpDocumentor\Reflection\Types\Object_;
@@ -36,7 +36,7 @@ class CollectionResolverTest extends TestCase
3636
/**
3737
* @uses \phpDocumentor\Reflection\Types\Context
3838
* @uses \phpDocumentor\Reflection\Types\Compound
39-
* @uses \phpDocumentor\Reflection\Types\GenericType
39+
* @uses \phpDocumentor\Reflection\Types\Generic
4040
* @uses \phpDocumentor\Reflection\Types\String_
4141
*
4242
* @covers ::resolve
@@ -49,7 +49,7 @@ public function testResolvingCollection(): void
4949

5050
$resolvedType = $fixture->resolve('ArrayObject<string>', new Context(''));
5151

52-
$this->assertInstanceOf(GenericType::class, $resolvedType);
52+
$this->assertInstanceOf(Generic::class, $resolvedType);
5353
$this->assertSame('\\ArrayObject<string>', (string) $resolvedType);
5454
$this->assertSame('\\ArrayObject', (string) $resolvedType->getFqsen());
5555
$this->assertEquals([new String_()], $resolvedType->getTypes());
@@ -58,7 +58,7 @@ public function testResolvingCollection(): void
5858
/**
5959
* @uses \phpDocumentor\Reflection\Types\Context
6060
* @uses \phpDocumentor\Reflection\Types\Compound
61-
* @uses \phpDocumentor\Reflection\Types\GenericType
61+
* @uses \phpDocumentor\Reflection\Types\Generic
6262
* @uses \phpDocumentor\Reflection\Types\String_
6363
*
6464
* @covers ::__construct
@@ -71,7 +71,7 @@ public function testResolvingCollectionWithKeyType(): void
7171

7272
$resolvedType = $fixture->resolve('ArrayObject<string[],Iterator>', new Context(''));
7373

74-
$this->assertInstanceOf(GenericType::class, $resolvedType);
74+
$this->assertInstanceOf(Generic::class, $resolvedType);
7575
$this->assertSame('\\ArrayObject<string[], \\Iterator>', (string) $resolvedType);
7676
$this->assertSame('\\ArrayObject', (string) $resolvedType->getFqsen());
7777

@@ -165,7 +165,7 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace(): void
165165
/**
166166
* @uses \phpDocumentor\Reflection\Types\Context
167167
* @uses \phpDocumentor\Reflection\Types\Compound
168-
* @uses \phpDocumentor\Reflection\Types\GenericType
168+
* @uses \phpDocumentor\Reflection\Types\Generic
169169
* @uses \phpDocumentor\Reflection\Types\String_
170170
*
171171
* @covers ::__construct
@@ -178,7 +178,7 @@ public function testResolvingCollectionOfCollection(): void
178178

179179
$resolvedType = $fixture->resolve('ArrayObject<string|integer|double,ArrayObject<DateTime>>', new Context(''));
180180

181-
$this->assertInstanceOf(GenericType::class, $resolvedType);
181+
$this->assertInstanceOf(Generic::class, $resolvedType);
182182
$this->assertSame('\\ArrayObject<string|int|float, \\ArrayObject<\\DateTime>>', (string) $resolvedType);
183183
$this->assertSame('\\ArrayObject', (string) $resolvedType->getFqsen());
184184

@@ -188,7 +188,7 @@ public function testResolvingCollectionOfCollection(): void
188188
$this->assertEquals(new Compound([new String_(), new Integer(), new Float_()]), $types[0]);
189189

190190
$this->assertArrayHasKey(0, $types);
191-
$this->assertInstanceOf(GenericType::class, $types[1]);
191+
$this->assertInstanceOf(Generic::class, $types[1]);
192192
$this->assertSame('\\ArrayObject', (string) $types[1]->getFqsen());
193193

194194
$nestedGenericTypes = $types[1]->getTypes();

tests/unit/Types/GenericTypeTest.php renamed to tests/unit/PseudoTypes/GenericTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
declare(strict_types=1);
44

5-
namespace phpDocumentor\Reflection\Types;
5+
namespace phpDocumentor\Reflection\PseudoTypes;
66

77
use phpDocumentor\Reflection\Fqsen;
8-
use phpDocumentor\Reflection\PseudoTypes\List_;
8+
use phpDocumentor\Reflection\Types\Array_;
9+
use phpDocumentor\Reflection\Types\Integer;
10+
use phpDocumentor\Reflection\Types\Object_;
11+
use phpDocumentor\Reflection\Types\String_;
912
use PHPUnit\Framework\TestCase;
1013

1114
/**
12-
* @coversDefaultClass \phpDocumentor\Reflection\Types\GenericType
15+
* @coversDefaultClass \phpDocumentor\Reflection\Types\Generic
1316
*/
14-
class GenericTypeTest extends TestCase
17+
class GenericTest extends TestCase
1518
{
1619
/**
1720
* @covers ::getFqsen
@@ -21,7 +24,7 @@ public function testCreate(): void
2124
{
2225
$fqsen = new Fqsen('\\Foo\\Bar');
2326
$types = [new Object_(new Fqsen('\\Foo\\SomeClass')), new List_(new Integer())];
24-
$type = new GenericType($fqsen, $types);
27+
$type = new Generic($fqsen, $types);
2528

2629
$this->assertSame($fqsen, $type->getFqsen());
2730
$this->assertSame($types, $type->getTypes());
@@ -31,20 +34,20 @@ public function testCreate(): void
3134
* @dataProvider provideToStringData
3235
* @covers ::__toString
3336
*/
34-
public function testToString(string $expectedResult, GenericType $type): void
37+
public function testToString(string $expectedResult, Generic $type): void
3538
{
3639
$this->assertSame($expectedResult, (string) $type);
3740
}
3841

3942
/**
40-
* @return array<string, array{string, GenericType}>
43+
* @return array<string, array{string, Generic}>
4144
*/
4245
public static function provideToStringData(): array
4346
{
4447
return [
4548
'without fqsen' => [
4649
'object<string>',
47-
new GenericType(
50+
new Generic(
4851
null,
4952
[
5053
new String_(),
@@ -53,18 +56,18 @@ public static function provideToStringData(): array
5356
],
5457
'collection without key' => [
5558
'\\ArrayObject<string>',
56-
new GenericType(new Fqsen('\\ArrayObject'), [new String_()]),
59+
new Generic(new Fqsen('\\ArrayObject'), [new String_()]),
5760
],
5861
'collection with key' => [
5962
'\\ArrayObject<string[], \\Iterator>',
60-
new GenericType(
63+
new Generic(
6164
new Fqsen('\\ArrayObject'),
6265
[new Array_(new String_()), new Object_(new Fqsen('\\Iterator'))]
6366
),
6467
],
6568
'more than two generics' => [
6669
'\\MyClass<\\SomeClassFirst, \\SomeClassSecond, \\SomeClassThird>',
67-
new GenericType(
70+
new Generic(
6871
new Fqsen('\\MyClass'),
6972
[
7073
new Object_(new Fqsen('\\SomeClassFirst')),

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
2424
use phpDocumentor\Reflection\PseudoTypes\False_;
2525
use phpDocumentor\Reflection\PseudoTypes\FloatValue;
26+
use phpDocumentor\Reflection\PseudoTypes\Generic;
2627
use phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString;
2728
use phpDocumentor\Reflection\PseudoTypes\IntegerRange;
2829
use phpDocumentor\Reflection\PseudoTypes\IntegerValue;
@@ -59,7 +60,6 @@
5960
use phpDocumentor\Reflection\Types\Context;
6061
use phpDocumentor\Reflection\Types\Expression;
6162
use phpDocumentor\Reflection\Types\Float_;
62-
use phpDocumentor\Reflection\Types\GenericType;
6363
use phpDocumentor\Reflection\Types\Integer;
6464
use phpDocumentor\Reflection\Types\InterfaceString;
6565
use phpDocumentor\Reflection\Types\Intersection;
@@ -1117,7 +1117,7 @@ public function genericsProvider(): array
11171117
[
11181118
'Collection<array-key, int>[]',
11191119
new Array_(
1120-
new GenericType(
1120+
new Generic(
11211121
new Fqsen('\\phpDocumentor\\Collection'),
11221122
[
11231123
new ArrayKey(),

0 commit comments

Comments
 (0)