| Conditions | 14 |
| Paths | 240 |
| Total Lines | 70 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 100 | public function dump(string $file = null){ |
||
| 101 | |||
| 102 | /** @phan-suppress-next-line PhanTypeMismatchArgumentInternal */ |
||
| 103 | set_error_handler(function(int $severity, string $msg, string $file, int $line):void{ |
||
| 104 | throw new ErrorException($msg, 0, $severity, $file, $line); |
||
| 105 | }); |
||
| 106 | |||
| 107 | $file ??= $this->options->cachefile; |
||
| 108 | |||
| 109 | // we're scaling the image up in order to draw crisp round circles, otherwise they appear square-y on small scales |
||
| 110 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
| 111 | $this->length = ($this->length + 2) * 10; |
||
| 112 | $this->scale *= 10; |
||
| 113 | } |
||
| 114 | |||
| 115 | $this->image = imagecreatetruecolor($this->length, $this->length); |
||
| 116 | |||
| 117 | // avoid: "Indirect modification of overloaded property $x has no effect" |
||
| 118 | // https://stackoverflow.com/a/10455217 |
||
| 119 | $bgColor = $this->options->imageTransparencyBG; |
||
| 120 | |||
| 121 | if($this->moduleValueIsValid($this->options->bgColor)){ |
||
| 122 | $bgColor = $this->getModuleValue($this->options->bgColor); |
||
| 123 | } |
||
| 124 | |||
| 125 | /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ |
||
| 126 | $background = imagecolorallocate($this->image, ...$bgColor); |
||
|
|
|||
| 127 | |||
| 128 | if( |
||
| 129 | $this->options->imageTransparent |
||
| 130 | && $this->options->outputType !== QROutputInterface::GDIMAGE_JPG |
||
| 131 | && $this->moduleValueIsValid($this->options->imageTransparencyBG) |
||
| 132 | ){ |
||
| 133 | $tbg = $this->getModuleValue($this->options->imageTransparencyBG); |
||
| 134 | /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ |
||
| 135 | imagecolortransparent($this->image, imagecolorallocate($this->image, ...$tbg)); |
||
| 136 | } |
||
| 137 | |||
| 138 | imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); |
||
| 139 | |||
| 140 | foreach($this->matrix->matrix() as $y => $row){ |
||
| 141 | foreach($row as $x => $M_TYPE){ |
||
| 142 | $this->setPixel($x, $y, $M_TYPE); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | // scale down to the expected size |
||
| 147 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
| 148 | $this->image = imagescale($this->image, $this->length/10, $this->length/10, IMG_BILINEAR_FIXED); |
||
| 149 | } |
||
| 150 | |||
| 151 | if($this->options->returnResource){ |
||
| 152 | restore_error_handler(); |
||
| 153 | |||
| 154 | return $this->image; |
||
| 155 | } |
||
| 156 | |||
| 157 | $imageData = $this->dumpImage(); |
||
| 158 | |||
| 159 | if($file !== null){ |
||
| 160 | $this->saveToFile($imageData, $file); |
||
| 161 | } |
||
| 162 | |||
| 163 | if($this->options->imageBase64){ |
||
| 164 | $imageData = $this->toBase64DataURI($imageData, 'image/'.$this->options->outputType); |
||
| 165 | } |
||
| 166 | |||
| 167 | restore_error_handler(); |
||
| 168 | |||
| 169 | return $imageData; |
||
| 170 | } |
||
| 238 |
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.