Conditions | 10 |
Paths | 6 |
Total Lines | 42 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | public function createAccess(Role $role) |
||
53 | { |
||
54 | if (null === $role->getUuid()) { |
||
|
|||
55 | throw new LogicException('Role does not have a uuid.'); |
||
56 | } |
||
57 | |||
58 | $services = $this->discoveryService->get(); |
||
59 | |||
60 | foreach ($role->getPermissions() as $service => $scopes) { |
||
61 | if ( |
||
62 | property_exists($services, $service) && |
||
63 | $services->$service->enabled && |
||
64 | property_exists($services->$service, 'attributes') && |
||
65 | property_exists($services->$service->attributes, 'access') && |
||
66 | $services->$service->attributes->access |
||
67 | ) { |
||
68 | $access = new Access; |
||
69 | $access |
||
70 | ->setOwner($role->getOwner()) |
||
71 | ->setOwnerUuid($role->getOwnerUuid()) |
||
72 | ->setAssignee('Role') |
||
73 | ->setAssigneeUuid($role->getUuid()) |
||
74 | ->setVersion(1); |
||
75 | |||
76 | foreach ($scopes as $scope) { |
||
77 | foreach ($scope['permissions'] as $entry) { |
||
78 | $permission = new Permission; |
||
79 | $permission |
||
80 | ->setScope($scope['scope']) |
||
81 | ->setEntity($scope['entity']) |
||
82 | ->setEntityUuid($scope['entityUuid']) |
||
83 | ->setKey($entry['key']) |
||
84 | ->setAttributes($entry['attributes']); |
||
85 | $access->addPermission($permission); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | $this->api->get($service.'.access')->create($access); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | return $this; |
||
94 | } |
||
134 |