Skip to content

Commit 3375963

Browse files
committed
PHPStan fixes.
1 parent 595a416 commit 3375963

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ parameters:
22
level: 8
33
paths:
44
- src
5-
checkGenericClassInNonGenericObjectType: false
65
ignoreErrors:
76
- '#Match expression does not handle remaining value#'
87
- '#has an uninitialized readonly property (.*). Assign it in the constructor.#'

src/AttributeParser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ protected function attributeInheritanceTree(\Reflector $subject, string $attribu
235235
*
236236
* This includes both classes and interfaces.
237237
*
238-
* @param \ReflectionClass $subject
238+
* @param \ReflectionClass<object> $subject
239239
* The reflection of the class for which we want the ancestors.
240-
* @return iterable<\ReflectionClass>
240+
* @return iterable<\ReflectionClass<object>>
241241
* @throws \ReflectionException
242242
*/
243243
protected function classInheritanceTree(\ReflectionClass $subject): iterable
@@ -293,7 +293,7 @@ protected function parameterInheritanceTree(\ReflectionParameter $subject): iter
293293
*
294294
* @param \ReflectionProperty|\ReflectionMethod|\ReflectionClassConstant $subject
295295
* The reflection of the component for which we want the ancestors.
296-
* @return iterable<\Reflector>
296+
* @return iterable<\ReflectionProperty|\ReflectionMethod|\ReflectionClassConstant>
297297
* @throws \ReflectionException
298298
*/
299299
protected function classElementInheritanceTree(\ReflectionProperty|\ReflectionMethod|\ReflectionClassConstant $subject): iterable
@@ -309,6 +309,7 @@ protected function classElementInheritanceTree(\ReflectionProperty|\ReflectionMe
309309
foreach ($this->classAncestors($subject->getDeclaringClass()->name) as $class) {
310310
$rClass = new \ReflectionClass($class);
311311
if ($rClass->$hasMethod($subjectName)) {
312+
// @phpstan-ignore generator.valueType (PHPStan thinks this could be false, but I'm pretty sure it's wrong.)
312313
yield $rClass->$getMethod($subjectName);
313314
}
314315
}
@@ -323,7 +324,7 @@ protected function classElementInheritanceTree(\ReflectionProperty|\ReflectionMe
323324
public function classAncestors(string $class, bool $includeClass = true): array
324325
{
325326
// These methods both return associative arrays, making + safe.
326-
/** @var array<class-string> $ancestors */
327+
/** @var array<string, class-string> $ancestors */
327328
$ancestors = class_parents($class) + class_implements($class);
328329
return $includeClass
329330
? [$class => $class] + $ancestors

src/Attributes/Reflect/CollectParameters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Crell\AttributeUtils\Attributes\Reflect;
66

7+
// @phpstan-ignore trait.unused (I don't know why PHPStan thinks this is unused. It very much is used.)
78
trait CollectParameters
89
{
910
/** @var ReflectParameter[] */

src/Attributes/Reflect/ReflectClass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class ReflectClass implements FromReflectionClass, ParseMethods, ParseStaticMeth
6868
*/
6969
public readonly ClassType $structType;
7070

71+
/**
72+
* @param \ReflectionClass<object> $subject
73+
*/
7174
public function fromReflection(\ReflectionClass $subject): void
7275
{
7376
$this->phpName = $subject->getName();

src/FromReflectionClass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
*/
1818
interface FromReflectionClass
1919
{
20+
/**
21+
* @param \ReflectionClass<object> $subject
22+
*/
2023
public function fromReflection(\ReflectionClass $subject): void;
2124
}

src/FromReflectionEnum.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
*/
1818
interface FromReflectionEnum
1919
{
20+
/**
21+
* @param \ReflectionEnum<\UnitEnum> $subject
22+
*/
2023
public function fromReflection(\ReflectionEnum $subject): void;
2124
}

0 commit comments

Comments
 (0)