| Conditions | 13 |
| Paths | 108 |
| Total Lines | 59 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 70 | protected function toSVG(){ |
||
| 71 | $length = ($this->moduleCount + ($this->options->addQuietzone ? 8 : 0)) * $this->options->scale; |
||
| 72 | |||
| 73 | // svg header |
||
| 74 | $svg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="'.$length.'" height="'.$length.'" viewBox="0 0 '.$length.' '.$length.'">'.$this->options->eol. |
||
| 75 | '<defs><style>rect{shape-rendering:crispEdges}</style></defs>'.$this->options->eol; |
||
| 76 | |||
| 77 | // @todo: optimize -> see https://github.com/alexeyten/qr-image/blob/master/lib/vector.js |
||
| 78 | foreach($this->options->moduleValues as $key => $value){ |
||
| 79 | |||
| 80 | // fallback |
||
| 81 | if(is_bool($value)){ |
||
| 82 | $value = $value ? '#000' : '#fff'; |
||
| 83 | } |
||
| 84 | |||
| 85 | // svg body |
||
| 86 | foreach($this->matrix->matrix() as $y => $row){ |
||
| 87 | //we'll combine active blocks within a single row as a lightweight compression technique |
||
| 88 | $from = -1; |
||
| 89 | $count = 0; |
||
| 90 | |||
| 91 | foreach($row as $x => $pixel){ |
||
| 92 | if($pixel === $key){ |
||
| 93 | $count++; |
||
| 94 | |||
| 95 | if($from < 0){ |
||
| 96 | $from = $x; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | elseif($from >= 0){ |
||
| 100 | $svg .= '<rect x="'.($from * $this->options->scale).'" y="'.($y * $this->options->scale) |
||
| 101 | .'" width="'.($this->options->scale * $count).'" height="'.$this->options->scale.'" fill="'.$value.'"' |
||
| 102 | .(trim($this->options->cssClass) !== '' ? ' class="'.$this->options->cssClass.'"' :'').' />' |
||
| 103 | .$this->options->eol; |
||
| 104 | |||
| 105 | // reset count |
||
| 106 | $from = -1; |
||
| 107 | $count = 0; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | // close off the row, if applicable |
||
| 112 | if($from >= 0){ |
||
| 113 | $svg .= '<rect x="'.($from * $this->options->scale).'" y="'.($y * $this->options->scale) |
||
| 114 | .'" width="'.($this->options->scale * $count).'" height="'.$this->options->scale.'" class="'.$this->options->cssClass.'" fill="'.$value.'" />'.$this->options->eol; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | // close svg |
||
| 120 | $svg .= '</svg>'.$this->options->eol; |
||
| 121 | |||
| 122 | // if saving to file, append the correct headers |
||
| 123 | if($this->options->cachefile){ |
||
| 124 | 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; |
||
| 125 | } |
||
| 126 | |||
| 127 | return $svg; |
||
| 128 | } |
||
| 129 | |||
| 131 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.