| Conditions | 12 |
| Paths | 120 |
| Total Lines | 59 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | 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 |
||
| 95 | public function dump(string $file = null){ |
||
| 96 | |||
| 97 | /** @phan-suppress-next-line PhanTypeMismatchArgumentInternal */ |
||
| 98 | set_error_handler(function(int $severity, string $msg, string $file, int $line):void{ |
||
| 99 | throw new ErrorException($msg, 0, $severity, $file, $line); |
||
| 100 | }); |
||
| 101 | |||
| 102 | $file ??= $this->options->cachefile; |
||
| 103 | |||
| 104 | // we're scaling the image up in order to draw crisp round circles, otherwise they appear square-y on small scales |
||
| 105 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
| 106 | $this->length = ($this->length + 2) * 10; |
||
| 107 | $this->scale *= 10; |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->image = imagecreatetruecolor($this->length, $this->length); |
||
| 111 | |||
| 112 | // avoid: "Indirect modification of overloaded property $imageTransparencyBG has no effect" |
||
| 113 | // https://stackoverflow.com/a/10455217 |
||
| 114 | $tbg = $this->options->imageTransparencyBG; |
||
| 115 | /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ |
||
| 116 | $background = imagecolorallocate($this->image, ...$tbg); |
||
|
|
|||
| 117 | |||
| 118 | if($this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ |
||
| 119 | imagecolortransparent($this->image, $background); |
||
| 120 | } |
||
| 121 | |||
| 122 | imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); |
||
| 123 | |||
| 124 | foreach($this->matrix->matrix() as $y => $row){ |
||
| 125 | foreach($row as $x => $M_TYPE){ |
||
| 126 | $this->setPixel($x, $y, $M_TYPE); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | // scale down to the expected size |
||
| 131 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
| 132 | $this->image = imagescale($this->image, $this->length/10, $this->length/10, IMG_BICUBIC); |
||
| 133 | } |
||
| 134 | |||
| 135 | if($this->options->returnResource){ |
||
| 136 | restore_error_handler(); |
||
| 137 | |||
| 138 | return $this->image; |
||
| 139 | } |
||
| 140 | |||
| 141 | $imageData = $this->dumpImage(); |
||
| 142 | |||
| 143 | if($file !== null){ |
||
| 144 | $this->saveToFile($imageData, $file); |
||
| 145 | } |
||
| 146 | |||
| 147 | if($this->options->imageBase64){ |
||
| 148 | $imageData = $this->base64encode($imageData, 'image/'.$this->options->outputType); |
||
| 149 | } |
||
| 150 | |||
| 151 | restore_error_handler(); |
||
| 152 | |||
| 153 | return $imageData; |
||
| 154 | } |
||
| 248 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.