-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] add union types #41911
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
[Security] add union types #41911
Conversation
nicolas-grekas
commented
Jun 30, 2021
Q | A |
---|---|
Branch? | 6.0 |
Bug fix? | no |
New feature? | no |
Deprecations? | no |
Tickets | Part of #41424 |
License | MIT |
Doc PR | - |
* @param string|null $originatedFromUri The URI where was the user at the switch | ||
* @param $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method | ||
* @param $credentials This usually is the password of the user | ||
* @param $originatedFromUri The URI where was the user at the switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it valid to omit the type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for phpstorm at least it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/param.html
@param [<Type>] [name] [<description>]
[…]
When provided it MAY contain a Type to indicate what is expected.
Yes, the type is optional. But I had to look it up myself as well and I'm not yet sure if I like that notation. Maybe we just need to get used to it. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If popular IDEs support it, I'm fine with it personally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you start using PHP attributes for everything ... you want to use it even to describe arguments. I wish this worked:
#[Param('user', 'The username (like a nickname, email address, etc.), or a ...')]
#[Param('credentials', 'This usually is the password of the user')]
#[Param('originatedFromUri', 'The URI where was the user at the switch')]
public function __construct(string|\Stringable|UserInterface $user, mixed $credentials, /* ... */, string $originatedFromUri = null)
{
// ...
}
Or even better, this:
public function __construct(
#[Param('The username (like a nickname, email address, etc.), or a ...')]
private string|\Stringable|UserInterface $user,
#[Param('This usually is the password of the user')]
private mixed $credentials,
// ...
#[Param('The URI where was the user at the switch')]
private string $originatedFromUri = null)
{
}
But support for attributes in PhpDocumentor doesn't seem a priority: phpDocumentor/Reflection#185
c180104
to
2b46e64
Compare
src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Show resolved
Hide resolved
2b46e64
to
24e042c
Compare
Comments addressed, thanks @wouterj |