| Conditions | 15 |
| Paths | 72 |
| Total Lines | 40 |
| 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 |
||
| 47 | public function post($print_response = true) |
||
| 48 | { |
||
| 49 | $upload = isset($_FILES[$this->options['param_name']]) ? |
||
| 50 | $_FILES[$this->options['param_name']] : null; |
||
| 51 | if ($upload && is_array($upload['tmp_name'])) { |
||
| 52 | foreach ($upload['tmp_name'] as $index => $value) { |
||
| 53 | $this->fileTypeExecutable($upload['tmp_name'][$index]); |
||
| 54 | } |
||
| 55 | } else { |
||
| 56 | $this->fileTypeExecutable($upload['tmp_name']); |
||
| 57 | } |
||
| 58 | |||
| 59 | $result = parent::post($print_response); |
||
| 60 | |||
| 61 | if ($this->canDo()) { |
||
| 62 | $can = true; |
||
| 63 | list($userData, $uploader) = array_values($this->clientOptions); |
||
| 64 | /** @var UploaderInterface $inst */ |
||
| 65 | $uploader = new $uploader(); |
||
| 66 | if (false === is_a($uploader, UploaderInterface::class)) { |
||
| 67 | throw new Exception('Uploader class must be instanceof UploaderInterface', 500); |
||
| 68 | } |
||
| 69 | if (true === $can && true === is_a($uploader, AccessUploadInterface::class)) { |
||
| 70 | $can = $uploader->can($userData); |
||
| 71 | } |
||
| 72 | if (true === $can && true === is_a($uploader, EventsUploaderInterface::class)) { |
||
| 73 | $can = $uploader->beforeUploading($userData); |
||
| 74 | } |
||
| 75 | if (true === $can) { |
||
| 76 | foreach ($result[$this->options['param_name']] as $i => $fileData) { |
||
| 77 | $result[$this->options['param_name']][$i] = $this->onFileUpload($uploader, $fileData, $userData); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | if (true === $can && true === is_a($uploader, EventsUploaderInterface::class)) { |
||
| 81 | $uploader->afterUploading($userData, $result[$this->options['param_name']]); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return $this->generate_response($result, $print_response); |
||
| 86 | } |
||
| 87 | |||
| 193 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.