← All changes
|
vendor/symfony/property-info/Extractor/ReflectionExtractor.php
+92
-73
3.0.3
→
3.2.90
View file →
| @@ -7,21 +7,21 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | 9 | * file that was distributed with this source code. |
| 10 | 10 | */ |
| 11 | -namespace WindPressPackages\Symfony\Component\PropertyInfo\Extractor; | |
| 11 | +namespace WindPressDeps\Symfony\Component\PropertyInfo\Extractor; | |
| 12 | 12 | |
| 13 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; | |
| 14 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; | |
| 15 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyListExtractorInterface; | |
| 16 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyReadInfo; | |
| 17 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface; | |
| 18 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | |
| 19 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyWriteInfo; | |
| 20 | -use WindPressPackages\Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface; | |
| 21 | -use WindPressPackages\Symfony\Component\PropertyInfo\Type; | |
| 22 | -use WindPressPackages\Symfony\Component\String\Inflector\EnglishInflector; | |
| 23 | -use WindPressPackages\Symfony\Component\String\Inflector\InflectorInterface; | |
| 13 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; | |
| 14 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; | |
| 15 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyListExtractorInterface; | |
| 16 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyReadInfo; | |
| 17 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface; | |
| 18 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | |
| 19 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyWriteInfo; | |
| 20 | +use WindPressDeps\Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface; | |
| 21 | +use WindPressDeps\Symfony\Component\PropertyInfo\Type; | |
| 22 | +use WindPressDeps\Symfony\Component\String\Inflector\EnglishInflector; | |
| 23 | +use WindPressDeps\Symfony\Component\String\Inflector\InflectorInterface; | |
| 24 | 24 | /** |
| 25 | 25 | * Extracts data using the reflection API. |
| 26 | 26 | * |
| 27 | 27 | * @author Kévin Dunglas <dunglas@gmail.com> |
| @@ -78,15 +78,15 @@ | ||
| 78 | 78 | $this->methodReflectionFlags = $this->getMethodsFlags($accessFlags); |
| 79 | 79 | $this->propertyReflectionFlags = $this->getPropertyFlags($accessFlags); |
| 80 | 80 | $this->magicMethodsFlags = $magicMethodsFlags; |
| 81 | 81 | $this->inflector = $inflector ?? new EnglishInflector(); |
| 82 | - $this->arrayMutatorPrefixesFirst = \array_merge($this->arrayMutatorPrefixes, \array_diff($this->mutatorPrefixes, $this->arrayMutatorPrefixes)); | |
| 83 | - $this->arrayMutatorPrefixesLast = \array_reverse($this->arrayMutatorPrefixesFirst); | |
| 82 | + $this->arrayMutatorPrefixesFirst = array_merge($this->arrayMutatorPrefixes, array_diff($this->mutatorPrefixes, $this->arrayMutatorPrefixes)); | |
| 83 | + $this->arrayMutatorPrefixesLast = array_reverse($this->arrayMutatorPrefixesFirst); | |
| 84 | 84 | } |
| 85 | 85 | /** |
| 86 | 86 | * {@inheritdoc} |
| 87 | 87 | */ |
| 88 | - public function getProperties(string $class, array $context = []) : ?array | |
| 88 | + public function getProperties(string $class, array $context = []): ?array | |
| 89 | 89 | { |
| 90 | 90 | try { |
| 91 | 91 | $reflectionClass = new \ReflectionClass($class); |
| 92 | 92 | } catch (\ReflectionException $e) { |
| @@ -106,19 +106,19 @@ | ||
| 106 | 106 | $propertyName = $this->getPropertyName($reflectionMethod->name, $reflectionProperties); |
| 107 | 107 | if (!$propertyName || isset($properties[$propertyName])) { |
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | - if ($reflectionClass->hasProperty($lowerCasedPropertyName = \lcfirst($propertyName)) || !$reflectionClass->hasProperty($propertyName) && !\preg_match('/^[A-Z]{2,}/', $propertyName)) { | |
| 110 | + if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || !$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) { | |
| 111 | 111 | $propertyName = $lowerCasedPropertyName; |
| 112 | 112 | } |
| 113 | 113 | $properties[$propertyName] = $propertyName; |
| 114 | 114 | } |
| 115 | - return $properties ? \array_values($properties) : null; | |
| 115 | + return $properties ? array_values($properties) : null; | |
| 116 | 116 | } |
| 117 | 117 | /** |
| 118 | 118 | * {@inheritdoc} |
| 119 | 119 | */ |
| 120 | - public function getTypes(string $class, string $property, array $context = []) : ?array | |
| 120 | + public function getTypes(string $class, string $property, array $context = []): ?array | |
| 121 | 121 | { |
| 122 | 122 | if ($fromMutator = $this->extractFromMutator($class, $property)) { |
| 123 | 123 | return $fromMutator; |
| 124 | 124 | } |
| @@ -124,9 +124,9 @@ | ||
| 124 | 124 | } |
| 125 | 125 | if ($fromAccessor = $this->extractFromAccessor($class, $property)) { |
| 126 | 126 | return $fromAccessor; |
| 127 | 127 | } |
| 128 | - if (($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction) && ($fromConstructor = $this->extractFromConstructor($class, $property))) { | |
| 128 | + if (($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction) && $fromConstructor = $this->extractFromConstructor($class, $property)) { | |
| 129 | 129 | return $fromConstructor; |
| 130 | 130 | } |
| 131 | 131 | if ($fromPropertyDeclaration = $this->extractFromPropertyDeclaration($class, $property)) { |
| 132 | 132 | return $fromPropertyDeclaration; |
| @@ -135,9 +135,9 @@ | ||
| 135 | 135 | } |
| 136 | 136 | /** |
| 137 | 137 | * {@inheritdoc} |
| 138 | 138 | */ |
| 139 | - public function getTypesFromConstructor(string $class, string $property) : ?array | |
| 139 | + public function getTypesFromConstructor(string $class, string $property): ?array | |
| 140 | 140 | { |
| 141 | 141 | try { |
| 142 | 142 | $reflection = new \ReflectionClass($class); |
| 143 | 143 | } catch (\ReflectionException $e) { |
| @@ -142,23 +142,23 @@ | ||
| 142 | 142 | $reflection = new \ReflectionClass($class); |
| 143 | 143 | } catch (\ReflectionException $e) { |
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | - if (!($reflectionConstructor = $reflection->getConstructor())) { | |
| 146 | + if (!$reflectionConstructor = $reflection->getConstructor()) { | |
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | - if (!($reflectionParameter = $this->getReflectionParameterFromConstructor($property, $reflectionConstructor))) { | |
| 149 | + if (!$reflectionParameter = $this->getReflectionParameterFromConstructor($property, $reflectionConstructor)) { | |
| 150 | 150 | return null; |
| 151 | 151 | } |
| 152 | - if (!($reflectionType = $reflectionParameter->getType())) { | |
| 152 | + if (!$reflectionType = $reflectionParameter->getType()) { | |
| 153 | 153 | return null; |
| 154 | 154 | } |
| 155 | - if (!($types = $this->extractFromReflectionType($reflectionType, $reflectionConstructor->getDeclaringClass()))) { | |
| 155 | + if (!$types = $this->extractFromReflectionType($reflectionType, $reflectionConstructor->getDeclaringClass())) { | |
| 156 | 156 | return null; |
| 157 | 157 | } |
| 158 | 158 | return $types; |
| 159 | 159 | } |
| 160 | - private function getReflectionParameterFromConstructor(string $property, \ReflectionMethod $reflectionConstructor) : ?\ReflectionParameter | |
| 160 | + private function getReflectionParameterFromConstructor(string $property, \ReflectionMethod $reflectionConstructor): ?\ReflectionParameter | |
| 161 | 161 | { |
| 162 | 162 | $reflectionParameter = null; |
| 163 | 163 | foreach ($reflectionConstructor->getParameters() as $reflectionParameter) { |
| 164 | 164 | if ($reflectionParameter->getName() === $property) { |
| @@ -169,9 +169,9 @@ | ||
| 169 | 169 | } |
| 170 | 170 | /** |
| 171 | 171 | * {@inheritdoc} |
| 172 | 172 | */ |
| 173 | - public function isReadable(string $class, string $property, array $context = []) : ?bool | |
| 173 | + public function isReadable(string $class, string $property, array $context = []): ?bool | |
| 174 | 174 | { |
| 175 | 175 | if ($this->isAllowedProperty($class, $property)) { |
| 176 | 176 | return \true; |
| 177 | 177 | } |
| @@ -179,9 +179,9 @@ | ||
| 179 | 179 | } |
| 180 | 180 | /** |
| 181 | 181 | * {@inheritdoc} |
| 182 | 182 | */ |
| 183 | - public function isWritable(string $class, string $property, array $context = []) : ?bool | |
| 183 | + public function isWritable(string $class, string $property, array $context = []): ?bool | |
| 184 | 184 | { |
| 185 | 185 | if ($this->isAllowedProperty($class, $property, \true)) { |
| 186 | 186 | return \true; |
| 187 | 187 | } |
| @@ -190,9 +190,9 @@ | ||
| 190 | 190 | } |
| 191 | 191 | /** |
| 192 | 192 | * {@inheritdoc} |
| 193 | 193 | */ |
| 194 | - public function isInitializable(string $class, string $property, array $context = []) : ?bool | |
| 194 | + public function isInitializable(string $class, string $property, array $context = []): ?bool | |
| 195 | 195 | { |
| 196 | 196 | try { |
| 197 | 197 | $reflectionClass = new \ReflectionClass($class); |
| 198 | 198 | } catch (\ReflectionException $e) { |
| @@ -214,9 +214,9 @@ | ||
| 214 | 214 | } |
| 215 | 215 | /** |
| 216 | 216 | * {@inheritdoc} |
| 217 | 217 | */ |
| 218 | - public function getReadInfo(string $class, string $property, array $context = []) : ?PropertyReadInfo | |
| 218 | + public function getReadInfo(string $class, string $property, array $context = []): ?PropertyReadInfo | |
| 219 | 219 | { |
| 220 | 220 | try { |
| 221 | 221 | $reflClass = new \ReflectionClass($class); |
| 222 | 222 | } catch (\ReflectionException $e) { |
| @@ -231,9 +231,9 @@ | ||
| 231 | 231 | $allowMagicCall = $context['enable_magic_call_extraction'] ?? \false; |
| 232 | 232 | } |
| 233 | 233 | $hasProperty = $reflClass->hasProperty($property); |
| 234 | 234 | $camelProp = $this->camelize($property); |
| 235 | - $getsetter = \lcfirst($camelProp); | |
| 235 | + $getsetter = lcfirst($camelProp); | |
| 236 | 236 | // jQuery style, e.g. read: last(), write: last($item) |
| 237 | 237 | foreach ($this->accessorPrefixes as $prefix) { |
| 238 | 238 | $methodName = $prefix . $camelProp; |
| 239 | 239 | if ($reflClass->hasMethod($methodName) && $reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags && !$reflClass->getMethod($methodName)->getNumberOfRequiredParameters()) { |
| @@ -259,9 +259,9 @@ | ||
| 259 | 259 | } |
| 260 | 260 | /** |
| 261 | 261 | * {@inheritdoc} |
| 262 | 262 | */ |
| 263 | - public function getWriteInfo(string $class, string $property, array $context = []) : ?PropertyWriteInfo | |
| 263 | + public function getWriteInfo(string $class, string $property, array $context = []): ?PropertyWriteInfo | |
| 264 | 264 | { |
| 265 | 265 | try { |
| 266 | 266 | $reflClass = new \ReflectionClass($class); |
| 267 | 267 | } catch (\ReflectionException $e) { |
| @@ -309,9 +309,9 @@ | ||
| 309 | 309 | if (!\in_array($mutatorPrefix, $this->arrayMutatorPrefixes, \true)) { |
| 310 | 310 | return new PropertyWriteInfo(PropertyWriteInfo::TYPE_METHOD, $methodName, $this->getWriteVisiblityForMethod($method), $method->isStatic()); |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | - $getsetter = \lcfirst($camelized); | |
| 313 | + $getsetter = lcfirst($camelized); | |
| 314 | 314 | if ($allowGetterSetter) { |
| 315 | 315 | [$accessible, $methodAccessibleErrors] = $this->isMethodAccessible($reflClass, $getsetter, 1); |
| 316 | 316 | if ($accessible) { |
| 317 | 317 | $method = $reflClass->getMethod($getsetter); |
| @@ -323,9 +323,9 @@ | ||
| 323 | 323 | $reflProperty = $reflClass->getProperty($property); |
| 324 | 324 | if (\PHP_VERSION_ID < 80100 || !$reflProperty->isReadOnly()) { |
| 325 | 325 | return new PropertyWriteInfo(PropertyWriteInfo::TYPE_PROPERTY, $property, $this->getWriteVisiblityForProperty($reflProperty), $reflProperty->isStatic()); |
| 326 | 326 | } |
| 327 | - $errors[] = [\sprintf('The property "%s" in class "%s" is a promoted readonly property.', $property, $reflClass->getName())]; | |
| 327 | + $errors[] = [sprintf('The property "%s" in class "%s" is a promoted readonly property.', $property, $reflClass->getName())]; | |
| 328 | 328 | $allowMagicSet = $allowMagicCall = \false; |
| 329 | 329 | } |
| 330 | 330 | if ($allowMagicSet) { |
| 331 | 331 | [$accessible, $methodAccessibleErrors] = $this->isMethodAccessible($reflClass, '__set', 2); |
| @@ -341,18 +341,18 @@ | ||
| 341 | 341 | } |
| 342 | 342 | $errors[] = $methodAccessibleErrors; |
| 343 | 343 | } |
| 344 | 344 | if (!$allowAdderRemover && null !== $adderAccessName && null !== $removerAccessName) { |
| 345 | - $errors[] = [\sprintf('The property "%s" in class "%s" can be defined with the methods "%s()" but ' . 'the new value must be an array or an instance of \\Traversable', $property, $reflClass->getName(), \implode('()", "', [$adderAccessName, $removerAccessName]))]; | |
| 345 | + $errors[] = [sprintf('The property "%s" in class "%s" can be defined with the methods "%s()" but ' . 'the new value must be an array or an instance of \Traversable', $property, $reflClass->getName(), implode('()", "', [$adderAccessName, $removerAccessName]))]; | |
| 346 | 346 | } |
| 347 | 347 | $noneProperty = new PropertyWriteInfo(); |
| 348 | - $noneProperty->setErrors(\array_merge([], ...$errors)); | |
| 348 | + $noneProperty->setErrors(array_merge([], ...$errors)); | |
| 349 | 349 | return $noneProperty; |
| 350 | 350 | } |
| 351 | 351 | /** |
| 352 | 352 | * @return Type[]|null |
| 353 | 353 | */ |
| 354 | - private function extractFromMutator(string $class, string $property) : ?array | |
| 354 | + private function extractFromMutator(string $class, string $property): ?array | |
| 355 | 355 | { |
| 356 | 356 | [$reflectionMethod, $prefix] = $this->getMutatorMethod($class, $property); |
| 357 | 357 | if (null === $reflectionMethod) { |
| 358 | 358 | return null; |
| @@ -358,9 +358,9 @@ | ||
| 358 | 358 | return null; |
| 359 | 359 | } |
| 360 | 360 | $reflectionParameters = $reflectionMethod->getParameters(); |
| 361 | 361 | $reflectionParameter = $reflectionParameters[0]; |
| 362 | - if (!($reflectionType = $reflectionParameter->getType())) { | |
| 362 | + if (!$reflectionType = $reflectionParameter->getType()) { | |
| 363 | 363 | return null; |
| 364 | 364 | } |
| 365 | 365 | $type = $this->extractFromReflectionType($reflectionType, $reflectionMethod->getDeclaringClass()); |
| 366 | 366 | if (1 === \count($type) && \in_array($prefix, $this->arrayMutatorPrefixes)) { |
| @@ -372,9 +372,9 @@ | ||
| 372 | 372 | * Tries to extract type information from accessors. |
| 373 | 373 | * |
| 374 | 374 | * @return Type[]|null |
| 375 | 375 | */ |
| 376 | - private function extractFromAccessor(string $class, string $property) : ?array | |
| 376 | + private function extractFromAccessor(string $class, string $property): ?array | |
| 377 | 377 | { |
| 378 | 378 | [$reflectionMethod, $prefix] = $this->getAccessorMethod($class, $property); |
| 379 | 379 | if (null === $reflectionMethod) { |
| 380 | 380 | return null; |
| @@ -391,9 +391,9 @@ | ||
| 391 | 391 | * Tries to extract type information from constructor. |
| 392 | 392 | * |
| 393 | 393 | * @return Type[]|null |
| 394 | 394 | */ |
| 395 | - private function extractFromConstructor(string $class, string $property) : ?array | |
| 395 | + private function extractFromConstructor(string $class, string $property): ?array | |
| 396 | 396 | { |
| 397 | 397 | try { |
| 398 | 398 | $reflectionClass = new \ReflectionClass($class); |
| 399 | 399 | } catch (\ReflectionException $e) { |
| @@ -414,9 +414,9 @@ | ||
| 414 | 414 | return $this->extractFromConstructor($parentClass->getName(), $property); |
| 415 | 415 | } |
| 416 | 416 | return null; |
| 417 | 417 | } |
| 418 | - private function extractFromPropertyDeclaration(string $class, string $property) : ?array | |
| 418 | + private function extractFromPropertyDeclaration(string $class, string $property): ?array | |
| 419 | 419 | { |
| 420 | 420 | try { |
| 421 | 421 | $reflectionClass = new \ReflectionClass($class); |
| 422 | 422 | if (\PHP_VERSION_ID >= 70400) { |
| @@ -421,9 +421,9 @@ | ||
| 421 | 421 | $reflectionClass = new \ReflectionClass($class); |
| 422 | 422 | if (\PHP_VERSION_ID >= 70400) { |
| 423 | 423 | $reflectionProperty = $reflectionClass->getProperty($property); |
| 424 | 424 | $reflectionPropertyType = $reflectionProperty->getType(); |
| 425 | - if (null !== $reflectionPropertyType && ($types = $this->extractFromReflectionType($reflectionPropertyType, $reflectionProperty->getDeclaringClass()))) { | |
| 425 | + if (null !== $reflectionPropertyType && $types = $this->extractFromReflectionType($reflectionPropertyType, $reflectionProperty->getDeclaringClass())) { | |
| 426 | 426 | return $types; |
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } catch (\ReflectionException $e) { |
| @@ -436,9 +436,9 @@ | ||
| 436 | 436 | $type = \gettype($defaultValue); |
| 437 | 437 | $type = static::MAP_TYPES[$type] ?? $type; |
| 438 | 438 | return [new Type($type, $this->isNullableProperty($class, $property), null, Type::BUILTIN_TYPE_ARRAY === $type)]; |
| 439 | 439 | } |
| 440 | - private function extractFromReflectionType(\ReflectionType $reflectionType, \ReflectionClass $declaringClass) : array | |
| 440 | + private function extractFromReflectionType(\ReflectionType $reflectionType, \ReflectionClass $declaringClass): array | |
| 441 | 441 | { |
| 442 | 442 | $types = []; |
| 443 | 443 | $nullable = $reflectionType->allowsNull(); |
| 444 | 444 | foreach ($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType ? $reflectionType->getTypes() : [$reflectionType] as $type) { |
| @@ -461,19 +461,19 @@ | ||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | return $types; |
| 464 | 464 | } |
| 465 | - private function resolveTypeName(string $name, \ReflectionClass $declaringClass) : string | |
| 465 | + private function resolveTypeName(string $name, \ReflectionClass $declaringClass): string | |
| 466 | 466 | { |
| 467 | - if ('self' === ($lcName = \strtolower($name))) { | |
| 467 | + if ('self' === $lcName = strtolower($name)) { | |
| 468 | 468 | return $declaringClass->name; |
| 469 | 469 | } |
| 470 | - if ('parent' === $lcName && ($parent = $declaringClass->getParentClass())) { | |
| 470 | + if ('parent' === $lcName && $parent = $declaringClass->getParentClass()) { | |
| 471 | 471 | return $parent->name; |
| 472 | 472 | } |
| 473 | 473 | return $name; |
| 474 | 474 | } |
| 475 | - private function isNullableProperty(string $class, string $property) : bool | |
| 475 | + private function isNullableProperty(string $class, string $property): bool | |
| 476 | 476 | { |
| 477 | 477 | try { |
| 478 | 478 | $reflectionProperty = new \ReflectionProperty($class, $property); |
| 479 | 479 | if (\PHP_VERSION_ID >= 70400) { |
| @@ -485,14 +485,22 @@ | ||
| 485 | 485 | // Return false if the property doesn't exist |
| 486 | 486 | } |
| 487 | 487 | return \false; |
| 488 | 488 | } |
| 489 | - private function isAllowedProperty(string $class, string $property, bool $writeAccessRequired = \false) : bool | |
| 489 | + private function isAllowedProperty(string $class, string $property, bool $writeAccessRequired = \false): bool | |
| 490 | 490 | { |
| 491 | 491 | try { |
| 492 | 492 | $reflectionProperty = new \ReflectionProperty($class, $property); |
| 493 | - if (\PHP_VERSION_ID >= 80100 && $writeAccessRequired && $reflectionProperty->isReadOnly()) { | |
| 494 | - return \false; | |
| 493 | + if ($writeAccessRequired) { | |
| 494 | + if (\PHP_VERSION_ID >= 80100 && $reflectionProperty->isReadOnly()) { | |
| 495 | + return \false; | |
| 496 | + } | |
| 497 | + if (\PHP_VERSION_ID >= 80400 && ($reflectionProperty->isProtectedSet() || $reflectionProperty->isPrivateSet())) { | |
| 498 | + return \false; | |
| 499 | + } | |
| 500 | + if (\PHP_VERSION_ID >= 80400 && $reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { | |
| 501 | + return \false; | |
| 502 | + } | |
| 495 | 503 | } |
| 496 | 504 | return (bool) ($reflectionProperty->getModifiers() & $this->propertyReflectionFlags); |
| 497 | 505 | } catch (\ReflectionException $e) { |
| 498 | 506 | // Return false if the property doesn't exist |
| @@ -504,11 +512,11 @@ | ||
| 504 | 512 | * |
| 505 | 513 | * Returns an array with a the instance of \ReflectionMethod as first key |
| 506 | 514 | * and the prefix of the method as second or null if not found. |
| 507 | 515 | */ |
| 508 | - private function getAccessorMethod(string $class, string $property) : ?array | |
| 516 | + private function getAccessorMethod(string $class, string $property): ?array | |
| 509 | 517 | { |
| 510 | - $ucProperty = \ucfirst($property); | |
| 518 | + $ucProperty = ucfirst($property); | |
| 511 | 519 | foreach ($this->accessorPrefixes as $prefix) { |
| 512 | 520 | try { |
| 513 | 521 | $reflectionMethod = new \ReflectionMethod($class, $prefix . $ucProperty); |
| 514 | 522 | if ($reflectionMethod->isStatic()) { |
| @@ -526,17 +534,17 @@ | ||
| 526 | 534 | /** |
| 527 | 535 | * Returns an array with a the instance of \ReflectionMethod as first key |
| 528 | 536 | * and the prefix of the method as second or null if not found. |
| 529 | 537 | */ |
| 530 | - private function getMutatorMethod(string $class, string $property) : ?array | |
| 538 | + private function getMutatorMethod(string $class, string $property): ?array | |
| 531 | 539 | { |
| 532 | - $ucProperty = \ucfirst($property); | |
| 540 | + $ucProperty = ucfirst($property); | |
| 533 | 541 | $ucSingulars = $this->inflector->singularize($ucProperty); |
| 534 | 542 | $mutatorPrefixes = \in_array($ucProperty, $ucSingulars, \true) ? $this->arrayMutatorPrefixesLast : $this->arrayMutatorPrefixesFirst; |
| 535 | 543 | foreach ($mutatorPrefixes as $prefix) { |
| 536 | 544 | $names = [$ucProperty]; |
| 537 | 545 | if (\in_array($prefix, $this->arrayMutatorPrefixes)) { |
| 538 | - $names = \array_merge($names, $ucSingulars); | |
| 546 | + $names = array_merge($names, $ucSingulars); | |
| 539 | 547 | } |
| 540 | 548 | foreach ($names as $name) { |
| 541 | 549 | try { |
| 542 | 550 | $reflectionMethod = new \ReflectionMethod($class, $prefix . $name); |
| @@ -553,18 +561,18 @@ | ||
| 553 | 561 | } |
| 554 | 562 | } |
| 555 | 563 | return null; |
| 556 | 564 | } |
| 557 | - private function getPropertyName(string $methodName, array $reflectionProperties) : ?string | |
| 565 | + private function getPropertyName(string $methodName, array $reflectionProperties): ?string | |
| 558 | 566 | { |
| 559 | - $pattern = \implode('|', \array_merge($this->accessorPrefixes, $this->mutatorPrefixes)); | |
| 560 | - if ('' !== $pattern && \preg_match('/^(' . $pattern . ')(.+)$/i', $methodName, $matches)) { | |
| 567 | + $pattern = implode('|', array_merge($this->accessorPrefixes, $this->mutatorPrefixes)); | |
| 568 | + if ('' !== $pattern && preg_match('/^(' . $pattern . ')(.+)$/i', $methodName, $matches)) { | |
| 561 | 569 | if (!\in_array($matches[1], $this->arrayMutatorPrefixes)) { |
| 562 | 570 | return $matches[2]; |
| 563 | 571 | } |
| 564 | 572 | foreach ($reflectionProperties as $reflectionProperty) { |
| 565 | 573 | foreach ($this->inflector->singularize($reflectionProperty->name) as $name) { |
| 566 | - if (\strtolower($name) === \strtolower($matches[2])) { | |
| 574 | + if (strtolower($name) === strtolower($matches[2])) { | |
| 567 | 575 | return $reflectionProperty->name; |
| 568 | 576 | } |
| 569 | 577 | } |
| 570 | 578 | } |
| @@ -579,9 +587,9 @@ | ||
| 579 | 587 | * @param array $singulars The singular form of the property name or null |
| 580 | 588 | * |
| 581 | 589 | * @return array An array containing the adder and remover when found and errors |
| 582 | 590 | */ |
| 583 | - private function findAdderAndRemover(\ReflectionClass $reflClass, array $singulars) : array | |
| 591 | + private function findAdderAndRemover(\ReflectionClass $reflClass, array $singulars): array | |
| 584 | 592 | { |
| 585 | 593 | if (!\is_array($this->arrayMutatorPrefixes) && 2 !== \count($this->arrayMutatorPrefixes)) { |
| 586 | 594 | return [null, null, []]; |
| 587 | 595 | } |
| @@ -597,27 +605,27 @@ | ||
| 597 | 605 | if ($addMethodFound && $removeMethodFound) { |
| 598 | 606 | return [$addMethod, $removeMethod, []]; |
| 599 | 607 | } |
| 600 | 608 | if ($addMethodFound && !$removeMethodFound) { |
| 601 | - $errors[] = [\sprintf('The add method "%s" in class "%s" was found, but the corresponding remove method "%s" was not found', $addMethod, $reflClass->getName(), $removeMethod)]; | |
| 609 | + $errors[] = [sprintf('The add method "%s" in class "%s" was found, but the corresponding remove method "%s" was not found', $addMethod, $reflClass->getName(), $removeMethod)]; | |
| 602 | 610 | } elseif (!$addMethodFound && $removeMethodFound) { |
| 603 | - $errors[] = [\sprintf('The remove method "%s" in class "%s" was found, but the corresponding add method "%s" was not found', $removeMethod, $reflClass->getName(), $addMethod)]; | |
| 611 | + $errors[] = [sprintf('The remove method "%s" in class "%s" was found, but the corresponding add method "%s" was not found', $removeMethod, $reflClass->getName(), $addMethod)]; | |
| 604 | 612 | } |
| 605 | 613 | } |
| 606 | - return [null, null, \array_merge([], ...$errors)]; | |
| 614 | + return [null, null, array_merge([], ...$errors)]; | |
| 607 | 615 | } |
| 608 | 616 | /** |
| 609 | 617 | * Returns whether a method is public and has the number of required parameters and errors. |
| 610 | 618 | */ |
| 611 | - private function isMethodAccessible(\ReflectionClass $class, string $methodName, int $parameters) : array | |
| 619 | + private function isMethodAccessible(\ReflectionClass $class, string $methodName, int $parameters): array | |
| 612 | 620 | { |
| 613 | 621 | $errors = []; |
| 614 | 622 | if ($class->hasMethod($methodName)) { |
| 615 | 623 | $method = $class->getMethod($methodName); |
| 616 | 624 | if (\ReflectionMethod::IS_PUBLIC === $this->methodReflectionFlags && !$method->isPublic()) { |
| 617 | - $errors[] = \sprintf('The method "%s" in class "%s" was found but does not have public access.', $methodName, $class->getName()); | |
| 625 | + $errors[] = sprintf('The method "%s" in class "%s" was found but does not have public access.', $methodName, $class->getName()); | |
| 618 | 626 | } elseif ($method->getNumberOfRequiredParameters() > $parameters || $method->getNumberOfParameters() < $parameters) { |
| 619 | - $errors[] = \sprintf('The method "%s" in class "%s" requires %d arguments, but should accept only %d.', $methodName, $class->getName(), $method->getNumberOfRequiredParameters(), $parameters); | |
| 627 | + $errors[] = sprintf('The method "%s" in class "%s" requires %d arguments, but should accept only %d.', $methodName, $class->getName(), $method->getNumberOfRequiredParameters(), $parameters); | |
| 620 | 628 | } else { |
| 621 | 629 | return [\true, $errors]; |
| 622 | 630 | } |
| 623 | 631 | } |
| @@ -625,16 +633,16 @@ | ||
| 625 | 633 | } |
| 626 | 634 | /** |
| 627 | 635 | * Camelizes a given string. |
| 628 | 636 | */ |
| 629 | - private function camelize(string $string) : string | |
| 637 | + private function camelize(string $string): string | |
| 630 | 638 | { |
| 631 | - return \str_replace(' ', '', \ucwords(\str_replace('_', ' ', $string))); | |
| 639 | + return str_replace(' ', '', ucwords(str_replace('_', ' ', $string))); | |
| 632 | 640 | } |
| 633 | 641 | /** |
| 634 | 642 | * Return allowed reflection method flags. |
| 635 | 643 | */ |
| 636 | - private function getMethodsFlags(int $accessFlags) : int | |
| 644 | + private function getMethodsFlags(int $accessFlags): int | |
| 637 | 645 | { |
| 638 | 646 | $methodFlags = 0; |
| 639 | 647 | if ($accessFlags & self::ALLOW_PUBLIC) { |
| 640 | 648 | $methodFlags |= \ReflectionMethod::IS_PUBLIC; |
| @@ -649,9 +657,9 @@ | ||
| 649 | 657 | } |
| 650 | 658 | /** |
| 651 | 659 | * Return allowed reflection property flags. |
| 652 | 660 | */ |
| 653 | - private function getPropertyFlags(int $accessFlags) : int | |
| 661 | + private function getPropertyFlags(int $accessFlags): int | |
| 654 | 662 | { |
| 655 | 663 | $propertyFlags = 0; |
| 656 | 664 | if ($accessFlags & self::ALLOW_PUBLIC) { |
| 657 | 665 | $propertyFlags |= \ReflectionProperty::IS_PUBLIC; |
| @@ -663,9 +671,9 @@ | ||
| 663 | 671 | $propertyFlags |= \ReflectionProperty::IS_PROTECTED; |
| 664 | 672 | } |
| 665 | 673 | return $propertyFlags; |
| 666 | 674 | } |
| 667 | - private function getReadVisiblityForProperty(\ReflectionProperty $reflectionProperty) : string | |
| 675 | + private function getReadVisiblityForProperty(\ReflectionProperty $reflectionProperty): string | |
| 668 | 676 | { |
| 669 | 677 | if ($reflectionProperty->isPrivate()) { |
| 670 | 678 | return PropertyReadInfo::VISIBILITY_PRIVATE; |
| 671 | 679 | } |
| @@ -673,9 +681,9 @@ | ||
| 673 | 681 | return PropertyReadInfo::VISIBILITY_PROTECTED; |
| 674 | 682 | } |
| 675 | 683 | return PropertyReadInfo::VISIBILITY_PUBLIC; |
| 676 | 684 | } |
| 677 | - private function getReadVisiblityForMethod(\ReflectionMethod $reflectionMethod) : string | |
| 685 | + private function getReadVisiblityForMethod(\ReflectionMethod $reflectionMethod): string | |
| 678 | 686 | { |
| 679 | 687 | if ($reflectionMethod->isPrivate()) { |
| 680 | 688 | return PropertyReadInfo::VISIBILITY_PRIVATE; |
| 681 | 689 | } |
| @@ -683,10 +691,21 @@ | ||
| 683 | 691 | return PropertyReadInfo::VISIBILITY_PROTECTED; |
| 684 | 692 | } |
| 685 | 693 | return PropertyReadInfo::VISIBILITY_PUBLIC; |
| 686 | 694 | } |
| 687 | - private function getWriteVisiblityForProperty(\ReflectionProperty $reflectionProperty) : string | |
| 695 | + private function getWriteVisiblityForProperty(\ReflectionProperty $reflectionProperty): string | |
| 688 | 696 | { |
| 697 | + if (\PHP_VERSION_ID >= 80400) { | |
| 698 | + if ($reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { | |
| 699 | + return PropertyWriteInfo::VISIBILITY_PRIVATE; | |
| 700 | + } | |
| 701 | + if ($reflectionProperty->isPrivateSet()) { | |
| 702 | + return PropertyWriteInfo::VISIBILITY_PRIVATE; | |
| 703 | + } | |
| 704 | + if ($reflectionProperty->isProtectedSet()) { | |
| 705 | + return PropertyWriteInfo::VISIBILITY_PROTECTED; | |
| 706 | + } | |
| 707 | + } | |
| 689 | 708 | if ($reflectionProperty->isPrivate()) { |
| 690 | 709 | return PropertyWriteInfo::VISIBILITY_PRIVATE; |
| 691 | 710 | } |
| 692 | 711 | if ($reflectionProperty->isProtected()) { |
| @@ -693,9 +712,9 @@ | ||
| 693 | 712 | return PropertyWriteInfo::VISIBILITY_PROTECTED; |
| 694 | 713 | } |
| 695 | 714 | return PropertyWriteInfo::VISIBILITY_PUBLIC; |
| 696 | 715 | } |
| 697 | - private function getWriteVisiblityForMethod(\ReflectionMethod $reflectionMethod) : string | |
| 716 | + private function getWriteVisiblityForMethod(\ReflectionMethod $reflectionMethod): string | |
| 698 | 717 | { |
| 699 | 718 | if ($reflectionMethod->isPrivate()) { |
| 700 | 719 | return PropertyWriteInfo::VISIBILITY_PRIVATE; |
| 701 | 720 | } |