1 | <?php |
||
10 | class SSOToken extends AbstractToken |
||
11 | { |
||
12 | /** |
||
13 | * @var Token|null |
||
14 | */ |
||
15 | private $auth0Data; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $storedRoles = []; |
||
21 | |||
22 | /** |
||
23 | * The user model for the API. |
||
24 | * |
||
25 | * @var mixed |
||
26 | */ |
||
27 | private $userModel; |
||
28 | |||
29 | /** |
||
30 | * @param Token $data |
||
31 | * |
||
32 | * @return SSOToken |
||
33 | */ |
||
34 | public function setAuth0Data(Token $data) |
||
40 | |||
41 | /** |
||
42 | * @return Token|null |
||
43 | */ |
||
44 | public function getAuth0Data() |
||
48 | |||
49 | /** |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function getAccessToken() |
||
60 | |||
61 | /** |
||
62 | * @return mixed |
||
63 | */ |
||
64 | public function getExpiresAt() |
||
72 | |||
73 | /** |
||
74 | * @return mixed |
||
75 | */ |
||
76 | public function getUserModel() |
||
80 | |||
81 | /** |
||
82 | * @param UserInfo $userModel |
||
83 | * |
||
84 | * @return SSOToken |
||
85 | */ |
||
86 | public function setUserModel(UserInfo $userModel) |
||
92 | |||
93 | public function getCredentials() |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function serialize() |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function unserialize($serialized) |
||
134 | |||
135 | public function getRoleNames(): array |
||
148 | |||
149 | |||
150 | /** |
||
151 | * This function is deprecated by Symfony 4.3. |
||
152 | */ |
||
153 | public function getRoles() |
||
165 | } |
||
166 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: