Conditions | 11 |
Paths | 9 |
Total Lines | 48 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
109 | public function createImporter(array $token, Supervisor $supervisor) |
||
110 | { |
||
111 | //Fetching path |
||
112 | $path = $this->resolvePath($token); |
||
113 | if (empty($attributes = $token[HtmlTokenizer::TOKEN_ATTRIBUTES])) { |
||
114 | throw new SyntaxException("Invalid import element syntax, attributes missing.", $token); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * <dark:use bundle="path-to-bundle"/> |
||
119 | */ |
||
120 | if (isset($attributes['bundle'])) { |
||
121 | $path = $attributes['bundle']; |
||
122 | |||
123 | return new Bundler($supervisor, $path, $token); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * <dark:use path="path-to-element" as="tag"/> |
||
128 | * <dark:use path="path-to-element" element="tag"/> |
||
129 | */ |
||
130 | if (isset($attributes['element']) || isset($attributes['as'])) { |
||
131 | $alias = isset($attributes['element']) ? $attributes['element'] : $attributes['as']; |
||
132 | |||
133 | return new Aliaser($alias, $path); |
||
134 | } |
||
135 | |||
136 | //Now we have to decide what importer to use |
||
137 | if (isset($attributes['namespace']) || isset($attributes['prefix'])) { |
||
138 | if (strpos($path, '*') === false) { |
||
139 | throw new SyntaxException( |
||
140 | "Path in namespace/prefix import must include start symbol.", $token |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | $prefix = isset($attributes['namespace']) |
||
145 | ? $attributes['namespace'] . ':' |
||
146 | : $attributes['prefix']; |
||
147 | |||
148 | return new Prefixer($prefix, $path); |
||
149 | } |
||
150 | |||
151 | if (isset($attributes['stop'])) { |
||
152 | return new Stopper($attributes['stop']); |
||
153 | } |
||
154 | |||
155 | throw new SyntaxException("Undefined use element.", $token); |
||
156 | } |
||
157 | |||
167 | } |