Skip to content

Commit 31e5dca

Browse files
committed
TASK: Adjust phpstan config to apply level 8 rules to the Flow/Reflection context and remove breaking changes
1 parent 9a2bd56 commit 31e5dca

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Neos.Flow/Classes/Reflection/ReflectionService.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ public function isClassReflected(string $className): bool
299299
$this->initialize();
300300
}
301301
$className = $this->cleanClassName($className);
302-
303302
return array_key_exists($className, $this->classReflectionData);
304303
}
305304

@@ -1476,7 +1475,7 @@ protected function reflectClassMethodParameter(string $className, MethodReflecti
14761475

14771476
if (
14781477
isset($this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_PARAMETERS][$parameter->getName()][self::DATA_PARAMETER_TYPE]) &&
1479-
$this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_PARAMETERS][$parameter->getName()][self::DATA_PARAMETER_TYPE] !== $this->cleanClassName($parameterAnnotation[0])
1478+
$this->classReflectionData[$className][self::DATA_CLASS_METHODS][$methodName][self::DATA_METHOD_PARAMETERS][$parameter->getName()][self::DATA_PARAMETER_TYPE] !== $this->cleanTypeName($parameterAnnotation[0])
14801479
) {
14811480
$this->log(' Wrong type in @param for "' . $method->getName() . '::' . $parameter->getName() . '": "' . $parameterAnnotation[0] . '"', LogLevel::DEBUG);
14821481
}
@@ -1691,7 +1690,7 @@ protected function evaluateClassPropertyAnnotationsForSchema(ClassSchema $classS
16911690
}
16921691

16931692
if (!$declaredType) {
1694-
throw new \Exception('Invalid type for ' . $className . '::$' . $propertyName, 1744046737);
1693+
return false;
16951694
}
16961695

16971696
if ($this->isPropertyAnnotatedWith($className, $propertyName, ORM\Id::class)) {
@@ -1927,7 +1926,7 @@ protected function convertParameterReflectionToArray(ParameterReflection $parame
19271926
}
19281927
}
19291928
if (!isset($parameterInformation[self::DATA_PARAMETER_TYPE]) && $parameterType !== null) {
1930-
$parameterInformation[self::DATA_PARAMETER_TYPE] = $this->cleanClassName($parameterType);
1929+
$parameterInformation[self::DATA_PARAMETER_TYPE] = $this->cleanTypeName($parameterType);
19311930
} elseif (!isset($parameterInformation[self::DATA_PARAMETER_TYPE])) {
19321931
$parameterInformation[self::DATA_PARAMETER_TYPE] = 'mixed';
19331932
}
@@ -2083,17 +2082,25 @@ public function saveToCache(): void
20832082
$this->log(sprintf('Updated reflection caches (%s classes).', count($this->updatedReflectionData)));
20842083
}
20852084

2085+
/**
2086+
* Clean a given type from possibly prefixed backslash
2087+
* @return string
2088+
*/
2089+
protected function cleanTypeName(string $className): string
2090+
{
2091+
return ltrim($className, '\\');
2092+
}
2093+
20862094
/**
20872095
* Clean a given class name from possibly prefixed backslash
20882096
* @return class-string
20892097
*/
20902098
protected function cleanClassName(string $className): string
20912099
{
2092-
$className = ltrim($className, '\\');
2093-
if (!class_exists($className)) {
2094-
throw new \Exception('Invalid class ' . $className, 1744047892);
2100+
$className = $this->cleanTypeName($className);
2101+
if (!class_exists($className) && !interface_exists($className) && !trait_exists($className) && !enum_exists($className)) {
2102+
throw ClassLoadingForReflectionFailedException::forClassName($className, $className);
20952103
}
2096-
20972104
return $className;
20982105
}
20992106

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
level: 8
33
paths:
4+
- Neos.Flow/Classes/Reflection
45
- Neos.Flow/Classes/ResourceManagement
56
- Neos.Flow/Classes/Security
67
- Neos.Flow/Classes/Session

0 commit comments

Comments
 (0)