Conditions | 9 |
Paths | 32 |
Total Lines | 65 |
Code Lines | 41 |
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 |
||
73 | protected function barcode_i25($code, $checksum = FALSE) |
||
74 | { |
||
75 | $chr['0'] = '11221'; |
||
76 | $chr['1'] = '21112'; |
||
77 | $chr['2'] = '12112'; |
||
78 | $chr['3'] = '22111'; |
||
79 | $chr['4'] = '11212'; |
||
80 | $chr['5'] = '21211'; |
||
81 | $chr['6'] = '12211'; |
||
82 | $chr['7'] = '11122'; |
||
83 | $chr['8'] = '21121'; |
||
84 | $chr['9'] = '12121'; |
||
85 | $chr['A'] = '11'; |
||
86 | $chr['Z'] = '21'; |
||
87 | if ($checksum) |
||
88 | { |
||
89 | // add checksum |
||
90 | $code .= $this->checksum_s25($code); |
||
91 | } |
||
92 | if ((strlen($code) % 2) != 0) |
||
93 | { |
||
94 | // add leading zero if code-length is odd |
||
95 | $code = '0' . $code; |
||
96 | } |
||
97 | // add start and stop codes |
||
98 | $code = 'AA' . strtolower($code) . 'ZA'; |
||
99 | |||
100 | $bararray = ['code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => []]; |
||
101 | $k = 0; |
||
102 | $clen = strlen($code); |
||
103 | for ($i = 0; $i < $clen; $i = ($i + 2)) |
||
104 | { |
||
105 | $char_bar = $code{$i}; |
||
106 | $char_space = $code{$i + 1}; |
||
107 | if ((!isset($chr[ $char_bar ])) OR (!isset($chr[ $char_space ]))) |
||
108 | { |
||
109 | // invalid character |
||
110 | return FALSE; |
||
111 | } |
||
112 | // create a bar-space sequence |
||
113 | $seq = ''; |
||
114 | $chrlen = strlen($chr[ $char_bar ]); |
||
115 | for ($s = 0; $s < $chrlen; $s++) |
||
116 | { |
||
117 | $seq .= $chr[ $char_bar ]{$s} . $chr[ $char_space ]{$s}; |
||
118 | } |
||
119 | $seqlen = strlen($seq); |
||
120 | for ($j = 0; $j < $seqlen; ++$j) |
||
121 | { |
||
122 | if (($j % 2) == 0) |
||
123 | { |
||
124 | $t = TRUE; // bar |
||
125 | } else |
||
126 | { |
||
127 | $t = FALSE; // space |
||
128 | } |
||
129 | $w = $seq{$j}; |
||
130 | $bararray['bcode'][ $k ] = ['t' => $t, 'w' => $w, 'h' => 1, 'p' => 0]; |
||
131 | $bararray['maxw'] += $w; |
||
132 | ++$k; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | return $bararray; |
||
137 | } |
||
138 | /** |
||
188 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.