| Conditions | 13 |
| Paths | 205 |
| Total Lines | 61 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 119 | protected function normalizeNames(Registry $registry): Registry |
||
| 120 | { |
||
| 121 | // resolve all the relation target names into roles |
||
| 122 | foreach ($this->locator->getClasses() as $class) { |
||
| 123 | if (!$registry->hasEntity($class->getName())) { |
||
| 124 | continue; |
||
| 125 | } |
||
| 126 | |||
| 127 | $e = $registry->getEntity($class->getName()); |
||
| 128 | |||
| 129 | // relations |
||
| 130 | foreach ($e->getRelations() as $name => $r) { |
||
| 131 | try { |
||
| 132 | $r->setTarget($this->resolveTarget($registry, $r->getTarget())); |
||
| 133 | |||
| 134 | if ($r->getOptions()->has('though')) { |
||
| 135 | $though = $r->getOptions()->get('though'); |
||
| 136 | if ($though !== null) { |
||
| 137 | $r->getOptions()->set( |
||
| 138 | 'though', |
||
| 139 | $this->resolveTarget($registry, $though) |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($r->getOptions()->has('through')) { |
||
| 145 | $through = $r->getOptions()->get('through'); |
||
| 146 | if ($through !== null) { |
||
| 147 | $r->getOptions()->set( |
||
| 148 | 'through', |
||
| 149 | $this->resolveTarget($registry, $through) |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | if ($r->getOptions()->has('throughInnerKey')) { |
||
| 155 | if ($throughInnerKey = (array)$r->getOptions()->get('throughInnerKey')) { |
||
| 156 | $r->getOptions()->set('throughInnerKey', $throughInnerKey[0]); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($r->getOptions()->has('throughOuterKey')) { |
||
| 161 | if ($throughOuterKey = (array)$r->getOptions()->get('throughOuterKey')) { |
||
| 162 | $r->getOptions()->set('throughOuterKey', $throughOuterKey[0]); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } catch (RegistryException $ex) { |
||
| 166 | throw new RelationException( |
||
| 167 | sprintf( |
||
| 168 | 'Unable to resolve `%s`.`%s` relation target (not found or invalid)', |
||
| 169 | $e->getRole(), |
||
| 170 | $name |
||
| 171 | ), |
||
| 172 | $ex->getCode(), |
||
| 173 | $ex |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | return $registry; |
||
| 180 | } |
||
| 267 |