Skip to content

Property info cannot resolve trait namespace #34191

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
webmake opened this issue Oct 30, 2019 · 6 comments · Fixed by #40811
Closed

Property info cannot resolve trait namespace #34191

webmake opened this issue Oct 30, 2019 · 6 comments · Fixed by #40811
Labels
Bug Help wanted Issues and PRs which are looking for volunteers to complete them. PropertyInfo Status: Needs Review

Comments

@webmake
Copy link

webmake commented Oct 30, 2019

Symfony version(s) affected: 4.3.5

Description
Hello, I have encountered with problem deserializing object, and eventually pointed to property-info, that my trait exists elsewhere than class itself. It seems
that getPhpTypeAndClass is too simple for traits (?).

How to reproduce

namespace Command\Common\Traits;

use Command\Model\Payment\UserAccountDetails;

trait UserDetailsAwareTrait
{
    /**
     * @var UserAccountDetails
     */
    protected $userAccountDetails;

    public function getUserAccountDetails(): UserAccountDetails
    {
        return $this->userAccountDetails;
    }

    public function setUserAccountDetails(UserAccountDetails $userAccountDetails): void
    {
        $this->userAccountDetails = $userAccountDetails;
    }
}
namespace Command\Bank;

use Command\Common\Traits\UserDetailsAwareTrait;

class DepositCommand
{
    use UserDetailsAwareTrait;
}
namespace Command\Model\Payment;

class UserAccountDetails
{
    /**
     * @var bool|null
     */
    private $accountVerified;

    public function isAccountVerified(): ?bool
    {
        return $this->accountVerified;
    }

    public function setAccountVerified(?bool $accountVerified): UserAccountDetails
    {
        $this->accountVerified = $accountVerified;

        return $this;
    }
}

Possible Solution

It seems that another library have already resolved this issue, you can take a look and this one

Additional context
as you can see structure passed to https://github.com/phpDocumentor/ReflectionDocBlock/blob/4.3.2/src/DocBlockFactory.php#L73 within $context variable
image
gives https://github.com/symfony/property-info/blob/v4.3.5/Extractor/PhpDocExtractor.php#L150
image

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@webmake
Copy link
Author

webmake commented Dec 22, 2020

Yes, still relevant. As a temporary solution I use fullnamespace..

@carsonbot carsonbot removed the Stalled label Dec 22, 2020
@magicsunday
Copy link

Same problem here. Please fix this.

@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Feb 12, 2021
@nicolas-grekas
Copy link
Member

I'm adding the "Help wanted" label.
PR welcome.

@xabbuh
Copy link
Member

xabbuh commented Feb 13, 2021

Can you confirm that #40175 fixes this?

@fabpot fabpot closed this as completed Feb 16, 2021
fabpot added a commit that referenced this issue Feb 16, 2021
…ed in traits (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[PropertyInfo]  use the right context for properties defined in traits

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #28732, #34191
| License       | MIT
| Doc PR        |

Commits
-------

1572491 use the right context for properties defined in traits
@colinodell
Copy link
Contributor

#40175 only fixed this for properties but methods are still broken. I've therefore opened PR #40811.

nicolas-grekas added a commit that referenced this issue Apr 14, 2021
…n traits (colinodell)

This PR was merged into the 4.4 branch.

Discussion
----------

[PropertyInfo] Use the right context for methods defined in traits

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34191
| License       | MIT
| Doc PR        |

Pull request #40175 only partially fixed #34191 - it solved the problem for properties used in traits but it did not address the same issue with methods.

I have therefore applied the same style of fix and confirmed it works properly with tests.

Commits
-------

c7e9493 [PropertyInfo] Use the right context for methods defined in traits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help wanted Issues and PRs which are looking for volunteers to complete them. PropertyInfo Status: Needs Review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants