Skip to content

Commit a29e58d

Browse files
committed
phpstan update and fixes
1 parent 831c63f commit a29e58d

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

phive.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpunit" version="^6.5.5" installed="6.5.5" location="./tools/phpunit"/>
4-
<phar name="phpstan" version="^0.9.1" installed="0.9.1" location="./tools/phpstan"/>
3+
<phar name="phpunit" version="^6.5.5" installed="6.5.11" location="./tools/phpunit"/>
4+
<phar name="phpstan" version="^0.9.1" installed="0.10.2" location="./tools/phpstan"/>
55
</phive>

src/FqsenResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private function isFqsen($type)
5050
*
5151
* @param string $type
5252
* @return Fqsen
53-
* @throws InvalidArgumentException when type is not a valid FQSEN.
53+
* @throws \InvalidArgumentException when type is not a valid FQSEN.
5454
*/
5555
private function resolvePartialStructuralElementName($type, Context $context)
5656
{

src/TypeResolver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public function resolve($type, Context $context = null)
116116

117117
// split the type string into tokens `|`, `?`, `(`, `)[]`, '<', '>' and type names
118118
$tokens = preg_split('/(\\||\\?|<|>|,|\\(|\\)(?:\\[\\])+)/', $type, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
119+
if (false === $tokens) {
120+
throw new \InvalidArgumentException('Unable to split the type string "' . $type . '" into tokens');
121+
}
119122
$tokenIterator = new \ArrayIterator($tokens);
120123

121124
return $this->parseTypes($tokenIterator, $context, self::PARSER_IN_COMPOUND);
@@ -193,8 +196,9 @@ private function parseTypes(\ArrayIterator $tokens, Context $context, $parserCon
193196
}
194197

195198
$classType = array_pop($types);
196-
197-
$types[] = $this->resolveCollection($tokens, $classType, $context);
199+
if ($classType) {
200+
$types[] = $this->resolveCollection($tokens, $classType, $context);
201+
}
198202

199203
$tokens->next();
200204
} elseif ($parserContext === self::PARSER_IN_COLLECTION_EXPRESSION

src/Types/ContextFactory.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ public function createFromReflector(\Reflector $reflector): Context
6363

6464
private function createFromReflectionParameter(\ReflectionParameter $parameter): Context
6565
{
66-
return $this->createFromReflectionClass($parameter->getDeclaringClass());
66+
$class = $parameter->getDeclaringClass();
67+
if ($class) {
68+
return $this->createFromReflectionClass($class);
69+
}
6770
}
6871

6972
private function createFromReflectionMethod(\ReflectionMethod $method): Context
@@ -87,7 +90,11 @@ private function createFromReflectionClass(\ReflectionClass $class): Context
8790
$namespace = $class->getNamespaceName();
8891

8992
if (is_string($fileName) && file_exists($fileName)) {
90-
return $this->createForNamespace($namespace, file_get_contents($fileName));
93+
$contents = file_get_contents($fileName);
94+
if (false === $contents) {
95+
throw new \RuntimeException('Unable to read file "' . $fileName . '"');
96+
}
97+
return $this->createForNamespace($namespace, $contents);
9198
}
9299

93100
return new Context($namespace, []);

src/Types/Object_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class Object_ implements Type
3030
/**
3131
* Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'.
3232
*
33-
* @throws InvalidArgumentException when provided $fqsen is not a valid type.
33+
* @throws \InvalidArgumentException when provided $fqsen is not a valid type.
3434
*/
3535
public function __construct(Fqsen $fqsen = null)
3636
{

0 commit comments

Comments
 (0)