Conditions | 12 |
Paths | 10 |
Total Lines | 44 |
Code Lines | 30 |
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 |
||
39 | public function addRuleValidation(array $fields): array |
||
40 | { |
||
41 | foreach ($fields as $key => $data) { |
||
42 | if ($key === 'vat_id') { |
||
43 | if ($this->config->getConfigByVatId('enabled_cpf') && $this->config->getConfigByVatId('enabled_cnpj')) { |
||
44 | $fields[$key]['validation'] = [ |
||
45 | 'required-entry' => 1, |
||
46 | Config::VAT_CPF_OR_CNPJ => 1, |
||
47 | ]; |
||
48 | } elseif ($this->config->getConfigByVatId('enabled_cpf')) { |
||
49 | $fields[$key]['validation'] = [ |
||
50 | 'required-entry' => 1, |
||
51 | Config::VAT_ONLY_CPF => 1, |
||
52 | ]; |
||
53 | } elseif ($this->config->getConfigByVatId('enabled_cnpj')) { |
||
54 | $fields[$key]['validation'] = [ |
||
55 | 'required-entry' => 1, |
||
56 | Config::VAT_ONLY_CNPJ => 1, |
||
57 | ]; |
||
58 | } |
||
59 | } elseif ($key === 'taxvat') { |
||
60 | if ($this->config->getConfigByTaxvat('enabled_cpf') |
||
61 | && $this->config->getConfigByTaxvat('enabled_cnpj') |
||
62 | ) { |
||
63 | $fields[$key]['validation'] = [ |
||
64 | 'required-entry' => 1, |
||
65 | Config::VAT_CPF_OR_CNPJ => 1, |
||
66 | ]; |
||
67 | } elseif ($this->config->getConfigByTaxvat('enabled_cpf')) { |
||
68 | $fields[$key]['validation'] = [ |
||
69 | 'required-entry' => 1, |
||
70 | Config::VAT_ONLY_CPF => 1, |
||
71 | ]; |
||
72 | } elseif ($this->config->getConfigByTaxvat('enabled_cnpj')) { |
||
73 | $fields[$key]['validation'] = [ |
||
74 | 'required-entry' => 1, |
||
75 | Config::VAT_ONLY_CNPJ => 1, |
||
76 | ]; |
||
77 | } |
||
78 | } |
||
79 | continue; |
||
80 | } |
||
81 | |||
82 | return $fields; |
||
83 | } |
||
132 |