class Foobar
/** @var HttpClient */ // <----------- the difference is here
private $httpClient;
public function __construct(HttpClient $httpClient)
$this->httpClient = $httpClient;
public function fetchOrientationToken()
$this->httpClient->methodDoesNotExist();
A violation is raised
Code snippet that reproduces the problem
https://phpstan.org/r/a6aeb2711d867c2bda6e388ee515e9c4
Expected output
A violation should be raised in both situation
That's too bad. I really don't want to add @var XXX
on each properties. This adds nothing for other developers, nor IDE, nor PHP.
Is fixing this something you want to consider ?
Could you consider adding a configuration option to "virtually" add @var XXX
on top of each properties that is a constructor arguments?
It would be an opt-in option of course.
Symfony’s coding standards state to not add the PHPDoc to a property if it can be inferred from the constructor, it is also the default configuration of PHP CS Fixer and it is considered a best practice by some.
It would be nice to have this option at least for interoperablility with other tools in the ecosystem.
hrach, iluuu1994, Lutacon, lucascourot, zmitic, and Kocal reacted with thumbs up emoji
lyrixx, welcoMattic, bilelgasmi, and teohhanhui reacted with confused emoji
All reactions
I understand you don't want to add this option. I will live with it but I really wanted this feature.
More over as @dunglas said, we remove all theses PHP Doc in Symfony, and it's the same for the SF community.
Do you know if we can build a plugin to do that?
https://phpstan.org/r/671b8ff43e7ac67a20058866de81d7f1
And this one?
https://phpstan.org/r/f0e0a1d235be96f4b2f0cef60c4fa2e5
You see, it's not that easy...
My point is that you can write them today in
@var, get the same benefits,
and transform them automatically to native in a year.
Yes, there’s a rule in strict-rules for that.