Conditions | 10 |
Paths | 7 |
Total Lines | 34 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
14 | public function build($block, $field, $key) { |
||
15 | // does the Block assign any $_casts? This is key (field) => value (class) |
||
16 | if (array_key_exists($key, $block->getCasts())) { |
||
17 | $casts = $block->getCasts(); |
||
18 | return new $casts[$key]($field, $block); |
||
19 | } |
||
20 | |||
21 | // find Fields specific to this Block matching: BlockNameFieldName |
||
22 | if ($class = $block->getChildClassName('Field', $block->component() . '_' . $key)) { |
||
23 | return new $class($field, $block); |
||
24 | } |
||
25 | |||
26 | // auto-match Field classes |
||
27 | if ($class = $block->getChildClassName('Field', $key)) { |
||
28 | return new $class($field, $block); |
||
29 | } |
||
30 | |||
31 | // single item relations |
||
32 | if (Str::isUuid($field) && ($block->_autoResolveRelations || in_array($key, $block->_resolveRelations))) { |
||
33 | return $block->getRelation(new RequestStory(), $field); |
||
34 | } |
||
35 | |||
36 | // complex fields |
||
37 | if (is_array($field) && !empty($field)) { |
||
38 | return $this->arrayField($block, $field, $key); |
||
39 | } |
||
40 | |||
41 | // legacy image fields |
||
42 | if ($this->isLegacyImageField($field)) { |
||
43 | return new Image($field, $block); |
||
44 | } |
||
45 | |||
46 | // strings or anything else - do nothing |
||
47 | return $field; |
||
48 | } |
||
146 | } |