Conditions | 14 |
Paths | 12 |
Total Lines | 93 |
Lines | 12 |
Ratio | 12.9 % |
Changes | 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 |
||
38 | public function search($params) |
||
39 | { |
||
40 | /* @var $query \yii\db\ActiveQuery */ |
||
41 | $query = $this->baseModel->find(); |
||
42 | |||
43 | $table_inheritance_joined = false; |
||
44 | |||
45 | $dataProvider = new ActiveDataProvider( |
||
46 | [ |
||
47 | 'query' => &$query, |
||
48 | 'pagination' => [ |
||
49 | 'pageSize' => 10, |
||
50 | ], |
||
51 | 'sort' => [ |
||
52 | 'defaultOrder' => [ |
||
53 | 'id' => SORT_DESC |
||
54 | ] |
||
55 | ], |
||
56 | ] |
||
57 | ); |
||
58 | |||
59 | if (!($this->load($params))) { |
||
60 | return $dataProvider; |
||
61 | } |
||
62 | |||
63 | $object = BaseObject::getForClass($this->baseModel->className()); |
||
|
|||
64 | $baseModelTableName = $this->baseModel->tableName(); |
||
65 | |||
66 | $eavJoinsCount = 0; |
||
67 | $osvJoinsCount = 0; |
||
68 | |||
69 | foreach ($this->propertyGroups as $groupId => $properties) { |
||
70 | foreach ($properties as $key => $propertyValue) { |
||
71 | /** @var \app\properties\PropertyValue $propertyValue */ |
||
72 | $prop = Property::findById($propertyValue->property_id); |
||
73 | if (empty($this->{$prop->key}) === true && $this->{$prop->key} !== '0') { |
||
74 | continue; |
||
75 | } |
||
76 | |||
77 | // determine property storage type and join needed table if needed |
||
78 | if ($prop->is_column_type_stored) { |
||
79 | if ($table_inheritance_joined === false) { |
||
80 | $table_inheritance_joined = true; |
||
81 | $query->join('INNER JOIN', $object->column_properties_table_name . ' ti', |
||
82 | 'ti.object_model_id = ' . $baseModelTableName . '.id'); |
||
83 | } |
||
84 | |||
85 | View Code Duplication | if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) { |
|
86 | $query->andFilterWhere(['like', 'ti.'.$prop->key, $this->{$prop->key}]); |
||
87 | } else { |
||
88 | $query->andFilterWhere(['ti.'.$prop->key => $this->{$prop->key}]); |
||
89 | } |
||
90 | |||
91 | } elseif ($prop->is_eav) { |
||
92 | $eavJoinsCount++; |
||
93 | $eavTableName = 'eav'.$eavJoinsCount; |
||
94 | |||
95 | $key = 'key'.$eavJoinsCount; |
||
96 | |||
97 | $query->join( |
||
98 | 'INNER JOIN', |
||
99 | "$object->eav_table_name $eavTableName", |
||
100 | $eavTableName.'.object_model_id = '.$baseModelTableName.".id AND $eavTableName.key=:$key", |
||
101 | [$key=>$prop->key] |
||
102 | ); |
||
103 | View Code Duplication | if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) { |
|
104 | $query->andFilterWhere(['like', $eavTableName.'.value', $this->{$prop->key}]); |
||
105 | } else { |
||
106 | // numeric - direct match |
||
107 | $query->andFilterWhere([$eavTableName.'.value' => $this->{$prop->key}]); |
||
108 | |||
109 | } |
||
110 | |||
111 | } elseif ($prop->has_static_values) { |
||
112 | $osvJoinsCount++; |
||
113 | $osvTableName = 'osv'.$osvJoinsCount; |
||
114 | |||
115 | $query->join( |
||
116 | 'INNER JOIN', |
||
117 | "object_static_values $osvTableName", |
||
118 | "$osvTableName.object_id={$object->id} AND $osvTableName.object_model_id=$baseModelTableName.id" |
||
119 | ); |
||
120 | |||
121 | |||
122 | // numeric - direct match |
||
123 | $query->andFilterWhere(["$osvTableName.property_static_value_id", $this->{$prop->key}]); |
||
124 | |||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | return $dataProvider; |
||
130 | } |
||
131 | |||
175 | } |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.