Conditions | 10 |
Paths | 4 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
33 | public function findOrMakeDefaultElements(): void |
||
34 | { |
||
35 | $owner = $this->getOwner(); |
||
36 | $write = false; |
||
37 | if ($owner->hasMethod('ElementalArea') && ! $owner->ElementalArea()->Elements()->exists()) { |
||
38 | foreach ( |
||
39 | array_keys([ |
||
40 | 'inherited' => null, |
||
41 | 'uninherited' => Config::UNINHERITED, |
||
42 | ]) |
||
43 | as $topVarNameAppendix |
||
44 | ) { |
||
45 | $className = $owner->ClassName; |
||
46 | $list = (array) array_filter($className::config()->get('elemental_template_' . $topVarNameAppendix, Config::UNINHERITED) ?: []); |
||
47 | foreach ($list as $areaName => $items) { |
||
48 | $area = $owner->{$areaName}(); |
||
49 | foreach (['_top', '', '_bottom'] as $innerVarNameAppendix) { |
||
50 | $elems = (array) array_filter($items['elements' . $innerVarNameAppendix] ?? []); |
||
51 | if (! empty($elems)) { |
||
52 | if ($this->findOrMakeDefaultElementsInner($area, $elems)) { |
||
53 | $write = true; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | |||
61 | if ($write) { |
||
62 | $owner->writeToStage(Versioned::DRAFT); |
||
63 | } |
||
85 |