Conditions | 12 |
Paths | 12 |
Total Lines | 44 |
Code Lines | 26 |
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 |
||
113 | protected function createProcessor(array $options) |
||
114 | { |
||
115 | $r = new \ReflectionClass($this->getProcessorClass()); |
||
116 | $args = []; |
||
117 | |||
118 | $constructor= $r->getConstructor(); |
||
119 | if ( |
||
120 | null !== $constructor |
||
121 | && \is_array($constructorParams = $constructor->getParameters()) |
||
122 | ) { |
||
123 | foreach ($constructorParams as $parameter) { |
||
124 | $name = $parameter->getName(); |
||
125 | $value = null; |
||
126 | $default = null; |
||
127 | if ( |
||
128 | !$parameter->isDefaultValueAvailable() |
||
129 | && !isset($options[$name]) |
||
130 | ) { |
||
131 | break; |
||
132 | } |
||
133 | |||
134 | if ($parameter->isDefaultValueAvailable()) { |
||
135 | $default = $parameter->getDefaultValue(); |
||
136 | } |
||
137 | |||
138 | if (isset($options[$name])) { |
||
139 | $value = $options[$name]; |
||
140 | } |
||
141 | $args[] = null !== $value ? $value : $default; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $outputType = $this->getOutputType(); |
||
146 | $dir = $this->getTarget(); |
||
147 | |||
148 | if (static::OUTPUT_FILE === $outputType) { |
||
149 | $dir = \dirname($dir); |
||
150 | } |
||
151 | |||
152 | if (static::OUTPUT_CONSOLE !== $outputType && !is_dir($dir)) { |
||
153 | mkdir($dir, 0775, true); |
||
154 | } |
||
155 | |||
156 | return $r->newInstanceArgs($args); |
||
157 | } |
||
159 |