Conditions | 13 |
Paths | 11 |
Total Lines | 53 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 2 |
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 namespace Cornford\Logical; |
||
51 | protected function decodeLogicStatements() |
||
52 | { |
||
53 | if (!$this->getLogic()) { |
||
54 | return true; |
||
55 | } |
||
56 | |||
57 | $orStatements = preg_split("/.OR./", $this->getLogic()); |
||
58 | |||
59 | foreach ($orStatements as $orKey => $orStatement) { |
||
60 | $andStatements = preg_split("/.AND./", $orStatement); |
||
61 | |||
62 | foreach ($andStatements as $andStatement) { |
||
63 | $items = preg_split("/\./", $andStatement, 2); |
||
64 | $decodedStatement = []; |
||
65 | |||
66 | foreach ($items as $item) { |
||
67 | $matches = null; |
||
68 | if (stristr($item, 'where')) { |
||
69 | if (!preg_match("/\((?<field>.*)\)/", $item, $matches)) { |
||
70 | return false; |
||
71 | } |
||
72 | |||
73 | $this->tempField = trim(trim($matches['field'], '\''), '"'); |
||
74 | |||
75 | continue; |
||
76 | } |
||
77 | |||
78 | if (!preg_match("/^(?<method>[a-zA-Z]{1,})\((?<expected>[\'\"]*.*[\'\"]*)\)/", $item, $matches)) { |
||
79 | return false; |
||
80 | } else { |
||
81 | $this->tempMethod = trim(trim($matches['method'], '\''), '"'); |
||
82 | $this->tempExpected = trim(trim($matches['expected'], '\''), '"'); |
||
83 | } |
||
84 | |||
85 | if (stristr($this->tempExpected, ',') && !stristr($this->tempExpected, '{') && !stristr($this->tempExpected, '}')) { |
||
86 | $this->tempExpected = explode(', ', $this->tempExpected); |
||
87 | } |
||
88 | |||
89 | if (stristr($this->tempExpected, '{') && stristr($this->tempExpected, '}')) { |
||
90 | $this->tempExpected = eval(str_replace('{', 'print_r(', str_replace('}', ', true);', $this->tempExpected))); |
||
91 | } |
||
92 | |||
93 | $decodedStatement[$orKey]['method'] = $this->tempMethod; |
||
94 | $decodedStatement[$orKey]['expected'] = $this->tempExpected; |
||
95 | $decodedStatement[$orKey]['field'] = $this->tempField; |
||
96 | } |
||
97 | |||
98 | $this->setDecodedLogicStatement($decodedStatement); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | return true; |
||
103 | } |
||
104 | |||
185 | } |