Conditions | 12 |
Paths | 42 |
Total Lines | 70 |
Code Lines | 50 |
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 |
||
105 | */ |
||
106 | protected function _inspectComparisonExpression(Comparison $expression, $bundle, Query $query) |
||
107 | { |
||
108 | $field = $expression->getField(); |
||
109 | $column = is_string($field) ? $this->_toolbox->columnName($field) : ''; |
||
110 | |||
111 | View Code Duplication | if (empty($column) || |
|
112 | in_array($column, (array)$this->_table->schema()->columns()) || // ignore real columns |
||
113 | !in_array($column, $this->_toolbox->getAttributeNames()) || |
||
114 | !$this->_toolbox->isSearchable($column) // ignore no searchable virtual columns |
||
115 | ) { |
||
116 | // nothing to alter |
||
117 | return $expression; |
||
118 | } |
||
119 | |||
120 | $attr = $this->_toolbox->attributes($bundle)[$column]; |
||
121 | $value = $expression->getValue(); |
||
122 | $type = $this->_toolbox->getType($column); |
||
123 | $conjunction = $expression->getOperator(); |
||
124 | $conditions = [ |
||
125 | 'EavValues.eav_attribute_id' => $attr['id'], |
||
126 | "EavValues.value_{$type} {$conjunction}" => $value, |
||
127 | ]; |
||
128 | |||
129 | // subquery scope |
||
130 | $subQuery = TableRegistry::get('Eav.EavValues') |
||
131 | ->find() |
||
132 | ->select('EavValues.entity_id') |
||
133 | ->where($conditions); |
||
134 | |||
135 | // some variables |
||
136 | $pk = $this->_tablePrimaryKey(); |
||
137 | $driverClass = $this->_driverClass($query); |
||
138 | |||
139 | View Code Duplication | switch ($driverClass) { |
|
140 | case 'sqlite': |
||
141 | $concat = implode(' || ', $pk); |
||
142 | $field = "({$concat} || '')"; |
||
143 | break; |
||
144 | case 'mysql': |
||
145 | case 'postgres': |
||
146 | case 'sqlserver': |
||
147 | default: |
||
148 | $concat = implode(', ', $pk); |
||
149 | $field = "CONCAT({$concat}, '')"; |
||
150 | break; |
||
151 | } |
||
152 | |||
153 | // compile query, faster than raw subquery in most cases |
||
154 | $ids = $subQuery->all()->extract('entity_id')->toArray(); |
||
155 | $ids = empty($ids) ? ['-1'] : $ids; |
||
156 | $expression->setField($field); |
||
157 | $expression->setValue($ids); |
||
158 | $expression->setOperator('IN'); |
||
159 | |||
160 | $class = new \ReflectionClass($expression); |
||
161 | $property = $class->getProperty('_type'); |
||
162 | $property->setAccessible(true); |
||
163 | $property->setValue($expression, 'string[]'); |
||
164 | |||
165 | return $expression; |
||
166 | } |
||
167 | |||
168 | protected function _inspectUnaryExpression(UnaryExpression $expression, $bundle, Query $query) |
||
169 | { |
||
170 | $class = new \ReflectionClass($expression); |
||
171 | $property = $class->getProperty('_value'); |
||
172 | $property->setAccessible(true); |
||
173 | $value = $property->getValue($expression); |
||
174 | |||
175 | if ($value instanceof IdentifierExpression) { |
||
256 |