Conditions | 13 |
Paths | 73 |
Total Lines | 60 |
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 |
||
41 | public function parse($name, array $existing = []) |
||
42 | { |
||
43 | if (in_array($name, $this->stack)) { |
||
44 | throw new \RuntimeException(sprintf('Recursion detected when parsing %s -> %s', implode(' -> ', $this->stack), $name)); |
||
45 | } |
||
46 | $this->stack[] = $name; |
||
47 | |||
48 | $value = $this->getValue($name); |
||
49 | |||
50 | if (!array_key_exists('types', $value)) { |
||
51 | $value['types'] = []; |
||
52 | } |
||
53 | |||
54 | if (array_key_exists('extends', $value)) { |
||
55 | $namespace = ''; |
||
56 | if (false !== strpos($name, ':')) { |
||
57 | $namespace = substr($name, 0, strpos($name, ':') + 1); |
||
58 | } |
||
59 | |||
60 | foreach ((array) $value['extends'] as $extend) { |
||
61 | if (false === strpos($extend, ':')) { |
||
62 | $extend = $namespace . $extend; |
||
63 | } |
||
64 | |||
65 | if (false === isset($existing[$extend])) { |
||
66 | $existing[$extend] = $this->parse($extend, $existing); |
||
67 | } |
||
68 | |||
69 | $value['types'] = array_merge($existing[$extend]->getPossiblePagePartTypes(), $value['types']); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | $types = []; |
||
74 | foreach ($value['types'] as $type) { |
||
75 | if ('' === (string) $type['class']) { |
||
76 | unset($types[$type['name']]); |
||
77 | |||
78 | continue; |
||
79 | } |
||
80 | |||
81 | $types[$type['name']] = ['name' => $type['name'], 'class' => $type['class'], 'preview' => array_key_exists('preview', $type) ? $type['preview'] : '']; |
||
82 | if (isset($type['pagelimit'])) { |
||
83 | $types[$type['name']]['pagelimit'] = $type['pagelimit']; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | $result = new PagePartAdminConfigurator(); |
||
88 | $result->setName($value['name']); |
||
89 | $result->setInternalName($name); |
||
90 | $result->setPossiblePagePartTypes(array_values($types)); |
||
91 | $result->setContext($value['context']); |
||
92 | |||
93 | if (isset($value['widget_template'])) { |
||
94 | $result->setWidgetTemplate($value['widget_template']); |
||
95 | } |
||
96 | |||
97 | array_pop($this->stack); |
||
98 | |||
99 | return $result; |
||
100 | } |
||
101 | |||
121 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.