| Conditions | 38 |
| Paths | 88 |
| Total Lines | 89 |
| 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 |
||
| 161 | public function getPHPoole(array $options = []) |
||
| 162 | { |
||
| 163 | // debug mode? |
||
| 164 | if (array_key_exists('debug', $options) && $options['debug']) { |
||
| 165 | $this->debug = true; |
||
| 166 | } |
||
| 167 | // quiet mode? |
||
| 168 | if (array_key_exists('quiet', $options) && $options['quiet']) { |
||
| 169 | $this->quiet = true; |
||
| 170 | } |
||
| 171 | |||
| 172 | // CLI custom message callback function |
||
| 173 | $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0) { |
||
| 174 | switch ($code) { |
||
| 175 | case 'LOCATE': |
||
| 176 | case 'CREATE': |
||
| 177 | case 'CONVERT': |
||
| 178 | case 'GENERATE': |
||
| 179 | case 'MENU': |
||
| 180 | case 'COPY': |
||
| 181 | case 'RENDER': |
||
| 182 | $this->wlAnnonce($message); |
||
| 183 | break; |
||
| 184 | case 'TIME': |
||
| 185 | $this->wl($message); |
||
| 186 | break; |
||
| 187 | case 'LOCATE_PROGRESS': |
||
| 188 | case 'CREATE_PROGRESS': |
||
| 189 | case 'CONVERT_PROGRESS': |
||
| 190 | case 'GENERATE_PROGRESS': |
||
| 191 | case 'MENU_PROGRESS': |
||
| 192 | case 'COPY_PROGRESS': |
||
| 193 | case 'RENDER_PROGRESS': |
||
| 194 | if ($this->debug) { |
||
| 195 | if ($itemsCount > 0) { |
||
| 196 | $this->wlDone(sprintf('(%u/%u) %s', $itemsCount, $itemsMax, $message)); |
||
| 197 | break; |
||
| 198 | } |
||
| 199 | $this->wlDone("$message"); |
||
| 200 | } else { |
||
| 201 | if (!$this->quiet) { |
||
| 202 | if (isset($itemsCount) && $itemsMax > 0) { |
||
| 203 | $this->newPB(0, $itemsMax); |
||
| 204 | $this->getPB()->update($itemsCount, "$message"); |
||
| 205 | if ($itemsCount == $itemsMax) { |
||
| 206 | $this->getPB()->update($itemsCount, "[$itemsCount/$itemsMax]"); |
||
| 207 | $this->getPB()->finish(); |
||
| 208 | } |
||
| 209 | } else { |
||
| 210 | $this->wl($message); |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | break; |
||
| 215 | case 'LOCATE_ERROR': |
||
| 216 | case 'CREATE_ERROR': |
||
| 217 | case 'CONVERT_ERROR': |
||
| 218 | case 'GENERATE_ERROR': |
||
| 219 | case 'MENU_ERROR': |
||
| 220 | case 'COPY_ERROR': |
||
| 221 | case 'RENDER_ERROR': |
||
| 222 | $this->wlError($message); |
||
| 223 | break; |
||
| 224 | } |
||
| 225 | }; |
||
| 226 | |||
| 227 | // instanciate PHPoole? |
||
| 228 | if (!$this->phpoole instanceof PHPoole) { |
||
| 229 | if (!file_exists($this->getPath().'/'.self::CONFIG_FILE)) { |
||
| 230 | throw new \Exception(sprintf('Config file not found in "%s"!', $this->getPath())); |
||
| 231 | } |
||
| 232 | |||
| 233 | try { |
||
| 234 | $optionsFile = Yaml::parse(file_get_contents($this->getPath().'/'.self::CONFIG_FILE)); |
||
| 235 | if (is_array($options)) { |
||
| 236 | $options = array_replace_recursive($optionsFile, $options); |
||
| 237 | } |
||
| 238 | $this->phpoole = new PHPoole($options, $messageCallback); |
||
| 239 | $this->phpoole->setSourceDir($this->getPath()); |
||
| 240 | $this->phpoole->setDestinationDir($this->getPath()); |
||
| 241 | } catch (ParseException $e) { |
||
| 242 | throw new \Exception(sprintf('Config file parse error: %s', $e->getMessage())); |
||
| 243 | } catch (\Exception $e) { |
||
| 244 | throw new \Exception(sprintf($e->getMessage())); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | return $this->phpoole; |
||
| 249 | } |
||
| 250 | |||
| 291 |
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.