mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 12:38:44 +02:00
N°8910 - Upgrade Symfony packages (#811)
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
namespace Symfony\Component\PropertyInfo\Extractor;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||
use phpDocumentor\Reflection\DocBlockFactory;
|
||||
use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
||||
@@ -36,7 +38,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
public const MUTATOR = 2;
|
||||
|
||||
/**
|
||||
* @var array<string, array{DocBlock|null, int|null, string|null}>
|
||||
* @var array<string, array{DocBlock|null, int|null, string|null, string|null}>
|
||||
*/
|
||||
private array $docBlocks = [];
|
||||
|
||||
@@ -63,6 +65,10 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
throw new \LogicException(\sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed. Try running composer require "phpdocumentor/reflection-docblock".', __CLASS__));
|
||||
}
|
||||
|
||||
if (!is_subclass_of(Generic::class, StaticMethod::class)) {
|
||||
throw new \LogicException('symfony/property-info v6 does not support phpdocumentor/reflection-docblock v6. Please stick to ^5.2 in your composer.json file.');
|
||||
}
|
||||
|
||||
$this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance();
|
||||
$this->contextFactory = new ContextFactory();
|
||||
$this->phpDocTypeHelper = new PhpDocTypeHelper();
|
||||
@@ -114,7 +120,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
public function getTypes(string $class, string $property, array $context = []): ?array
|
||||
{
|
||||
/** @var DocBlock $docBlock */
|
||||
[$docBlock, $source, $prefix] = $this->getDocBlock($class, $property);
|
||||
[$docBlock, $source, $prefix, $declaringClass] = $this->getDocBlock($class, $property);
|
||||
if (!$docBlock) {
|
||||
return null;
|
||||
}
|
||||
@@ -133,12 +139,15 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
foreach ($this->phpDocTypeHelper->getTypes($tag->getType()) as $type) {
|
||||
switch ($type->getClassName()) {
|
||||
case 'self':
|
||||
$resolvedClass = $declaringClass ?? $class;
|
||||
break;
|
||||
|
||||
case 'static':
|
||||
$resolvedClass = $class;
|
||||
break;
|
||||
|
||||
case 'parent':
|
||||
if (false !== $resolvedClass = $parentClass ??= get_parent_class($class)) {
|
||||
if (false !== $resolvedClass = $parentClass ??= get_parent_class($declaringClass ?? $class)) {
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
@@ -217,7 +226,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{DocBlock|null, int|null, string|null}
|
||||
* @return array{DocBlock|null, int|null, string|null, string|null}
|
||||
*/
|
||||
private function getDocBlock(string $class, string $property): array
|
||||
{
|
||||
@@ -236,31 +245,36 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
$ucFirstProperty = ucfirst($property);
|
||||
|
||||
switch (true) {
|
||||
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($class, $property):
|
||||
$data = [$docBlock, self::MUTATOR, null];
|
||||
case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($reflectionProperty->class, $property):
|
||||
$data = [$docBlock, self::MUTATOR, null, $reflectionProperty->class];
|
||||
break;
|
||||
|
||||
case $docBlock = $this->getDocBlockFromProperty($class, $property):
|
||||
$data = [$docBlock, self::PROPERTY, null];
|
||||
case [$docBlock, $declaringClass] = $this->getDocBlockFromProperty($class, $property):
|
||||
$data = [$docBlock, self::PROPERTY, null, $declaringClass];
|
||||
break;
|
||||
|
||||
case [$docBlock] = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::ACCESSOR):
|
||||
$data = [$docBlock, self::ACCESSOR, null];
|
||||
case [$docBlock, , $declaringClass] = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::ACCESSOR):
|
||||
$data = [$docBlock, self::ACCESSOR, null, $declaringClass];
|
||||
break;
|
||||
|
||||
case [$docBlock, $prefix] = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::MUTATOR):
|
||||
$data = [$docBlock, self::MUTATOR, $prefix];
|
||||
case [$docBlock, $prefix, $declaringClass] = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::MUTATOR):
|
||||
$data = [$docBlock, self::MUTATOR, $prefix, $declaringClass];
|
||||
break;
|
||||
|
||||
default:
|
||||
$data = [null, null, null];
|
||||
$data = [null, null, null, null];
|
||||
}
|
||||
|
||||
return $this->docBlocks[$propertyHash] = $data;
|
||||
}
|
||||
|
||||
private function getDocBlockFromProperty(string $class, string $property): ?DocBlock
|
||||
/**
|
||||
* @return array{DocBlock, string}|null
|
||||
*/
|
||||
private function getDocBlockFromProperty(string $class, string $property, ?string $originalClass = null): ?array
|
||||
{
|
||||
$originalClass ??= $class;
|
||||
|
||||
// Use a ReflectionProperty instead of $class to get the parent class if applicable
|
||||
try {
|
||||
$reflectionProperty = new \ReflectionProperty($class, $property);
|
||||
@@ -272,37 +286,45 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasProperty($property)) {
|
||||
return $this->getDocBlockFromProperty($trait->getName(), $property);
|
||||
return $this->getDocBlockFromProperty($trait->getName(), $property, $reflector->isTrait() ? $originalClass : $reflector->getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector));
|
||||
$declaringClass = $reflector->isTrait() ? $originalClass : $reflector->getName();
|
||||
|
||||
return [$this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector)), $declaringClass];
|
||||
} catch (\InvalidArgumentException|\RuntimeException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{DocBlock, string}|null
|
||||
* @return array{DocBlock, string, string}|null
|
||||
*/
|
||||
private function getDocBlockFromMethod(string $class, string $ucFirstProperty, int $type): ?array
|
||||
private function getDocBlockFromMethod(string $class, string $ucFirstProperty, int $type, ?string $originalClass = null): ?array
|
||||
{
|
||||
$originalClass ??= $class;
|
||||
$prefixes = self::ACCESSOR === $type ? $this->accessorPrefixes : $this->mutatorPrefixes;
|
||||
$prefix = null;
|
||||
$method = null;
|
||||
|
||||
foreach ($prefixes as $prefix) {
|
||||
$methodName = $prefix.$ucFirstProperty;
|
||||
|
||||
try {
|
||||
$reflectionMethod = new \ReflectionMethod($class, $methodName);
|
||||
if ($reflectionMethod->isStatic()) {
|
||||
$method = new \ReflectionMethod($class, $methodName);
|
||||
if ($method->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::ACCESSOR === $type && \in_array((string) $method->getReturnType(), ['void', 'never'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
(self::ACCESSOR === $type && 0 === $reflectionMethod->getNumberOfRequiredParameters())
|
||||
|| (self::MUTATOR === $type && $reflectionMethod->getNumberOfParameters() >= 1)
|
||||
(self::ACCESSOR === $type && !$method->getNumberOfRequiredParameters())
|
||||
|| (self::MUTATOR === $type && $method->getNumberOfParameters() >= 1)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
@@ -311,20 +333,22 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($reflectionMethod)) {
|
||||
if (!$method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$reflector = $reflectionMethod->getDeclaringClass();
|
||||
$reflector = $method->getDeclaringClass();
|
||||
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($methodName)) {
|
||||
return $this->getDocBlockFromMethod($trait->getName(), $ucFirstProperty, $type);
|
||||
return $this->getDocBlockFromMethod($trait->getName(), $ucFirstProperty, $type, $reflector->isTrait() ? $originalClass : $reflector->getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
|
||||
$declaringClass = $reflector->isTrait() ? $originalClass : $reflector->getName();
|
||||
|
||||
return [$this->docBlockFactory->create($method, $this->createFromReflector($reflector)), $prefix, $declaringClass];
|
||||
} catch (\InvalidArgumentException|\RuntimeException) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user