Conditions | 10 |
Paths | 9 |
Total Lines | 32 |
Code Lines | 19 |
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 |
||
85 | private function check() |
||
86 | { |
||
87 | $partitaIva = $this->getPartitaIva(); |
||
88 | if ($partitaIva === "" || strlen($partitaIva) != 11 || (preg_match("/^[0-9]+\$/", $partitaIva) != 1)) { |
||
89 | $valid = false; |
||
90 | } else { |
||
91 | $s = 0; |
||
92 | for ($i = 0; $i <= 9; $i += 2) { |
||
93 | $s += ord($partitaIva[$i]) - ord("0"); |
||
94 | } |
||
95 | |||
96 | for ($i = 1; $i <= 9; $i += 2) { |
||
97 | $c = 2 * ( ord($partitaIva[$i]) - ord("0") ); |
||
98 | if ($c > 9) { |
||
99 | $c = $c - 9; |
||
100 | } |
||
101 | $s += $c; |
||
102 | } |
||
103 | |||
104 | if (((10 - $s%10)%10) !== (ord($partitaIva[10]) - ord("0"))) { |
||
105 | $valid = false; |
||
106 | } |
||
107 | |||
108 | if (!preg_match("/^0([0-9][1-9]|[1-9][0-9])|100|120|121|888|999/",substr($partitaIva,7,3))) { |
||
109 | $valid = false; |
||
110 | } |
||
111 | |||
112 | if (!isset($valid)) { |
||
113 | $valid = true; |
||
114 | } |
||
115 | } |
||
116 | $this->setIsValid($valid); |
||
117 | } |
||
118 | } |