Skip to content

Commit 70fdb32

Browse files
committed
Add more phpstan checks
1 parent 90aec97 commit 70fdb32

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"autoload-dev": {
2828
"psr-4": {
29-
"phpDocumentor\\Reflection\\": "tests"
29+
"phpDocumentor\\Reflection\\": "tests/unit"
3030
}
3131
},
3232
"extra": {

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#Parameter \#1 \$types of class phpDocumentor\\Reflection\\Types\\Compound constructor expects array<phpDocumentor\\Reflection\\Type>, array<int, string> given\.#'
5+
path: %currentWorkingDirectory%/tests/unit/Types/CompoundTest.php
6+
- message: '#Parameter \#2 \$fileContents of method phpDocumentor\\Reflection\\Types\\ContextFactory::createForNamespace\(\) expects string, string|false given\.#'
7+
path: %currentWorkingDirectory%/tests/unit/Types/ContextFactoryTest.php

src/TypeResolver.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ public function __construct(FqsenResolver $fqsenResolver = null)
9797
* replaced with another namespace.
9898
* @return Type
9999
*/
100-
public function resolve($type, Context $context = null)
100+
public function resolve(string $type, Context $context = null): Type
101101
{
102-
if (!is_string($type)) {
103-
throw new \InvalidArgumentException(
104-
'Attempted to resolve type but it appeared not to be a string, received: ' . var_export($type, true)
105-
);
106-
}
107-
108102
$type = trim($type);
109103
if (!$type) {
110104
throw new \InvalidArgumentException('Attempted to resolve "' . $type . '" but it appears to be empty');

tests/unit/CollectionResolverTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@ public function testResolvingCollectionOfCollection()
170170

171171
/** @var Collection $valueType */
172172
$valueType = $resolvedType->getValueType();
173+
/** @var Object_ $collectionValueType */
174+
$collectionValueType = $valueType->getValueType();
173175
$this->assertInstanceOf(Types\Collection::class, $valueType);
174176
$this->assertInstanceOf(Types\Object_::class, $valueType->getValueType());
175177
$this->assertEquals('\\ArrayObject', (string) $valueType->getFqsen());
176-
$this->assertEquals('\\DateTime', (string) $valueType->getValueType()->getFqsen());
178+
$this->assertEquals('\\DateTime', (string) $collectionValueType->getFqsen());
177179

178180
/** @var Compound $keyType */
179181
$keyType = $resolvedType->getKeyType();

tests/unit/FqsenResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace phpDocumentor\Reflection\unit;
3+
namespace phpDocumentor\Reflection;
44

55
use phpDocumentor\Reflection\FqsenResolver;
66
use phpDocumentor\Reflection\Types\Context;

tests/unit/TypeResolverTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -583,19 +583,6 @@ public function testExceptionIsThrownIfTypeIsEmpty()
583583
$fixture->resolve(' ', new Context(''));
584584
}
585585

586-
/**
587-
* @covers ::__construct
588-
* @covers ::resolve
589-
* @uses \phpDocumentor\Reflection\Types\Context
590-
*
591-
* @expectedException \InvalidArgumentException
592-
*/
593-
public function testExceptionIsThrownIfTypeIsNotAString()
594-
{
595-
$fixture = new TypeResolver();
596-
$fixture->resolve(['a'], new Context(''));
597-
}
598-
599586
/**
600587
* Returns a list of keywords and expected classes that are created from them.
601588
*

0 commit comments

Comments
 (0)