The Wayback Machine - https://web.archive.org/web/20230213202036/https://github.com/symfony/symfony/issues/49123
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PropertyInfo] PhpStanExtractor does not check for dependency package #49123

Closed
andersonamuller opened this issue Jan 26, 2023 · 1 comment
Closed

Comments

@andersonamuller
Copy link
Contributor

Symfony version(s) affected

6.2.5

Description

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:
<?php

require 'vendor/autoload.php';

class Role
{
    public function __construct(
        public readonly string $name,
    ) {
    }
}

class User
{
    /**
     * @param list<Role> $roles
     */
    public function __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

final class PhpStanExtractor implements PropertyTypeExtractorInterface, ConstructorArgumentTypeExtractorInterface 
{
...        
    public function __construct(array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null)
    {
        if (!class_exists(\phpDocumentor\Reflection\Types\ContextFactory::class)) {
            throw new \LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed.', __CLASS__));
        }
...

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Jan 29, 2023

thanks for the report, #49146 will improve this

nicolas-grekas added a commit that referenced this issue Feb 1, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.