Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
28 | class SamlToken extends AbstractToken |
||
29 | { |
||
30 | /** |
||
31 | * @var \SAML2\Assertion |
||
32 | */ |
||
33 | public $assertion; |
||
34 | |||
35 | /** |
||
36 | * @var \Surfnet\StepupBundle\Value\Loa |
||
37 | */ |
||
38 | private $loa; |
||
39 | |||
40 | /** |
||
41 | * @var InstitutionConfigurationOptions |
||
42 | */ |
||
43 | private $institutionConfigurationOptions; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $raManagementInstitution; |
||
49 | |||
50 | public function __construct( |
||
61 | |||
62 | /** |
||
63 | * @return InstitutionConfigurationOptions |
||
64 | */ |
||
65 | public function getInstitutionConfigurationOptions() |
||
69 | |||
70 | /** |
||
71 | * @param string $institution |
||
72 | * @param InstitutionConfigurationOptions $institutionConfigurationOptions |
||
73 | */ |
||
74 | View Code Duplication | public function changeInstitutionScope( |
|
97 | |||
98 | /** |
||
99 | * @param string $institution |
||
100 | */ |
||
101 | View Code Duplication | public function changeRaaInstitutionScope($institution) |
|
102 | { |
||
103 | if ($this->getUser() === null) { |
||
104 | throw new LogicException('Cannot change RAA institution scope: token does not contain a user'); |
||
105 | } |
||
106 | |||
107 | $roles = array_map(function (RoleInterface $role) { |
||
108 | return $role->getRole(); |
||
109 | }, $this->getRoles()); |
||
110 | |||
111 | if (!in_array('ROLE_RAA', $roles)) { |
||
112 | throw new RuntimeException(sprintf( |
||
113 | 'Unauthorized to change institution scope to "%s": role SRAA required, found roles "%s"', |
||
114 | $institution, |
||
115 | implode(', ', $roles) |
||
116 | )); |
||
117 | } |
||
118 | |||
119 | $this->raManagementInstitution = $institution; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Returns the user credentials. |
||
124 | * |
||
125 | * @return mixed The user credentials |
||
126 | */ |
||
127 | public function getCredentials() |
||
131 | |||
132 | /** |
||
133 | * @return Loa |
||
134 | */ |
||
135 | public function getLoa() |
||
139 | |||
140 | public function serialize() |
||
144 | |||
145 | public function unserialize($serialized) |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getRaManagementInstitution() |
||
162 | } |
||
163 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: