Conditions | 12 |
Paths | 120 |
Total Lines | 59 |
Code Lines | 27 |
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 |
||
82 | public function dump(string $file = null){ |
||
83 | |||
84 | /** @phan-suppress-next-line PhanTypeMismatchArgumentInternal */ |
||
85 | set_error_handler(function(int $severity, string $msg, string $file, int $line):void{ |
||
86 | throw new ErrorException($msg, 0, $severity, $file, $line); |
||
87 | }); |
||
88 | |||
89 | $file ??= $this->options->cachefile; |
||
90 | |||
91 | // we're scaling the image up in order to draw crisp round circles, otherwise they appear square-y on small scales |
||
92 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
93 | $this->length = ($this->length + 2) * 10; |
||
94 | $this->scale *= 10; |
||
95 | } |
||
96 | |||
97 | $this->image = imagecreatetruecolor($this->length, $this->length); |
||
98 | |||
99 | // avoid: "Indirect modification of overloaded property $imageTransparencyBG has no effect" |
||
100 | // https://stackoverflow.com/a/10455217 |
||
101 | $tbg = $this->options->imageTransparencyBG; |
||
102 | /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ |
||
103 | $background = imagecolorallocate($this->image, ...$tbg); |
||
|
|||
104 | |||
105 | if($this->options->imageTransparent && $this->options->outputType !== QRCode::OUTPUT_IMAGE_JPG){ |
||
106 | imagecolortransparent($this->image, $background); |
||
107 | } |
||
108 | |||
109 | imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); |
||
110 | |||
111 | foreach($this->matrix->matrix() as $y => $row){ |
||
112 | foreach($row as $x => $M_TYPE){ |
||
113 | $this->setPixel($x, $y, $M_TYPE); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | // scale down to the expected size |
||
118 | if($this->options->drawCircularModules && $this->options->scale <= 20){ |
||
119 | $this->image = imagescale($this->image, $this->length/10, $this->length/10, IMG_BICUBIC); |
||
120 | } |
||
121 | |||
122 | if($this->options->returnResource){ |
||
123 | restore_error_handler(); |
||
124 | |||
125 | return $this->image; |
||
126 | } |
||
127 | |||
128 | $imageData = $this->dumpImage(); |
||
129 | |||
130 | if($file !== null){ |
||
131 | $this->saveToFile($imageData, $file); |
||
132 | } |
||
133 | |||
134 | if($this->options->imageBase64){ |
||
135 | $imageData = $this->base64encode($imageData, 'image/'.$this->options->outputType); |
||
136 | } |
||
137 | |||
138 | restore_error_handler(); |
||
139 | |||
140 | return $imageData; |
||
141 | } |
||
209 |
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.