8000 [Security] Added type-hints to auth providers, tokens and voters. · symfony/symfony@5e680c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e680c2

Browse files
committed
[Security] Added type-hints to auth providers, tokens and voters.
1 parent cc9778e commit 5e680c2

File tree

15 files changed

+34
-59
lines changed

15 files changed

+34
-59
lines changed

src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function retrieveUser($username, UsernamePasswordToken $token)
66+
protected function retrieveUser(string $username, UsernamePasswordToken $token)
6767
{
6868
$user = $token->getUser();
6969
if ($user instanceof UserInterface) {

src/Symfony/Component/Security/Core/Authentication/Provider/LdapBindAuthenticationProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ public function __construct(UserProviderInterface $userProvider, UserCheckerInte
4646

4747
/**
4848
* Set a query string to use in order to find a DN for the username.
49-
*
50-
* @param string $queryString
5149
*/
52-
public function setQueryString($queryString)
50+
public function setQueryString(string $queryString)
5351
{
5452
$this->queryString = $queryString;
5553
}
5654

5755
/**
5856
* {@inheritdoc}
5957
*/
60-
protected function retrieveUser($username, UsernamePasswordToken $token)
58+
protected function retrieveUser(string $username, UsernamePasswordToken $token)
6159
{
6260
if (AuthenticationProviderInterface::USERNAME_NONE_PROVIDED === $username) {
6361
throw new UsernameNotFoundException('Username can not be null');

src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,11 @@ public function supports(TokenInterface $token)
109109
/**
110110
* Retrieves the user from an implementation-specific location.
111111
*
112-
* @param string $username The username to retrieve
113-
* @param UsernamePasswordToken $token The Token
114-
*
115112
* @return UserInterface The user
116113
*
117114
* @throws AuthenticationException if the credentials could not be validated
118115
*/
119-
abstract protected function retrieveUser($username, UsernamePasswordToken $token);
116+
abstract protected function retrieveUser(string $username, UsernamePasswordToken $token);
120117

121118
/**
122119
* Does additional checks on the user and token (like validating the

src/Symfony/Component/Security/Core/Authentication/RememberMe/InMemoryTokenProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InMemoryTokenProvider implements TokenProviderInterface
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function loadTokenBySeries($series)
28+
public function loadTokenBySeries(string $series)
2929
{
3030
if (!isset($this->tokens[$series])) {
3131
throw new TokenNotFoundException('No token found.');
@@ -37,7 +37,7 @@ public function loadTokenBySeries($series)
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function updateToken($series, $tokenValue, \DateTime $lastUsed)
40+
public function updateToken(string $series, string $tokenValue, \DateTime $lastUsed)
4141
{
4242
if (!isset($this->tokens[$series])) {
4343
throw new TokenNotFoundException('No token found.');
@@ -56,7 +56,7 @@ public function updateToken($series, $tokenValue, \DateTime $lastUsed)
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function deleteTokenBySeries($series)
59+
public function deleteTokenBySeries(string $series)
6060
{
6161
unset($this->tokens[$series]);
6262
}

src/Symfony/Component/Security/Core/Authentication/RememberMe/TokenProviderInterface.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,23 @@ interface TokenProviderInterface
2323
/**
2424
* Loads the active token for the given series.
2525
*
26-
* @param string $series
27-
*
2826
* @return PersistentTokenInterface
2927
*
3028
* @throws TokenNotFoundException if the token is not found
3129
*/
32-
public function loadTokenBySeries($series);
30+
public function loadTokenBySeries(string $series);
3331

3432
/**
3533
* Deletes all tokens belonging to series.
36-
*
37-
* @param string $series
3834
*/
39-
public function deleteTokenBySeries($series);
35+
public function deleteTokenBySeries(string $series);
4036

4137
/**
4238
* Updates the token according to this data.
4339
*
44-
* @param string $series
45-
* @param string $tokenValue
46-
* @param \DateTime $lastUsed
47-
*
4840
* @throws TokenNotFoundException if the token is not found
4941
*/
50-
public function updateToken($series, $tokenValue, \DateTime $lastUsed);
42+
public function updateToken(string $series, string $tokenValue, \DateTime $lastUsed);
5143

5244
/**
5345
* Creates a new token.

src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public function isAuthenticated()
108108
/**
109109
* {@inheritdoc}
110110
*/
111-
public function setAuthenticated($authenticated)
111+
public function setAuthenticated(bool $authenticated)
112112
{
113-
$this->authenticated = (bool) $authenticated;
113+
$this->authenticated = $authenticated;
114114
}
115115

116116
/**
@@ -187,25 +187,21 @@ public function setAttributes(array $attributes)
187187
/**
188188
* Returns true if the attribute exists.
189189
*
190-
* @param string $name The attribute name
191-
*
192190
* @return bool true if the attribute exists, false otherwise
193191
*/
194-
public function hasAttribute($name)
192+
public function hasAttribute(string $name)
195193
{
196194
return \array_key_exists($name, $this->attributes);
197195
}
198196

199197
/**
200198
* Returns an attribute value.
201199
*
202-
* @param string $name The attribute name
203-
*
204200
* @return mixed The attribute value
205201
*
206202
* @throws \InvalidArgumentException When attribute doesn't exist for this token
207203
*/
208-
public function getAttribute($name)
204+
public function getAttribute(string $name)
209205
{
210206
if (!\array_key_exists($name, $this->attributes)) {
211207
throw new \InvalidArgumentException(sprintf('This token has no "%s" attribute.', $name));
@@ -217,10 +213,9 @@ public function getAttribute($name)
217213
/**
218214
* Sets an attribute.
219215
*
220-
* @param string $name The attribute name
221-
* @param mixed $value The attribute value
216+
* @param mixed $value The attribute value
222217
*/
223-
public function setAttribute($name, $value)
218+
public function setAttribute(string $name, $value)
224219
{
225220
$this->attributes[$name] = $value;
226221
}

src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(UserInterface $user, string $providerKey, string $se
5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function setAuthenticated($authenticated)
55+
public function setAuthenticated(bool $authenticated)
5656
{
5757
if ($authenticated) {
5858
throw new \LogicException('You cannot set this token to authenticated after creation.');

src/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ public function isAuthenticated();
8080

8181
/**
8282
* Sets the authenticated flag.
83-
*
84-
* @param bool $isAuthenticated The authenticated flag
8583
*/
86-
public function setAuthenticated($isAuthenticated);
84+
public function setAuthenticated(bool $isAuthenticated);
8785

8886
/**
8987
* Removes sensitive information from the token.
@@ -107,30 +105,25 @@ public function setAttributes(array $attributes);
107105
/**
108106
* Returns true if the attribute exists.
109107
*
110-
* @param string $name The attribute name
111-
*
112108
* @return bool true if the attribute exists, false otherwise
113109
*/
114-
public function hasAttribute($name);
110+
public function hasAttribute(string $name);
115111

116112
/**
117113
* Returns an attribute value.
118114
*
119-
* @param string $name The attribute name
120-
*
121115
* @return mixed The attribute value
122116
*
123117
* @throws \InvalidArgumentException When attribute doesn't exist for this token
124118
*/
125-
public function getAttribute($name);
119+
public function getAttribute(string $name);
126120

127121
/**
128122
* Sets an attribute.
129123
*
130-
* @param string $name The attribute name
131-
* @param mixed $value The attribute value
124+
* @param mixed $value The attribute value
132125
*/
133-
public function setAttribute($name, $value);
126+
public function setAttribute(string $name, $value);
134127

135128
/**
136129
* Returns all the necessary state of the object for serialization purposes.

src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct($user, $credentials, string $providerKey, array $rol
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function setAuthenticated($isAuthenticated)
50+
public function setAuthenticated(bool $isAuthenticated)
5151
{
5252
if ($isAuthenticated) {
5353
throw new \LogicException('Cannot set this token to trusted after instantiation.');

src/Symfony/Component/Security/Core/Authorization/Voter/Voter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function vote(TokenInterface $token, $subject, array $attributes)
5454
*
5555
* @return bool True if the attribute and subject are supported, false otherwise
5656
*/
57-
abstract protected function supports($attribute, $subject);
57+
abstract protected function supports(string $attribute, $subject);
5858

5959
/**
6060
* Perform a single access check operation on a given attribute, subject and token.
@@ -66,5 +66,5 @@ abstract protected function supports($attribute, $subject);
6666
*
6767
* @return bool
6868
*/
69-
abstract protected function voteOnAttribute($attribute, $subject, TokenInterface $token);
69+
abstract protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token);
7070
}

0 commit comments

Comments
 (0)
0