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 |
||
27 | class PermissionsHelper extends AppHelper |
||
28 | { |
||
29 | /** |
||
30 | * Permissions |
||
31 | * |
||
32 | * @var Permissions |
||
33 | */ |
||
34 | private $Permissions; |
||
35 | |||
36 | /** |
||
37 | * {@inheritDoc} |
||
38 | */ |
||
39 | public function initialize(array $config) |
||
47 | |||
48 | /** |
||
49 | * Get an array to use as $option in a select field with role-IDs |
||
50 | * |
||
51 | * @param bool $includeAnon Include anon-user |
||
52 | * @return array |
||
53 | */ |
||
54 | View Code Duplication | public function rolesSelectId(bool $includeAnon = false): array |
|
62 | |||
63 | /** |
||
64 | * Get an array to use as $option in a select field with role-types |
||
65 | * |
||
66 | * @param bool $includeAnon Include anon-user |
||
67 | * @return array |
||
68 | */ |
||
69 | View Code Duplication | public function rolesSelectType(bool $includeAnon = false): array |
|
77 | |||
78 | /** |
||
79 | * L10n a role. |
||
80 | * |
||
81 | * @param int|string $id Role-ID or role-type. |
||
82 | * @return string The localized string. |
||
83 | */ |
||
84 | public function roleAsString($id): string |
||
92 | } |
||
93 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..