| Conditions | 17 |
| Paths | 288 |
| Total Lines | 62 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | 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 |
||
| 90 | public function getRelations() |
||
| 91 | { |
||
| 92 | $classNames = array_keys($this->relations); |
||
| 93 | |||
| 94 | $associations = []; |
||
| 95 | |||
| 96 | foreach ($classNames as $class) { |
||
| 97 | $rawAssoc = $this->getRelationsByClass($class); |
||
| 98 | foreach ($rawAssoc as $raw) { |
||
| 99 | if (!in_array($raw, $associations)) { |
||
| 100 | $associations[] = $raw; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $unknowns = []; |
||
| 106 | foreach ($this->knownSides as $knownType => $knownDeets) { |
||
| 107 | $unknowns[$knownType] = []; |
||
| 108 | foreach (array_keys($knownDeets) as $key) { |
||
| 109 | $unknowns[$knownType][$key] = []; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | $monoAssoc = []; |
||
| 113 | $polyAssoc = []; |
||
| 114 | foreach ($associations as $assoc) { |
||
| 115 | if ($assoc->getFirst() instanceof AssociationStubMonomorphic) { |
||
| 116 | $monoAssoc[] = $assoc; |
||
| 117 | continue; |
||
| 118 | } |
||
| 119 | // monomorphic associations are dealt with, now for the polymorphic associations - they're a mite trickier |
||
| 120 | $firstKnown = $assoc->getFirst()->isKnownSide(); |
||
| 121 | $known = $firstKnown ? $assoc->getFirst() : $assoc->getLast(); |
||
| 122 | $unknown = $firstKnown ? $assoc->getLast() : $assoc->getFirst(); |
||
| 123 | $className = $known->getBaseType(); |
||
| 124 | $relName = $known->getRelationName(); |
||
| 125 | $unknowns[$className][$relName][] = $unknown; |
||
| 126 | } |
||
| 127 | |||
| 128 | foreach ($this->knownSides as $knownType => $knownDeets) { |
||
| 129 | foreach (array_keys($knownDeets) as $key) { |
||
| 130 | $lastCandidates = $unknowns[$knownType][$key]; |
||
| 131 | if (0 == count($lastCandidates)) { |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | foreach ($lastCandidates as $lc) { |
||
| 135 | $stub = clone $this->knownSides[$knownType][$key]; |
||
| 136 | $isMulti = ($stub->getMultiplicity()->getValue() == AssociationStubRelationType::MANY); |
||
| 137 | $relPolyTypeName = substr($lc->getBaseType(), strrpos($lc->getBaseType(), '\\')+1); |
||
| 138 | $relPolyTypeName = str_plural($relPolyTypeName, $isMulti?2:1); |
||
| 139 | $stub->setRelationName($stub->getRelationName() . '_' . $relPolyTypeName); |
||
| 140 | $assoc = new AssociationMonomorphic(); |
||
| 141 | $first = -1 === $stub->compare($lc); |
||
| 142 | $assoc->setFirst($first ? $stub : $lc); |
||
| 143 | $assoc->setLast($first ? $lc : $stub); |
||
| 144 | assert($assoc->isOk()); |
||
| 145 | $polyAssoc[] = $assoc; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | $result = array_merge($monoAssoc, $polyAssoc); |
||
| 150 | return $result; |
||
| 151 | } |
||
| 152 | |||
| 169 |