Skip to content

Commit 8f4e85c

Browse files
committed
code style fixes
1 parent e24aabf commit 8f4e85c

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/TypeResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ private function resolveClassString(ArrayIterator $tokens, Context $context): ar
485485
}
486486

487487
if ($aggreatedObjects) {
488+
assert($classType instanceof AggregatedType);
488489
foreach ($classType->getIterator() as $typeInner) {
489490
if (!$typeInner instanceof Object_ || $typeInner->getFqsen() === null) {
490491
throw new RuntimeException(
@@ -515,10 +516,13 @@ private function resolveClassString(ArrayIterator $tokens, Context $context): ar
515516

516517
$return = [];
517518
if ($aggreatedObjects) {
519+
assert($classType instanceof AggregatedType);
518520
foreach ($classType->getIterator() as $typeInner) {
521+
assert($typeInner instanceof Object_);
519522
$return[] = new ClassString($typeInner->getFqsen());
520523
}
521524
} else {
525+
assert($classType instanceof Object_);
522526
$return[] = new ClassString($classType->getFqsen());
523527
}
524528

src/Types/AbstractList.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use phpDocumentor\Reflection\Type;
1717

18+
use function count;
19+
use function implode;
20+
1821
/**
1922
* Represents a list of values. This is an abstract class for Array_ and Collection.
2023
*
@@ -67,16 +70,21 @@ public function getValueType(): Type
6770
public function __toString(): string
6871
{
6972
if ($this->keyType) {
70-
7173
$classStringValues = [];
7274
if ($this->valueType instanceof AggregatedType) {
75+
/**
76+
* @psalm-suppress ImpureMethodCall
77+
*/
7378
foreach ($this->valueType->getIterator() as $typeInner) {
74-
if (!$typeInner instanceof ClassString) {
79+
if ($typeInner instanceof ClassString) {
80+
$fqsenTmp = $typeInner->getFqsen();
81+
if ($fqsenTmp) {
82+
$classStringValues[] = $fqsenTmp->__toString();
83+
}
84+
} else {
7585
$classStringValues = [];
7686
break;
7787
}
78-
79-
$classStringValues[] = $typeInner->getFqsen()->__toString();
8088
}
8189
}
8290
if (count($classStringValues) > 0) {

tests/unit/ClassStringResolverTest.php

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

1414
namespace phpDocumentor\Reflection;
1515

16-
use phpDocumentor\Reflection\PseudoTypes\IntegerRange;
16+
use phpDocumentor\Reflection\Types\Array_;
17+
use phpDocumentor\Reflection\Types\ClassString;
18+
use phpDocumentor\Reflection\Types\Compound;
1719
use phpDocumentor\Reflection\Types\Context;
20+
use phpDocumentor\Reflection\Types\Integer;
1821
use PHPUnit\Framework\TestCase;
1922

2023
/**
@@ -37,15 +40,15 @@ public function testResolvingClassString(): void
3740

3841
$resolvedType = $fixture->resolve('array<int,class-string<\Foo\Bar>>', new Context(''));
3942

40-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Array_::class, $resolvedType);
43+
$this->assertInstanceOf(Array_::class, $resolvedType);
4144
$this->assertSame('array<int,class-string<\Foo\Bar>>', (string) $resolvedType);
4245

4346
$keyType = $resolvedType->getKeyType();
4447
$valueTpye = $resolvedType->getValueType();
4548

46-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Integer::class, $keyType);
49+
$this->assertInstanceOf(Integer::class, $keyType);
4750

48-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\ClassString::class, $valueTpye);
51+
$this->assertInstanceOf(ClassString::class, $valueTpye);
4952
$this->assertSame('Bar', $valueTpye->getFqsen()->getName());
5053
$this->assertSame('\Foo\Bar', $valueTpye->getFqsen()->__toString());
5154
}
@@ -64,18 +67,17 @@ public function testResolvingClassStrings(): void
6467

6568
$resolvedType = $fixture->resolve('array<int,class-string<\Foo\Bar|\Foo\Lall>>', new Context(''));
6669

67-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Array_::class, $resolvedType);
70+
$this->assertInstanceOf(Array_::class, $resolvedType);
6871
$this->assertSame('array<int,class-string<\Foo\Bar|\Foo\Lall>>', (string) $resolvedType);
6972

7073
$keyType = $resolvedType->getKeyType();
7174
$valueTpye = $resolvedType->getValueType();
7275

73-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Integer::class, $keyType);
76+
$this->assertInstanceOf(Integer::class, $keyType);
7477

75-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\Compound::class, $valueTpye);
78+
$this->assertInstanceOf(Compound::class, $valueTpye);
7679
foreach ($valueTpye->getIterator() as $type) {
77-
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\ClassString::class, $type);
80+
$this->assertInstanceOf(ClassString::class, $type);
7881
}
7982
}
80-
8183
}

0 commit comments

Comments
 (0)