Conditions | 11 |
Paths | 21 |
Total Lines | 39 |
Code Lines | 28 |
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 |
||
34 | public static function validate($data, $type) |
||
35 | { |
||
36 | if (!array_key_exists($type, self::$barcode1D)) { |
||
37 | return false; |
||
38 | } |
||
39 | $bcSpks = self::$barcode1D[$type]; |
||
40 | $len = $bcSpks['len']; |
||
41 | $oddeven = $bcSpks['oddeven']; |
||
42 | $regex = $bcSpks['regex']; |
||
43 | $code = $bcSpks['code']; |
||
44 | //apply rules over barcode data |
||
45 | if ($code == 'ASCII') { |
||
46 | $data = iconv('utf-8', 'us-ascii//TRANSLIT', $data); |
||
47 | } |
||
48 | if ($regex != '') { |
||
49 | $data = preg_replace($regex, '', $data); |
||
50 | } |
||
51 | $data = trim($data); |
||
52 | if (empty($data)) { |
||
53 | return false; |
||
54 | } |
||
55 | $dlen = strlen($data); |
||
56 | if (($oddeven == 'even' && $dlen % 2 != 0) |
||
57 | || ($oddeven == 'odd' && $dlen % 2 == 0) |
||
58 | ) { |
||
59 | return false; |
||
60 | } |
||
61 | $al = explode('-', $len); |
||
62 | if (count($al) > 1) { |
||
63 | if ($dlen < $al[0]) { |
||
64 | return false; |
||
65 | } |
||
66 | $alen = $al[1]; |
||
67 | } else { |
||
68 | $alen = $al[0]; |
||
69 | } |
||
70 | $data = substr($data, 0, $alen); |
||
71 | return $data; |
||
72 | } |
||
73 | } |
||
74 |