Conditions | 11 |
Paths | 39 |
Total Lines | 72 |
Code Lines | 42 |
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 |
||
53 | public function encodeMask(QRinput $input, $mask) |
||
54 | { |
||
55 | if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
||
56 | throw new Exception('wrong version'); |
||
57 | } |
||
58 | if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
||
59 | throw new Exception('wrong level'); |
||
60 | } |
||
61 | |||
62 | $raw = new QRrawcode($input); |
||
63 | |||
64 | QRtools::markTime('after_raw'); |
||
65 | |||
66 | $version = $raw->version; |
||
67 | $width = QRspec::getWidth($version); |
||
68 | $frame = QRspec::newFrame($version); |
||
69 | |||
70 | $filler = new FrameFiller($width, $frame); |
||
71 | if(is_null($filler)) { |
||
72 | return NULL; |
||
73 | } |
||
74 | |||
75 | // inteleaved data and ecc codes |
||
76 | for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
||
77 | $code = $raw->getCode(); |
||
78 | $bit = 0x80; |
||
79 | for($j=0; $j<8; $j++) { |
||
80 | $addr = $filler->next(); |
||
81 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
||
82 | $bit = $bit >> 1; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | QRtools::markTime('after_filler'); |
||
87 | |||
88 | unset($raw); |
||
89 | |||
90 | // remainder bits |
||
91 | $j = QRspec::getRemainder($version); |
||
92 | for($i=0; $i<$j; $i++) { |
||
93 | $addr = $filler->next(); |
||
94 | $filler->setFrameAt($addr, 0x02); |
||
95 | } |
||
96 | |||
97 | $frame = $filler->frame; |
||
98 | unset($filler); |
||
99 | |||
100 | |||
101 | // masking |
||
102 | $maskObj = new QRmask(); |
||
103 | if($mask < 0) { |
||
104 | |||
105 | if (QR_FIND_BEST_MASK) { |
||
106 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
||
107 | } else { |
||
108 | $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); |
||
109 | } |
||
110 | } else { |
||
111 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
||
112 | } |
||
113 | |||
114 | if($masked == NULL) { |
||
115 | return NULL; |
||
116 | } |
||
117 | |||
118 | QRtools::markTime('after_mask'); |
||
119 | |||
120 | $this->version = $version; |
||
121 | $this->width = $width; |
||
122 | $this->data = $masked; |
||
123 | |||
124 | return $this; |
||
125 | } |
||
194 | } |