| Conditions | 19 |
| Paths | 22 |
| Total Lines | 49 |
| 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 |
||
| 142 | public function getPHPoole(array $options = []) |
||
| 143 | { |
||
| 144 | $messageCallback = function ($code, $message = '', $itemsCount = 0, $itemsMax = 0, $verbose = true) { |
||
| 145 | switch ($code) { |
||
| 146 | case 'CREATE': |
||
| 147 | case 'CONVERT': |
||
| 148 | case 'GENERATE': |
||
| 149 | case 'COPY': |
||
| 150 | case 'RENDER': |
||
| 151 | case 'TIME': |
||
| 152 | $this->wlAnnonce($message); |
||
| 153 | break; |
||
| 154 | case 'CREATE_PROGRESS': |
||
| 155 | case 'CONVERT_PROGRESS': |
||
| 156 | case 'GENERATE_PROGRESS': |
||
| 157 | case 'COPY_PROGRESS': |
||
| 158 | case 'RENDER_PROGRESS': |
||
| 159 | if ($itemsMax && $itemsCount) { |
||
| 160 | $this->newPB(1, $itemsMax); |
||
| 161 | $this->getPB()->update($itemsCount, "$message"); |
||
| 162 | } else { |
||
| 163 | $this->wl($message); |
||
| 164 | } |
||
| 165 | break; |
||
| 166 | } |
||
| 167 | }; |
||
| 168 | |||
| 169 | if (!$this->phpoole instanceof PHPoole) { |
||
| 170 | if (!file_exists($this->getPath().'/'.self::CONFIG_FILE)) { |
||
| 171 | throw new \Exception(sprintf('Config file not found in "%s"!', $this->getPath())); |
||
| 172 | } |
||
| 173 | |||
| 174 | try { |
||
| 175 | $optionsFile = Yaml::parse(file_get_contents($this->getPath().'/'.self::CONFIG_FILE)); |
||
| 176 | if (is_array($options)) { |
||
| 177 | $options = array_replace_recursive($optionsFile, $options); |
||
| 178 | } |
||
| 179 | $this->phpoole = new PHPoole($options, $messageCallback); |
||
| 180 | $this->phpoole->setSourceDir($this->getPath()); |
||
| 181 | $this->phpoole->setDestinationDir($this->getPath()); |
||
| 182 | } catch (ParseException $e) { |
||
| 183 | throw new \Exception(sprintf('Config file parse error: %s', $e->getMessage())); |
||
| 184 | } catch (\Exception $e) { |
||
| 185 | throw new \Exception(sprintf($e->getMessage())); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | return $this->phpoole; |
||
| 190 | } |
||
| 191 | |||
| 232 |
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.