Conditions | 10 |
Paths | 12 |
Total Lines | 35 |
Code Lines | 21 |
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 function handle() |
||
35 | { |
||
36 | if (empty($this->template->parametersErrorFromHydrate)) { |
||
|
|||
37 | return; |
||
38 | } |
||
39 | $allParamsAndAlias = $this->template->getParamsAndAlias(); |
||
40 | |||
41 | foreach ($this->template->parametersErrorFromHydrate as $name => $value) { |
||
42 | if (!is_string($name)) { |
||
43 | // example : 1 => "ouvrage collectif" from |ouvrage collectif| |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | // delete error parameter if no value |
||
48 | if (empty($value)) { |
||
49 | unset($this->template->parametersErrorFromHydrate[$name]); |
||
50 | |||
51 | continue; |
||
52 | } |
||
53 | |||
54 | $maxDistance = 1; |
||
55 | if (mb_strlen($name) >= 4) { |
||
56 | $maxDistance = 2; |
||
57 | } |
||
58 | if (mb_strlen($name) >= 8) { |
||
59 | $maxDistance = 3; |
||
60 | } |
||
61 | |||
62 | $predName = TextUtil::predictCorrectParam($name, $allParamsAndAlias, $maxDistance); |
||
63 | if ($predName && mb_strlen($name) >= 5 && empty($this->template->getParam($predName))) { |
||
64 | $predName = $this->template->getAliasParam($predName); |
||
65 | $this->template->setParam($predName, $value); |
||
66 | $this->optiStatus->addSummaryLog(sprintf('%s⇒%s ?', $name, $predName)); |
||
67 | $this->optiStatus->setNotCosmetic(true); |
||
68 | unset($this->template->parametersErrorFromHydrate[$name]); |
||
69 | } |
||
72 | } |