From 8e873d0b5be64f88b10ba7996300146770f29d1b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Mar 2020 10:53:59 +0100 Subject: [PATCH 1/3] [Security/Core] fix some annotations --- .../Core/Authentication/Token/AbstractToken.php | 4 ++-- .../Core/Authentication/Token/AnonymousToken.php | 7 ++++--- .../Authentication/Token/PreAuthenticatedToken.php | 11 ++++++----- .../Core/Authentication/Token/TokenInterface.php | 6 +++--- .../Authentication/Token/UsernamePasswordToken.php | 11 ++++++----- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index 9d5a01d942..d10b938bf0 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -31,7 +31,7 @@ abstract class AbstractToken implements TokenInterface private $attributes = []; /** - * @param (RoleInterface|string)[] $roles An array of roles + * @param (Role|string)[] $roles An array of roles * * @throws \InvalidArgumentException */ @@ -41,7 +41,7 @@ abstract class AbstractToken implements TokenInterface if (\is_string($role)) { $role = new Role($role); } elseif (!$role instanceof RoleInterface) { - throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, Role instances or RoleInterface instances, but got %s.', \gettype($role))); + throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, Role instances, but got %s.', \gettype($role))); } $this->roles[] = $role; diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php index 7677b90d27..2cbb788490 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Core\Authentication\Token; use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\User\UserInterface; /** * AnonymousToken represents an anonymous token. @@ -23,9 +24,9 @@ class AnonymousToken extends AbstractToken private $secret; /** - * @param string $secret A secret used to make sure the token is created by the app and not by a malicious client - * @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string - * @param Role[] $roles An array of roles + * @param string $secret A secret used to make sure the token is created by the app and not by a malicious client + * @param string|\Stringable|UserInterface $user + * @param (Role|string)[] $roles */ public function __construct($secret, $user, array $roles = []) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php index 7ff0cfe8a5..31a7b666cc 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php @@ -11,7 +11,8 @@ namespace Symfony\Component\Security\Core\Authentication\Token; -use Symfony\Component\Security\Core\Role\RoleInterface; +use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\User\UserInterface; /** * PreAuthenticatedToken implements a pre-authenticated token. @@ -24,10 +25,10 @@ class PreAuthenticatedToken extends AbstractToken private $providerKey; /** - * @param string|object $user The user can be a UserInterface instance, or an object implementing a __toString method or the username as a regular string - * @param mixed $credentials The user credentials - * @param string $providerKey The provider key - * @param (RoleInterface|string)[] $roles An array of roles + * @param string|\Stringable|UserInterface $user + * @param mixed $credentials + * @param string $providerKey + * @param (Role|string)[] $roles */ public function __construct($user, $credentials, $providerKey, array $roles = []) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php b/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php index 583700c178..ff30ef9078 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Core\Authentication\Token; use Symfony\Component\Security\Core\Role\RoleInterface; +use Symfony\Component\Security\Core\User\UserInterface; /** * TokenInterface is the interface for the user authentication information. @@ -47,8 +48,7 @@ interface TokenInterface extends \Serializable /** * Returns a user representation. * - * @return string|object Can be a UserInterface instance, an object implementing a __toString method, - * or the username as a regular string + * @return string|\Stringable|UserInterface * * @see AbstractToken::setUser() */ @@ -60,7 +60,7 @@ interface TokenInterface extends \Serializable * The user can be a UserInterface instance, or an object implementing * a __toString method or the username as a regular string. * - * @param string|object $user The user + * @param string|\Stringable|UserInterface $user * * @throws \InvalidArgumentException */ diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php index 9b71520a2b..ae69107edd 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php @@ -11,7 +11,8 @@ namespace Symfony\Component\Security\Core\Authentication\Token; -use Symfony\Component\Security\Core\Role\RoleInterface; +use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\User\UserInterface; /** * UsernamePasswordToken implements a username and password token. @@ -24,10 +25,10 @@ class UsernamePasswordToken extends AbstractToken private $providerKey; /** - * @param string|object $user The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method - * @param mixed $credentials This usually is the password of the user - * @param string $providerKey The provider key - * @param (RoleInterface|string)[] $roles An array of roles + * @param string|\Stringable|UserInterface $user The username (like a nickname, email address, etc.) or a UserInterface instance + * @param mixed $credentials + * @param string $providerKey + * @param (Role|string)[] $roles * * @throws \InvalidArgumentException */ From 0ee97f23a6711ff302686549a876ae6831192a6c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Mar 2020 11:25:23 +0100 Subject: [PATCH 2/3] [Validator] clarify stringable type annotations --- .../Validator/ConstraintViolation.php | 32 +++++++++---------- .../ConstraintViolationInterface.php | 2 +- .../Context/ExecutionContextInterface.php | 8 ++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Validator/ConstraintViolation.php b/src/Symfony/Component/Validator/ConstraintViolation.php index ae9ff89eb5..a90a7a0bd8 100644 --- a/src/Symfony/Component/Validator/ConstraintViolation.php +++ b/src/Symfony/Component/Validator/ConstraintViolation.php @@ -32,22 +32,22 @@ class ConstraintViolation implements ConstraintViolationInterface /** * Creates a new constraint violation. * - * @param string $message The violation message - * @param string $messageTemplate The raw violation message - * @param array $parameters The parameters to substitute in the - * raw violation message - * @param mixed $root The value originally passed to the - * validator - * @param string $propertyPath The property path from the root - * value to the invalid value - * @param mixed $invalidValue The invalid value that caused this - * violation - * @param int|null $plural The number for determining the plural - * form when translating the message - * @param mixed $code The error code of the violation - * @param Constraint|null $constraint The constraint whose validation - * caused the violation - * @param mixed $cause The cause of the violation + * @param string|\Stringable $message The violation message as a string or a stringable object + * @param string $messageTemplate The raw violation message + * @param array $parameters The parameters to substitute in the + * raw violation message + * @param mixed $root The value originally passed to the + * validator + * @param string $propertyPath The property path from the root + * value to the invalid value + * @param mixed $invalidValue The invalid value that caused this + * violation + * @param int|null $plural The number for determining the plural + * form when translating the message + * @param mixed $code The error code of the violation + * @param Constraint|null $constraint The constraint whose validation + * caused the violation + * @param mixed $cause The cause of the violation */ public function __construct($message, $messageTemplate, array $parameters, $root, $propertyPath, $invalidValue, $plural = null, $code = null, Constraint $constraint = null, $cause = null) { diff --git a/src/Symfony/Component/Validator/ConstraintViolationInterface.php b/src/Symfony/Component/Validator/ConstraintViolationInterface.php index 5ac25cf9ba..137d7015bf 100644 --- a/src/Symfony/Component/Validator/ConstraintViolationInterface.php +++ b/src/Symfony/Component/Validator/ConstraintViolationInterface.php @@ -36,7 +36,7 @@ interface ConstraintViolationInterface /** * Returns the violation message. * - * @return string The violation message + * @return string|\Stringable The violation message as a string or a stringable object */ public function getMessage(); diff --git a/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php b/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php index 09137f8511..3d7925b471 100644 --- a/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php +++ b/src/Symfony/Component/Validator/Context/ExecutionContextInterface.php @@ -64,8 +64,8 @@ interface ExecutionContextInterface /** * Adds a violation at the current node of the validation graph. * - * @param string $message The error message - * @param array $params The parameters substituted in the error message + * @param string|\Stringable $message The error message as a string or a stringable object + * @param array $params The parameters substituted in the error message */ public function addViolation($message, array $params = []); @@ -81,8 +81,8 @@ interface ExecutionContextInterface * ->setTranslationDomain('number_validation') * ->addViolation(); * - * @param string $message The error message - * @param array $parameters The parameters substituted in the error message + * @param string|\Stringable $message The error message as a string or a stringable object + * @param array $parameters The parameters substituted in the error message * * @return ConstraintViolationBuilderInterface The violation builder */ From 523f5c04ab8c11b04097db74a4de96da3688d92b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 13 Mar 2020 11:30:33 +0100 Subject: [PATCH 3/3] fix typo --- .../Security/Core/Authentication/Token/AbstractToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php index d10b938bf0..99bc3d6d8f 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php @@ -41,7 +41,7 @@ abstract class AbstractToken implements TokenInterface if (\is_string($role)) { $role = new Role($role); } elseif (!$role instanceof RoleInterface) { - throw new \InvalidArgumentException(sprintf('$roles must be an array of strings, Role instances, but got %s.', \gettype($role))); + throw new \InvalidArgumentException(sprintf('$roles must be an array of strings or Role instances, but got %s.', \gettype($role))); } $this->roles[] = $role;