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 |
||
8 | class RolesDataSource |
||
|
|||
9 | { |
||
10 | /** |
||
11 | * @var TokenStorage |
||
12 | */ |
||
13 | private $tokenStorage; |
||
14 | |||
15 | /* |
||
16 | * @var array |
||
17 | */ |
||
18 | private $roleHierarchy; |
||
19 | |||
20 | /** |
||
21 | * RolesDataSource constructor. |
||
22 | * |
||
23 | * @param TokenStorage $tokenStorage |
||
24 | * @param array $roleHierarchy |
||
25 | */ |
||
26 | public function __construct(TokenStorage $tokenStorage, $roleHierarchy) |
||
31 | |||
32 | /** |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function getRoles() |
||
41 | |||
42 | /** |
||
43 | * @return array |
||
44 | */ |
||
45 | View Code Duplication | public function getRolesFormParams() |
|
58 | |||
59 | /** |
||
60 | * flatten the array of all roles defined in role_hierarchy. |
||
61 | * |
||
62 | * @param array $roleHierarchy |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function getAllAvailableRoles($roleHierarchy) |
||
83 | } |
||
84 |