The \Symfony\Component\PropertyInfo\PhpStan\NameScopeFactory has a dependency on \phpDocumentor\Reflection\Types\ContextFactory but that is very clear when using the \Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor and it will throw an error when doing it.
The \Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor fails with a more clear exception.
How to reproduce
// First, run "composer require symfony/property-info"// and "composer require phpstan/phpdoc-parser"// Then, execute this file:<?phprequire'vendor/autoload.php';
classRole
{
publicfunction__construct(
public readonly string$name,
) {
}
}
classUser
{
/** * @param list<Role> $roles */publicfunction__construct(
public readonly array$roles,
) {
}
}
$extractor = new \Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor();
$types = $extractor->getTypes(User::class, 'roles');
// It will throw an error about an hidden dependency on \phpDocumentor\Reflection\Types\ContextFactory::class
Possible Solution
Add to the constructor of the PhpStanExtractor a check like in the PhpDocExtractor
finalclassPhpStanExtractorimplementsPropertyTypeExtractorInterface, ConstructorArgumentTypeExtractorInterface
{
...
publicfunction __construct(array$mutatorPrefixes = null, array$accessorPrefixes = null, array$arrayMutatorPrefixes = null)
{
if (!class_exists(\phpDocumentor\Reflection\Types\ContextFactory::class)) {
thrownew \LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed.', __CLASS__));
}
...
Additional Context
No response
The text was updated successfully, but these errors were encountered:
…package is missing (xabbuh)
This PR was merged into the 5.4 branch.
Discussion
----------
[PropertyInfo] fail with a meaningful error when a needed package is missing
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#49123
| License | MIT
| Doc PR |
Commits
-------
2f7cf98 fail with a meaningful error when a needed package is missing
Symfony version(s) affected
6.2.5
Description
The
\Symfony\Component\PropertyInfo\PhpStan\NameScopeFactoryhas a dependency on\phpDocumentor\Reflection\Types\ContextFactorybut that is very clear when using the\Symfony\Component\PropertyInfo\Extractor\PhpStanExtractorand it will throw an error when doing it.The
\Symfony\Component\PropertyInfo\Extractor\PhpDocExtractorfails with a more clear exception.How to reproduce
Possible Solution
Add to the constructor of the PhpStanExtractor a check like in the PhpDocExtractor
Additional Context
No response
The text was updated successfully, but these errors were encountered: