Conditions | 12 |
Paths | 4 |
Total Lines | 59 |
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 |
||
10 | public static function fetch($sections) |
||
11 | { |
||
12 | self::$deepness++; |
||
13 | $options = array(); |
||
14 | $sections = SectionManager::fetch($sections); |
||
15 | if (!empty($sections)) { |
||
16 | foreach ($sections as $section) { |
||
17 | $section_fields = $section->fetchFields(); |
||
18 | if(!is_array($section_fields)) { |
||
19 | continue; |
||
20 | } |
||
21 | |||
22 | $fields = array(); |
||
23 | foreach($section_fields as $f) { |
||
24 | $fd = General::intval($f->get('deepness')); |
||
25 | if ($fd > 0 && self::$deepness > $fd) { |
||
26 | continue; |
||
27 | } |
||
28 | if (in_array($f->get('id'), self::$seenFields)) { |
||
29 | continue; |
||
30 | } |
||
31 | self::$seenFields[] = $f->get('id'); |
||
32 | $modes = $f->fetchIncludableElements(); |
||
33 | |||
34 | if (is_array($modes)) { |
||
35 | // include default |
||
36 | $fields[] = array( |
||
37 | 'id' => $f->get('id'), |
||
38 | 'name' => $f->get('label'), |
||
39 | 'handle' => $f->get('element_name'), |
||
40 | 'type' => $f->get('type'), |
||
41 | 'default' => true, |
||
42 | ); |
||
43 | if (count($modes) > 1) { |
||
44 | foreach ($modes as $mode) { |
||
45 | $fields[] = array( |
||
46 | 'id' => $f->get('id'), |
||
47 | 'name' => $f->get('label'), |
||
48 | 'handle' => $mode, |
||
49 | 'type' => $f->get('type') |
||
50 | ); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $options[] = array( |
||
57 | 'name' => $section->get('name'), |
||
58 | 'handle' => $section->get('handle'), |
||
59 | 'fields' => $fields |
||
60 | ); |
||
61 | } |
||
62 | } |
||
63 | self::$deepness--; |
||
64 | if (self::$deepness === 0) { |
||
65 | self::$seenFields = array(); |
||
66 | } |
||
67 | return $options; |
||
68 | } |
||
69 | } |
||
70 |