Skip to content

[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

Merged
merged 1 commit into from
Jul 1, 2021
Merged

Conversation

nicolas-grekas
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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. 🤔

Copy link
Member

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.

Copy link
Member

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

@nicolas-grekas nicolas-grekas force-pushed the unions-sec branch 4 times, most recently from c180104 to 2b46e64 Compare June 30, 2021 16:21
@nicolas-grekas
Copy link
Member Author

Comments addressed, thanks @wouterj

@nicolas-grekas nicolas-grekas merged commit fd0566c into symfony:6.0 Jul 1, 2021
@nicolas-grekas nicolas-grekas deleted the unions-sec branch July 1, 2021 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants