mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Fix FQSEN resolving on see,covers,uses
The See, Covers and Use tags can reference also methods, properties and constants. Which means that the FqsenResolver cannot handle those properly. This patch fixes that issue.
This commit is contained in:
@@ -20,6 +20,8 @@ use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\Utils;
|
||||
use Webmozart\Assert\Assert;
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
|
||||
/**
|
||||
* Reflection class for a @covers tag in a Docblock.
|
||||
@@ -54,11 +56,24 @@ final class Covers extends BaseTag implements Factory\StaticMethod
|
||||
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
|
||||
|
||||
return new static(
|
||||
$resolver->resolve($parts[0], $context),
|
||||
self::resolveFqsen($parts[0], $resolver, $context),
|
||||
$descriptionFactory->create($parts[1] ?? '', $context)
|
||||
);
|
||||
}
|
||||
|
||||
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
|
||||
{
|
||||
Assert::notNull($fqsenResolver);
|
||||
$fqsenParts = explode('::', $parts);
|
||||
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
|
||||
|
||||
if (!array_key_exists(1, $fqsenParts)) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
return new Fqsen($resolved . '::' . $fqsenParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the structural element this tag refers to.
|
||||
*/
|
||||
|
||||
@@ -18,10 +18,13 @@ use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\Utils;
|
||||
use Webmozart\Assert\Assert;
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
@@ -50,7 +53,6 @@ final class See extends BaseTag implements Factory\StaticMethod
|
||||
?DescriptionFactory $descriptionFactory = null,
|
||||
?TypeContext $context = null
|
||||
) : self {
|
||||
Assert::notNull($typeResolver);
|
||||
Assert::notNull($descriptionFactory);
|
||||
|
||||
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
|
||||
@@ -61,7 +63,20 @@ final class See extends BaseTag implements Factory\StaticMethod
|
||||
return new static(new Url($parts[0]), $description);
|
||||
}
|
||||
|
||||
return new static(new FqsenRef($typeResolver->resolve($parts[0], $context)), $description);
|
||||
return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description);
|
||||
}
|
||||
|
||||
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
|
||||
{
|
||||
Assert::notNull($fqsenResolver);
|
||||
$fqsenParts = explode('::', $parts);
|
||||
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
|
||||
|
||||
if (!array_key_exists(1, $fqsenParts)) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
return new Fqsen($resolved . '::' . $fqsenParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,8 @@ use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\Types\Context as TypeContext;
|
||||
use phpDocumentor\Reflection\Utils;
|
||||
use Webmozart\Assert\Assert;
|
||||
use function array_key_exists;
|
||||
use function explode;
|
||||
|
||||
/**
|
||||
* Reflection class for a {@}uses tag in a Docblock.
|
||||
@@ -53,11 +55,24 @@ final class Uses extends BaseTag implements Factory\StaticMethod
|
||||
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
|
||||
|
||||
return new static(
|
||||
$resolver->resolve($parts[0], $context),
|
||||
self::resolveFqsen($parts[0], $resolver, $context),
|
||||
$descriptionFactory->create($parts[1] ?? '', $context)
|
||||
);
|
||||
}
|
||||
|
||||
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
|
||||
{
|
||||
Assert::notNull($fqsenResolver);
|
||||
$fqsenParts = explode('::', $parts);
|
||||
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
|
||||
|
||||
if (!array_key_exists(1, $fqsenParts)) {
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
return new Fqsen($resolved . '::' . $fqsenParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the structural element this tag refers to.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user