Conditions | 11 |
Paths | 63 |
Total Lines | 62 |
Code Lines | 30 |
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 |
||
87 | protected function svg():string{ |
||
88 | $matrix = $this->matrix->matrix(); |
||
89 | |||
90 | $svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) |
||
91 | .$this->options->eol |
||
92 | .'<defs>'.$this->options->svgDefs.'</defs>' |
||
93 | .$this->options->eol; |
||
94 | |||
95 | foreach($this->moduleValues as $M_TYPE => $value){ |
||
96 | $path = ''; |
||
97 | |||
98 | foreach($matrix as $y => $row){ |
||
99 | //we'll combine active blocks within a single row as a lightweight compression technique |
||
100 | $start = null; |
||
101 | $count = 0; |
||
102 | |||
103 | foreach($row as $x => $module){ |
||
104 | |||
105 | if($module === $M_TYPE){ |
||
106 | $count++; |
||
107 | |||
108 | if($start === null){ |
||
109 | $start = $x; |
||
110 | } |
||
111 | |||
112 | if(isset($row[$x + 1])){ |
||
113 | continue; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | if($count > 0){ |
||
118 | $len = $count; |
||
119 | $path .= sprintf('M%s %s h%s v1 h-%sZ ', $start, $y, $len, $len); |
||
120 | |||
121 | // reset count |
||
122 | $count = 0; |
||
123 | $start = null; |
||
124 | } |
||
125 | |||
126 | } |
||
127 | |||
128 | } |
||
129 | |||
130 | if(!empty($path)){ |
||
131 | $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); |
||
132 | } |
||
133 | |||
134 | } |
||
135 | |||
136 | // close svg |
||
137 | $svg .= '</svg>'.$this->options->eol; |
||
138 | |||
139 | // if saving to file, append the correct headers |
||
140 | if($this->options->cachefile){ |
||
141 | 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; |
||
142 | } |
||
143 | |||
144 | if($this->options->imageBase64){ |
||
145 | $svg = sprintf('data:image/svg+xml;base64,%s', base64_encode($svg)); |
||
146 | } |
||
147 | |||
148 | return $svg; |
||
149 | } |
||
152 |