| Conditions | 13 |
| Paths | 66 |
| Total Lines | 43 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 68 | protected function uploadStep2(ResponseInterface $response, \SplFileObject $file, callable $on_progress = null) |
||
|
|
|||
| 69 | { |
||
| 70 | $info = $response->getContent(); |
||
| 71 | $canceled = false; |
||
| 72 | while ($info->processing_info->state === 'pending' || $info->processing_info->state === 'in_progress') { |
||
| 73 | $percent = isset($info->processing_info->progress_percent) |
||
| 74 | ? $info->processing_info->progress_percent |
||
| 75 | : null |
||
| 76 | ; |
||
| 77 | if ($on_progress && (new \ReflectionFunction($on_progress))->isGenerator()) { |
||
| 78 | Co::async(function () use ($on_progress, $percent, $response, &$canceled) { |
||
| 79 | if (false === (yield $on_progress($percent, $response))) { |
||
| 80 | $canceled = true; |
||
| 81 | } |
||
| 82 | }); |
||
| 83 | } elseif ($on_progress) { |
||
| 84 | if (false === $on_progress($percent, $response)) { |
||
| 85 | yield Co::RETURN_WITH => $info; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | if ($canceled) yield Co::RETURN_WITH => $info; |
||
| 89 | yield Co::DELAY => $info->processing_info->check_after_secs; |
||
| 90 | if ($canceled) yield Co::RETURN_WITH => $info; |
||
| 91 | $response = (yield $this->getAsync('media/upload', [ |
||
| 92 | 'command' => 'STATUS', |
||
| 93 | 'media_id' => $info->media_id_string, |
||
| 94 | ], true)); |
||
| 95 | $info = $response->getContent(); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($info->processing_info->state === 'failed') { |
||
| 99 | throw new HttpException( |
||
| 100 | isset($info->processing_info->error->message) |
||
| 101 | ? $info->processing_info->error->message |
||
| 102 | : $info->processing_info->error->name, |
||
| 103 | $info->processing_info->error->code, |
||
| 104 | $response->getHandle(), |
||
| 105 | $response |
||
| 106 | ); |
||
| 107 | } |
||
| 108 | |||
| 109 | yield Co::RETURN_WITH => $info; |
||
| 110 | } |
||
| 111 | |||
| 127 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.