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