| Conditions | 10 |
| Paths | 42 |
| Total Lines | 58 |
| Code Lines | 28 |
| 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 |
||
| 80 | protected function svg():string{ |
||
| 81 | $matrix = $this->matrix->matrix(); |
||
| 82 | |||
| 83 | $svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) |
||
| 84 | .$this->options->eol |
||
| 85 | .'<defs>'.$this->options->svgDefs.'</defs>' |
||
| 86 | .$this->options->eol; |
||
| 87 | |||
| 88 | foreach($this->moduleValues as $M_TYPE => $value){ |
||
| 89 | $path = ''; |
||
| 90 | |||
| 91 | foreach($matrix as $y => $row){ |
||
| 92 | //we'll combine active blocks within a single row as a lightweight compression technique |
||
| 93 | $start = null; |
||
| 94 | $count = 0; |
||
| 95 | |||
| 96 | foreach($row as $x => $module){ |
||
| 97 | |||
| 98 | if($module === $M_TYPE){ |
||
| 99 | $count++; |
||
| 100 | |||
| 101 | if($start === null){ |
||
| 102 | $start = $x; |
||
| 103 | } |
||
| 104 | |||
| 105 | if(isset($row[$x + 1])){ |
||
| 106 | continue; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | if($count > 0){ |
||
| 111 | $len = $count; |
||
| 112 | $path .= sprintf('M%s %s h%s v1 h-%sZ ', $start, $y, $len, $len); |
||
| 113 | |||
| 114 | // reset count |
||
| 115 | $count = 0; |
||
| 116 | $start = null; |
||
| 117 | } |
||
| 118 | |||
| 119 | } |
||
| 120 | |||
| 121 | } |
||
| 122 | |||
| 123 | if(!empty($path)){ |
||
| 124 | $svg .= sprintf('<path class="qr-%s %s" stroke="transparent" fill="%s" fill-opacity="%s" d="%s" />', $M_TYPE, $this->options->cssClass, $value, $this->options->svgOpacity, $path); |
||
| 125 | } |
||
| 126 | |||
| 127 | } |
||
| 128 | |||
| 129 | // close svg |
||
| 130 | $svg .= '</svg>'.$this->options->eol; |
||
| 131 | |||
| 132 | // if saving to file, append the correct headers |
||
| 133 | if($this->options->cachefile){ |
||
| 134 | return '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'.$this->options->eol.$svg; |
||
| 135 | } |
||
| 136 | |||
| 137 | return $svg; |
||
| 138 | } |
||
| 141 |