| Conditions | 10 |
| Paths | 30 |
| Total Lines | 47 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 104 | public function dump(string $file = null){ |
||
| 105 | |||
| 106 | $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]); |
||
| 107 | $fpdf->AddPage(); |
||
| 108 | |||
| 109 | if($this::moduleValueIsValid($this->options->bgColor)){ |
||
| 110 | $bgColor = $this->prepareModuleValue($this->options->bgColor); |
||
| 111 | /** @phan-suppress-next-line PhanParamTooFewUnpack */ |
||
| 112 | $fpdf->SetFillColor(...$bgColor); |
||
|
|
|||
| 113 | $fpdf->Rect(0, 0, $this->length, $this->length, 'F'); |
||
| 114 | } |
||
| 115 | |||
| 116 | $prevColor = null; |
||
| 117 | |||
| 118 | for($y = 0; $y < $this->moduleCount; $y++){ |
||
| 119 | for($x = 0; $x < $this->moduleCount; $x++){ |
||
| 120 | |||
| 121 | if(!$this->options->drawLightModules && !$this->matrix->check($x, $y)){ |
||
| 122 | continue; |
||
| 123 | } |
||
| 124 | |||
| 125 | $color = $this->getModuleValueAt($x, $y); |
||
| 126 | |||
| 127 | if($color !== null && $color !== $prevColor){ |
||
| 128 | /** @phan-suppress-next-line PhanParamTooFewUnpack */ |
||
| 129 | $fpdf->SetFillColor(...$color); |
||
| 130 | $prevColor = $color; |
||
| 131 | } |
||
| 132 | |||
| 133 | $fpdf->Rect(($x * $this->scale), ($y * $this->scale), $this->scale, $this->scale, 'F'); |
||
| 134 | } |
||
| 135 | |||
| 136 | } |
||
| 137 | |||
| 138 | if($this->options->returnResource){ |
||
| 139 | return $fpdf; |
||
| 140 | } |
||
| 141 | |||
| 142 | $pdfData = $fpdf->Output('S'); |
||
| 143 | |||
| 144 | $this->saveToFile($pdfData, $file); |
||
| 145 | |||
| 146 | if($this->options->imageBase64){ |
||
| 147 | $pdfData = $this->toBase64DataURI($pdfData, 'application/pdf'); |
||
| 148 | } |
||
| 149 | |||
| 150 | return $pdfData; |
||
| 151 | } |
||
| 154 |