| Conditions | 5 |
| Paths | 8 |
| Total Lines | 77 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 51 | private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) |
||
| 52 | { |
||
| 53 | $h = count($frame); |
||
| 54 | $w = strlen($frame[0]); |
||
| 55 | |||
| 56 | $imgW = $w + 2 * $outerFrame; |
||
| 57 | $imgH = $h + 2 * $outerFrame; |
||
| 58 | |||
| 59 | if ($cmyk) { |
||
| 60 | // convert color value into decimal eps format |
||
| 61 | $c = round((($fore_color & 0xFF000000) >> 16) / 255, 5); |
||
| 62 | $m = round((($fore_color & 0x00FF0000) >> 16) / 255, 5); |
||
| 63 | $y = round((($fore_color & 0x0000FF00) >> 8) / 255, 5); |
||
| 64 | $k = round(($fore_color & 0x000000FF) / 255, 5); |
||
| 65 | $fore_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; |
||
| 66 | |||
| 67 | // convert color value into decimal eps format |
||
| 68 | $c = round((($back_color & 0xFF000000) >> 16) / 255, 5); |
||
| 69 | $m = round((($back_color & 0x00FF0000) >> 16) / 255, 5); |
||
| 70 | $y = round((($back_color & 0x0000FF00) >> 8) / 255, 5); |
||
| 71 | $k = round(($back_color & 0x000000FF) / 255, 5); |
||
| 72 | $back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; |
||
| 73 | } else { |
||
| 74 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
||
| 75 | $r = round((($fore_color & 0xFF0000) >> 16) / 255, 5); |
||
| 76 | $b = round((($fore_color & 0x00FF00) >> 8) / 255, 5); |
||
| 77 | $g = round(($fore_color & 0x0000FF) / 255, 5); |
||
| 78 | $fore_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n"; |
||
| 79 | |||
| 80 | // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) |
||
| 81 | $r = round((($back_color & 0xFF0000) >> 16) / 255, 5); |
||
| 82 | $b = round((($back_color & 0x00FF00) >> 8) / 255, 5); |
||
| 83 | $g = round(($back_color & 0x0000FF) / 255, 5); |
||
| 84 | $back_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n"; |
||
| 85 | } |
||
| 86 | |||
| 87 | $output = |
||
| 88 | '%!PS-Adobe EPSF-3.0'."\n". |
||
| 89 | '%%Creator: PHPQrcodeLib'."\n". |
||
| 90 | '%%Title: QRcode'."\n". |
||
| 91 | '%%CreationDate: '.date('Y-m-d')."\n". |
||
| 92 | '%%DocumentData: Clean7Bit'."\n". |
||
| 93 | '%%LanguageLevel: 2'."\n". |
||
| 94 | '%%Pages: 1'."\n". |
||
| 95 | '%%BoundingBox: 0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint."\n"; |
||
| 96 | |||
| 97 | // set the scale |
||
| 98 | $output .= $pixelPerPoint.' '.$pixelPerPoint.' scale'."\n"; |
||
| 99 | // position the center of the coordinate system |
||
| 100 | |||
| 101 | $output .= $outerFrame.' '.$outerFrame.' translate'."\n"; |
||
| 102 | |||
| 103 | // redefine the 'rectfill' operator to shorten the syntax |
||
| 104 | $output .= '/F { rectfill } def'."\n"; |
||
| 105 | |||
| 106 | // set the symbol color |
||
| 107 | $output .= $back_color_string; |
||
| 108 | $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2 * $outerFrame).' '.($h + 2 * $outerFrame).' F'."\n"; |
||
| 109 | |||
| 110 | // set the symbol color |
||
| 111 | $output .= $fore_color_string; |
||
| 112 | |||
| 113 | // Convert the matrix into pixels |
||
| 114 | |||
| 115 | for ($i = 0; $i < $h; $i++) { |
||
| 116 | for ($j = 0; $j < $w; $j++) { |
||
| 117 | if ($frame[$i][$j] == '1') { |
||
| 118 | $y = $h - 1 - $i; |
||
| 119 | $x = $j; |
||
| 120 | $output .= $x.' '.$y.' 1 1 F'."\n"; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $output .= '%%EOF'; |
||
| 126 | |||
| 127 | return $output; |
||
| 128 | } |
||
| 201 |