| Conditions | 12 |
| Paths | 122 |
| Total Lines | 67 |
| Code Lines | 33 |
| 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 |
||
| 52 | protected function svg(){ |
||
| 53 | $scale = $this->options->scale; |
||
| 54 | $length = $this->moduleCount * $scale; |
||
| 55 | $matrix = $this->matrix->matrix(); |
||
| 56 | |||
| 57 | $svg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'.$length.'px" height="'.$length.'px">' |
||
| 58 | .$this->options->eol |
||
| 59 | .'<defs>'.$this->options->svgDefs.'</defs>' |
||
| 60 | .$this->options->eol; |
||
| 61 | |||
| 62 | foreach($this->options->moduleValues as $M_TYPE => $value){ |
||
| 63 | |||
| 64 | // fallback |
||
| 65 | if(is_bool($value)){ |
||
| 66 | $value = $value ? '#000' : '#fff'; |
||
| 67 | } |
||
| 68 | |||
| 69 | $path = ''; |
||
| 70 | |||
| 71 | foreach($matrix as $y => $row){ |
||
| 72 | //we'll combine active blocks within a single row as a lightweight compression technique |
||
| 73 | $start = null; |
||
| 74 | $count = 0; |
||
| 75 | |||
| 76 | foreach($row as $x => $module){ |
||
| 77 | |||
| 78 | if($module === $M_TYPE){ |
||
| 79 | $count++; |
||
| 80 | |||
| 81 | if($start === null){ |
||
| 82 | $start = $x * $scale; |
||
| 83 | } |
||
| 84 | |||
| 85 | if($row[$x + 1] ?? false){ |
||
| 86 | continue; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if($count > 0){ |
||
| 91 | $len = $count * $scale; |
||
| 92 | $path .= 'M' .$start. ' ' .($y * $scale). ' h'.$len.' v'.$scale.' h-'.$len.'Z '; |
||
| 93 | |||
| 94 | // reset count |
||
| 95 | $count = 0; |
||
| 96 | $start = null; |
||
| 97 | } |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 101 | } |
||
| 102 | |||
| 103 | if(!empty($path)){ |
||
| 104 | $svg .= '<path class="qr-'.$M_TYPE.' '.$this->options->cssClass.'" stroke="transparent" fill="'.$value.'" fill-opacity="'.$this->options->svgOpacity.'" d="'.$path.'" />'; |
||
| 105 | } |
||
| 106 | |||
| 107 | } |
||
| 108 | |||
| 109 | // close svg |
||
| 110 | $svg .= '</svg>'.$this->options->eol; |
||
| 111 | |||
| 112 | // if saving to file, append the correct headers |
||
| 113 | if($this->options->cachefile){ |
||
| 114 | 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; |
||
| 115 | } |
||
| 116 | |||
| 117 | return $svg; |
||
| 118 | } |
||
| 119 | |||
| 121 |