| Conditions | 8 |
| Paths | 54 |
| Total Lines | 115 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | public function createOrganizationElements(Organization $organization) |
||
| 51 | { |
||
| 52 | $profilesData = [ |
||
| 53 | 'teacher' => [], |
||
| 54 | 'tutor' => [], |
||
| 55 | 'department_head' => [], |
||
| 56 | 'financial_manager' => [], |
||
| 57 | 'student' => [], |
||
| 58 | 'head_teacher' => [], |
||
| 59 | 'staff' => [] |
||
| 60 | ]; |
||
| 61 | |||
| 62 | $profiles = []; |
||
| 63 | |||
| 64 | $em = $this->entityManager; |
||
| 65 | foreach ($profilesData as $key => $profileData) { |
||
| 66 | $profile = new Profile(); |
||
| 67 | $profile |
||
| 68 | ->setOrganization($organization) |
||
| 69 | ->setCode($key) |
||
| 70 | ->setNameNeutral($this->translator->trans('profile.'.$key.'.0', [], 'core')) |
||
| 71 | ->setNameMale($this->translator->trans('profile.'.$key.'.1', [], 'core')) |
||
| 72 | ->setNameFemale($this->translator->trans('profile.'.$key.'.2', [], 'core')) |
||
| 73 | ->setInitials($this->translator->trans('profile.'.$key.'.initials', [], 'core')); |
||
| 74 | |||
| 75 | $profiles[$key] = $profile; |
||
| 76 | |||
| 77 | $em->persist($profile); |
||
| 78 | } |
||
| 79 | |||
| 80 | $data = [ |
||
| 81 | 'management' => [false, [], []], |
||
| 82 | 'department' => ['department_head', [], []], |
||
| 83 | 'unit' => ['tutor', [], [ |
||
| 84 | 'tutor', |
||
| 85 | 'student' |
||
| 86 | ]], |
||
| 87 | 'evaluation' => [false, [], []], |
||
| 88 | 'subject' => ['teacher', [ |
||
| 89 | 'department' => [false, false], |
||
| 90 | 'unit' => [true, false], |
||
| 91 | 'evaluation' => [true, true] |
||
| 92 | ], [ |
||
| 93 | 'teacher', |
||
| 94 | 'student'] |
||
| 95 | ], |
||
| 96 | 'other' => [false, [], []] |
||
| 97 | ]; |
||
| 98 | |||
| 99 | $elements = []; |
||
| 100 | |||
| 101 | $documentRoot = new Folder(); |
||
| 102 | $documentRoot |
||
| 103 | ->setOrganization($organization) |
||
| 104 | ->setName('documents'); |
||
| 105 | |||
| 106 | $em->persist($documentRoot); |
||
| 107 | |||
| 108 | $root = new Element(); |
||
| 109 | $root |
||
| 110 | ->setOrganization($organization) |
||
| 111 | ->setFolder(true) |
||
| 112 | ->setName($organization->getName()); |
||
| 113 | |||
| 114 | $em->persist($root); |
||
| 115 | |||
| 116 | foreach ($data as $key => $item) { |
||
| 117 | $element = new Element(); |
||
| 118 | $element |
||
| 119 | ->setOrganization($organization) |
||
| 120 | ->setParent($root) |
||
| 121 | ->setCode($key) |
||
| 122 | ->setFolder(true) |
||
| 123 | ->setLocked(true) |
||
| 124 | ->setName($this->translator->trans('list.'.$key, [], 'core')); |
||
| 125 | |||
| 126 | $em->persist($element); |
||
| 127 | |||
| 128 | if (false !== $item[0]) { |
||
| 129 | $element->setProfile($profiles[$item[0]]); |
||
| 130 | } |
||
| 131 | |||
| 132 | $elements[$key] = $element; |
||
| 133 | } |
||
| 134 | |||
| 135 | // referencias |
||
| 136 | foreach ($data as $key => $item) { |
||
| 137 | foreach ($item[1] as $name => $referenceData) { |
||
| 138 | $reference = new Reference(); |
||
| 139 | $reference |
||
| 140 | ->setSource($elements[$key]) |
||
| 141 | ->setTarget($elements[$name]) |
||
| 142 | ->setMandatory($referenceData[0]) |
||
| 143 | ->setMultiple($referenceData[1]); |
||
| 144 | |||
| 145 | $elements[$key]->addReference($reference); |
||
| 146 | $em->persist($reference); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | // actores |
||
| 151 | foreach ($data as $key => $item) { |
||
| 152 | foreach ($item[2] as $actorData) { |
||
| 153 | $actor = new Actor(); |
||
| 154 | $actor |
||
| 155 | ->setSource($elements[$key]) |
||
| 156 | ->setProfile($profiles[$actorData]); |
||
| 157 | $elements[$key]->addActor($actor); |
||
| 158 | |||
| 159 | $em->persist($actor); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | return $root; |
||
| 164 | } |
||
| 165 | } |
||
| 166 |