Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyInfo] PhpStan FQSEN error #44431

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

Closed
vlastv opened this issue Dec 2, 2021 · 14 comments
Closed

[PropertyInfo] PhpStan FQSEN error #44431

vlastv opened this issue Dec 2, 2021 · 14 comments

Comments

@vlastv
Copy link
Contributor

vlastv commented Dec 2, 2021

Symfony version(s) affected

5.4, 6.*

Description

PhpStanExtractor incorrect detect class with different namespace. PhpDocExtractor work correct.

#40457

How to reproduce

<?php

namespace {
    require_once __DIR__ . '/vendor/autoload.php';

    use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
    use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;

    $phpDocExtractor = new PhpDocExtractor();
    $phpStanExtractor = new PhpStanExtractor();


    dump(
        $phpDocTypes = $phpDocExtractor->getTypes(B\Dummy::class, 'property'),
        $phpStanTypes = $phpStanExtractor->getTypes(B\Dummy::class, 'property')
    );

    assert($phpStanTypes[0]->getClassName() === 'A\Property');
    assert($phpDocTypes[0]->getClassName() === $phpStanTypes[0]->getClassName());
}


namespace A {
    class Property {

    }

    class Dummy {
        /**
         * @var Property
         */
        public $property;
    }
}

namespace B {
    class Dummy extends \A\Dummy {

    }
}

Possible Solution

No response

Additional Context

No response

@Korbeil
Copy link
Contributor

Korbeil commented Dec 10, 2021

This is duplicate of #44417 and was fixed in #44430

@xabbuh xabbuh closed this as completed Dec 10, 2021
@isypov-andrey
Copy link

isypov-andrey commented Mar 24, 2022

This bug is actual and not fixed in #44430
image
I don't see any changes

@Korbeil
Copy link
Contributor

Korbeil commented Mar 24, 2022

Could you share what is your issue and how to reproduce it maybe ?

This bug was fixed and there is a test in the PR to show how I fixed it. Maybe you found a different bug or a new way to get the same issue ?

@isypov-andrey
Copy link

isypov-andrey commented Mar 24, 2022

I have exactly the same case as @vlastv. In your test, the full namespace is indicated, but here is the relative one. The problem is with inheritance in another namespace

@Korbeil
Copy link
Contributor

Korbeil commented Mar 24, 2022

Are you sure you are up-to-date ?

@isypov-andrey
Copy link

isypov-andrey commented Mar 25, 2022

Yes, i ran this code on version property-info v5.4.3
Output:

array:1 [
  0 => Symfony\Component\PropertyInfo\Type {#20
    -builtinType: "object"
    -nullable: false
    -class: "A\Property"
    -collection: false
    -collectionKeyType: []
    -collectionValueType: []
  }
]
array:1 [
  0 => Symfony\Component\PropertyInfo\Type {#32
    -builtinType: "object"
    -nullable: false
    -class: "B\Property"
    -collection: false
    -collectionKeyType: []
    -collectionValueType: []
  }
]

Fatal error: Uncaught AssertionError: assert($phpStanTypes[0]->getClassName() === 'A\\Property') in /Users/andrejisypov/Projects/ucheba/ucheba-backend/src/test.php:17
Stack trace:
#0 /Users/andrejisypov/Projects/ucheba/ucheba-backend/src/test.php(17): assert(false, 'assert($phpStan...')
#1 {main}
  thrown in /Users/andrejisypov/Projects/ucheba/ucheba-backend/src/test.php on line 17

@xabbuh
Copy link
Member

xabbuh commented Mar 25, 2022

@isypov-andrey Please open a new issue and provide an example project that allows to reproduce your issue. Thanks!

@isypov-andrey
Copy link

@xabbuh It seems to me that it is worth reopening this issue, since the problem has not actually been resolved. There are no changes in PR #44430 except refactoring

@xabbuh
Copy link
Member

xabbuh commented Mar 25, 2022

Please provide an example application that allows to reproduce and we can consider to reopen.

@isypov-andrey
Copy link

https://github.com/isypov-andrey/property-info-bug

@isypov-andrey
Copy link

@xabbuh @Korbeil Did you check my example?

@xabbuh xabbuh reopened this Mar 30, 2022
@Korbeil
Copy link
Contributor

Korbeil commented Mar 30, 2022

Thanks for the reproducer, I'll try to fix it as soon as possible.

@Korbeil
Copy link
Contributor

Korbeil commented Mar 30, 2022

I think I found the issue and fixed it, could you take a look on the linked pull request @isypov-andrey ?

@isypov-andrey
Copy link

@Korbeil PR solves the problem, thanks for the quick fix!

nicolas-grekas added a commit that referenced this issue Mar 31, 2022
…(Korbeil)

This PR was merged into the 5.4 branch.

Discussion
----------

[PropertyInfo] PhpStanExtractor namespace missmatch issue

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44431
| License       | MIT
| Doc PR        | N/A

Thanks to `@isypov`-andrey report, we found out an issue with namespace matching and the PhpStanExtractor.
In this PR I'm fixing this issue.

- [x] Test to validate the issue
- [x] Fix

Commits
-------

d46b676 [PropertyInfo] PhpStanExtractor namespace missmatch issue
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

6 participants