Conditions | 20 |
Paths | 16 |
Total Lines | 65 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
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 | if (is_array($this->tempExpected)) { |
||
89 | foreach ($this->tempExpected as &$expected) { |
||
90 | $expected = trim(trim($expected, '\''), '"'); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | |||
95 | if (!is_array($this->tempExpected) && stristr($this->tempExpected, '{') && stristr($this->tempExpected, '}')) { |
||
96 | $this->tempExpected = eval(str_replace('{', 'return (', str_replace('}', ');', $this->tempExpected))); |
||
97 | } elseif(is_array($this->tempExpected)) { |
||
98 | foreach ($this->tempExpected as &$expected) { |
||
99 | if (stristr($expected, '{') && stristr($expected, '}')) { |
||
100 | $expected = eval(str_replace('{', 'return (', str_replace('}', ');', $expected))); |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | |||
105 | $decodedStatement[$orKey]['method'] = $this->tempMethod; |
||
106 | $decodedStatement[$orKey]['expected'] = $this->tempExpected; |
||
107 | $decodedStatement[$orKey]['field'] = $this->tempField; |
||
108 | } |
||
109 | |||
110 | $this->setDecodedLogicStatement($decodedStatement); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | return true; |
||
115 | } |
||
116 | |||
197 | } |