| Conditions | 35 |
| Paths | 88 |
| Total Lines | 84 |
| 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 |
||
| 153 | public function getPHPoole(array $options = []) |
||
| 154 | { |
||
| 155 | // debug mode? |
||
| 156 | if (array_key_exists('debug', $options) && $options['debug']) { |
||
| 157 | $this->debug = true; |
||
| 158 | } |
||
| 159 | // quiet mode? |
||
| 160 | if (array_key_exists('quiet', $options) && $options['quiet']) { |
||
| 161 | $this->quiet = true; |
||
| 162 | } |
||
| 163 | |||
| 164 | // CLI custom message callback function |
||
| 165 | $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0) { |
||
| 166 | switch ($code) { |
||
| 167 | case 'CREATE': |
||
| 168 | case 'CONVERT': |
||
| 169 | case 'GENERATE': |
||
| 170 | case 'MENU': |
||
| 171 | case 'COPY': |
||
| 172 | case 'RENDER': |
||
| 173 | case 'TIME': |
||
| 174 | $this->wlAnnonce($message); |
||
| 175 | break; |
||
| 176 | case 'CREATE_PROGRESS': |
||
| 177 | case 'CONVERT_PROGRESS': |
||
| 178 | case 'GENERATE_PROGRESS': |
||
| 179 | case 'MENU_PROGRESS': |
||
| 180 | case 'COPY_PROGRESS': |
||
| 181 | case 'RENDER_PROGRESS': |
||
| 182 | if ($this->debug) { |
||
| 183 | if ($itemsCount > 0) { |
||
| 184 | $this->wlDone(sprintf("(%u/%u) %s", $itemsCount, $itemsMax, $message)); |
||
| 185 | break; |
||
| 186 | } |
||
| 187 | $this->wlDone("$message"); |
||
| 188 | } else { |
||
| 189 | if (!$this->quiet) { |
||
| 190 | if ($itemsMax && $itemsCount) { |
||
| 191 | $this->newPB(1, $itemsMax); |
||
| 192 | $this->getPB()->update($itemsCount, "$message"); |
||
| 193 | if ($itemsCount == $itemsMax) { |
||
| 194 | $this->getPB()->update($itemsCount, "[$itemsCount/$itemsMax]"); |
||
| 195 | $this->getPB()->finish(); |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | $this->wl($message); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | break; |
||
| 203 | case 'CREATE_ERROR': |
||
| 204 | case 'CONVERT_ERROR': |
||
| 205 | case 'GENERATE_ERROR': |
||
| 206 | case 'MENU_ERROR': |
||
| 207 | case 'COPY_ERROR': |
||
| 208 | case 'RENDER_ERROR': |
||
| 209 | $this->wlError($message); |
||
| 210 | break; |
||
| 211 | } |
||
| 212 | }; |
||
| 213 | |||
| 214 | // instanciate PHPoole? |
||
| 215 | if (!$this->phpoole instanceof PHPoole) { |
||
| 216 | if (!file_exists($this->getPath().'/'.self::CONFIG_FILE)) { |
||
| 217 | throw new \Exception(sprintf('Config file not found in "%s"!', $this->getPath())); |
||
| 218 | } |
||
| 219 | |||
| 220 | try { |
||
| 221 | $optionsFile = Yaml::parse(file_get_contents($this->getPath().'/'.self::CONFIG_FILE)); |
||
| 222 | if (is_array($options)) { |
||
| 223 | $options = array_replace_recursive($optionsFile, $options); |
||
| 224 | } |
||
| 225 | $this->phpoole = new PHPoole($options, $messageCallback); |
||
| 226 | $this->phpoole->setSourceDir($this->getPath()); |
||
| 227 | $this->phpoole->setDestinationDir($this->getPath()); |
||
| 228 | } catch (ParseException $e) { |
||
| 229 | throw new \Exception(sprintf('Config file parse error: %s', $e->getMessage())); |
||
| 230 | } catch (\Exception $e) { |
||
| 231 | throw new \Exception(sprintf($e->getMessage())); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | return $this->phpoole; |
||
| 236 | } |
||
| 237 | |||
| 278 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.