| Conditions | 13 |
| Paths | 14 |
| Total Lines | 46 |
| Code Lines | 26 |
| 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 |
||
| 129 | public function getOwnerPage() |
||
| 130 | { |
||
| 131 | if ($this->OwnerClassName) { |
||
| 132 | $class = $this->OwnerClassName; |
||
| 133 | $instance = Injector::inst()->get($class); |
||
| 134 | if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) { |
||
| 135 | return null; |
||
| 136 | } |
||
| 137 | $elementalAreaRelations = $instance->getElementalRelations(); |
||
| 138 | |||
| 139 | foreach ($elementalAreaRelations as $eaRelationship) { |
||
| 140 | $areaID = $eaRelationship . 'ID'; |
||
| 141 | |||
| 142 | $currentStage = Versioned::get_stage() ?: Versioned::DRAFT; |
||
| 143 | $page = Versioned::get_by_stage($class, $currentStage)->filter($areaID, $this->ID); |
||
| 144 | |||
| 145 | |||
| 146 | if ($page && $page->exists()) { |
||
| 147 | return $page->first(); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | foreach ($this->supportedPageTypes() as $class) { |
||
| 153 | $instance = Injector::inst()->get($class); |
||
| 154 | if (!ClassInfo::hasMethod($instance, 'getElementalRelations')) { |
||
| 155 | return null; |
||
| 156 | } |
||
| 157 | $elementalAreaRelations = $instance->getElementalRelations(); |
||
| 158 | |||
| 159 | foreach ($elementalAreaRelations as $eaRelationship) { |
||
| 160 | $areaID = $eaRelationship . 'ID'; |
||
| 161 | $page = Versioned::get_by_stage($class, Versioned::DRAFT)->filter($areaID, $this->ID); |
||
| 162 | |||
| 163 | if ($page && $page->exists()) { |
||
| 164 | if ($this->OwnerClassName !== $class) { |
||
| 165 | $this->OwnerClassName = $class; |
||
| 166 | $this->write(); |
||
| 167 | } |
||
| 168 | |||
| 169 | return $page->first(); |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | return null; |
||
| 175 | } |
||
| 217 |