| Conditions | 3 |
| Paths | 3 |
| Total Lines | 74 |
| Code Lines | 48 |
| 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 |
||
| 40 | public function initialize(array $data) |
||
| 41 | { |
||
| 42 | $items = [ |
||
| 43 | [ |
||
| 44 | 'owner' => 'System', |
||
| 45 | 'owner_uuid' => $data['identity']['system']['uuid'], |
||
| 46 | 'assignee' => 'System', |
||
| 47 | 'assignee_uuid' => $data['identity']['system']['uuid'], |
||
| 48 | 'permissions' => [ |
||
| 49 | [ |
||
| 50 | 'scope' => Permission::GENERIC, |
||
| 51 | 'key' => 'entity', |
||
| 52 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT, Permission::ADD, Permission::DELETE] |
||
| 53 | ], |
||
| 54 | [ |
||
| 55 | 'scope' => Permission::GENERIC, |
||
| 56 | 'key' => 'property', |
||
| 57 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT] |
||
| 58 | ], |
||
| 59 | [ |
||
| 60 | 'scope' => Permission::GENERIC, |
||
| 61 | 'key' => 'generic', |
||
| 62 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT, Permission::ADD, Permission::DELETE, Permission::EXECUTE] |
||
| 63 | ] |
||
| 64 | ] |
||
| 65 | ], |
||
| 66 | [ |
||
| 67 | 'owner' => 'BusinessUnit', |
||
| 68 | 'owner_uuid' => $data['business_unit']['administration']['uuid'], |
||
| 69 | 'assignee' => 'Staff', |
||
| 70 | 'assignee_uuid' => $data['identity']['admin']['uuid'], |
||
| 71 | 'permissions' => [ |
||
| 72 | [ |
||
| 73 | 'scope' => Permission::GENERIC, |
||
| 74 | 'key' => 'entity', |
||
| 75 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT, Permission::ADD, Permission::DELETE] |
||
| 76 | ], |
||
| 77 | [ |
||
| 78 | 'scope' => Permission::GENERIC, |
||
| 79 | 'key' => 'property', |
||
| 80 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT] |
||
| 81 | ], |
||
| 82 | [ |
||
| 83 | 'scope' => Permission::GENERIC, |
||
| 84 | 'key' => 'generic', |
||
| 85 | 'attributes' => [Permission::BROWSE, Permission::READ, Permission::EDIT, Permission::ADD, Permission::DELETE, Permission::EXECUTE] |
||
| 86 | ] |
||
| 87 | ] |
||
| 88 | ] |
||
| 89 | ]; |
||
| 90 | |||
| 91 | $manager = $this->accessService->getManager(); |
||
| 92 | |||
| 93 | foreach ($items as $item) { |
||
| 94 | $access = $this->accessService->createInstance(); |
||
| 95 | $access |
||
| 96 | ->setOwner($item['owner']) |
||
| 97 | ->setOwnerUuid($item['owner_uuid']) |
||
| 98 | ->setAssignee($item['assignee']) |
||
| 99 | ->setAssigneeUuid($item['assignee_uuid']) |
||
| 100 | ->setTenant($data['tenant']['uuid']); |
||
| 101 | |||
| 102 | foreach ($item['permissions'] as $subItem) { |
||
| 103 | $permission = $this->permissionService->createInstance(); |
||
| 104 | $permission |
||
| 105 | ->setScope($subItem['scope']) |
||
| 106 | ->setKey($subItem['key']) |
||
| 107 | ->setAttributes($subItem['attributes']) |
||
| 108 | ->setTenant($data['tenant']['uuid']); |
||
| 109 | $access->addPermission($permission); |
||
| 110 | } |
||
| 111 | |||
| 112 | $manager->persist($access); |
||
| 113 | $manager->flush(); |
||
| 114 | } |
||
| 117 |