Complex classes like AclSecurityHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AclSecurityHandler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class AclSecurityHandler implements AclSecurityHandlerInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var TokenStorageInterface |
||
34 | */ |
||
35 | protected $tokenStorage; |
||
36 | |||
37 | /** |
||
38 | * @var AuthorizationCheckerInterface |
||
39 | */ |
||
40 | protected $authorizationChecker; |
||
41 | |||
42 | /** |
||
43 | * @var MutableAclProviderInterface |
||
44 | */ |
||
45 | protected $aclProvider; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $superAdminRoles; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $adminPermissions; |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $objectPermissions; |
||
61 | |||
62 | /** |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $maskBuilderClass; |
||
66 | |||
67 | /** |
||
68 | * @param TokenStorageInterface $tokenStorage |
||
69 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
70 | * @param MutableAclProviderInterface $aclProvider |
||
71 | * @param string $maskBuilderClass |
||
72 | * @param array $superAdminRoles |
||
73 | */ |
||
74 | public function __construct($tokenStorage, $authorizationChecker, MutableAclProviderInterface $aclProvider, $maskBuilderClass, array $superAdminRoles) |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function setAdminPermissions(array $permissions) |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getAdminPermissions() |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function setObjectPermissions(array $permissions) |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function getObjectPermissions() |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function isGranted(AdminInterface $admin, $attributes, $object = null) |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function getBaseRole(AdminInterface $admin) |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function buildSecurityInformation(AdminInterface $admin) |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function createObjectSecurity(AdminInterface $admin, $object) |
||
183 | |||
184 | /** |
||
185 | * {@inheritdoc} |
||
186 | */ |
||
187 | public function deleteObjectSecurity(AdminInterface $admin, $object) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function getObjectAcl(ObjectIdentityInterface $objectIdentity) |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function findObjectAcls(\Traversable $oids, array $sids = []) |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function addObjectOwner(AclInterface $acl, UserSecurityIdentity $securityIdentity = null) |
||
233 | |||
234 | /** |
||
235 | * {@inheritdoc} |
||
236 | */ |
||
237 | public function addObjectClassAces(AclInterface $acl, array $roleInformation = []) |
||
266 | |||
267 | /** |
||
268 | * {@inheritdoc} |
||
269 | */ |
||
270 | public function createAcl(ObjectIdentityInterface $objectIdentity) |
||
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function updateAcl(AclInterface $acl) |
||
282 | |||
283 | /** |
||
284 | * {@inheritdoc} |
||
285 | */ |
||
286 | public function deleteAcl(ObjectIdentityInterface $objectIdentity) |
||
290 | |||
291 | /** |
||
292 | * {@inheritdoc} |
||
293 | */ |
||
294 | public function findClassAceIndexByRole(AclInterface $acl, $role) |
||
304 | |||
305 | /** |
||
306 | * {@inheritdoc} |
||
307 | */ |
||
308 | public function findClassAceIndexByUsername(AclInterface $acl, $username) |
||
318 | } |
||
319 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: