Conditions | 9 |
Paths | 32 |
Total Lines | 66 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
68 | protected function barcode_i25($code, $checksum = FALSE) |
||
69 | { |
||
70 | $chr = array(); |
||
71 | $chr['0'] = '11221'; |
||
72 | $chr['1'] = '21112'; |
||
73 | $chr['2'] = '12112'; |
||
74 | $chr['3'] = '22111'; |
||
75 | $chr['4'] = '11212'; |
||
76 | $chr['5'] = '21211'; |
||
77 | $chr['6'] = '12211'; |
||
78 | $chr['7'] = '11122'; |
||
79 | $chr['8'] = '21121'; |
||
80 | $chr['9'] = '12121'; |
||
81 | $chr['A'] = '11'; |
||
82 | $chr['Z'] = '21'; |
||
83 | if ($checksum) |
||
84 | { |
||
85 | // add checksum |
||
86 | $code .= $this->checksum_s25($code); |
||
87 | } |
||
88 | if ((strlen($code) % 2) != 0) |
||
89 | { |
||
90 | // add leading zero if code-length is odd |
||
91 | $code = '0' . $code; |
||
92 | } |
||
93 | // add start and stop codes |
||
94 | $code = 'AA' . strtolower($code) . 'ZA'; |
||
95 | |||
96 | $bararray = ['code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => []]; |
||
97 | $k = 0; |
||
98 | $clen = strlen($code); |
||
99 | for ($i = 0; $i < $clen; $i = ($i + 2)) |
||
100 | { |
||
101 | $char_bar = $code{$i}; |
||
102 | $char_space = $code{$i + 1}; |
||
103 | if ((!isset($chr[ $char_bar ])) || (!isset($chr[ $char_space ]))) |
||
104 | { |
||
105 | // invalid character |
||
106 | return FALSE; |
||
107 | } |
||
108 | // create a bar-space sequence |
||
109 | $seq = ''; |
||
110 | $chrlen = strlen($chr[ $char_bar ]); |
||
111 | for ($s = 0; $s < $chrlen; $s++) |
||
112 | { |
||
113 | $seq .= $chr[ $char_bar ]{$s} . $chr[ $char_space ]{$s}; |
||
114 | } |
||
115 | $seqlen = strlen($seq); |
||
116 | for ($j = 0; $j < $seqlen; ++$j) |
||
117 | { |
||
118 | if (($j % 2) == 0) |
||
119 | { |
||
120 | $t = TRUE; // bar |
||
121 | } else |
||
122 | { |
||
123 | $t = FALSE; // space |
||
124 | } |
||
125 | $w = $seq{$j}; |
||
126 | $bararray['bcode'][ $k ] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0]; |
||
127 | $bararray['maxw'] += $w; |
||
128 | ++$k; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | return $bararray; |
||
133 | } |
||
134 | |||
186 |