| Conditions | 28 | 
| Paths | 924 | 
| Total Lines | 172 | 
| Code Lines | 110 | 
| Lines | 0 | 
| Ratio | 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 | ||
| 81 | public function getPossibleSelections() | ||
| 82 |     { | ||
| 83 | $data = [ | ||
| 84 | 'propertyIds' => [], | ||
| 85 | 'propertyStaticValueIds' => [], | ||
| 86 | ]; | ||
| 87 |         if ($this->onlyAvailableFilters) { | ||
| 88 |             Yii::beginProfile("onlyAvailableFilters"); | ||
| 89 | $object = Object::findById($this->objectId); | ||
| 90 |             if (!is_null($object) && isset($this->currentSelections['last_category_id'])) { | ||
| 91 | |||
| 92 | $cacheKey = 'FilterWidget: ' . $object->id . ':' . $this->currentSelections['last_category_id'] . ':' | ||
| 93 | . Json::encode($this->currentSelections['properties']); | ||
| 94 | $data = Yii::$app->cache->get($cacheKey); | ||
| 95 |                 if ($data === false) { | ||
| 96 | $data = []; | ||
| 97 |                     Yii::beginProfile("ObjectIds for this category"); | ||
| 98 | $query = new Query(); | ||
| 99 | $query = $query->select($object->categories_table_name . '.object_model_id') | ||
| 100 | ->distinct() | ||
| 101 | ->from($object->categories_table_name) | ||
| 102 | ->join( | ||
| 103 | "JOIN", | ||
| 104 | Product::tableName(), | ||
| 105 |                             sprintf("%s.`id` = %s.`object_model_id`", | ||
| 106 | Product::tableName(), | ||
| 107 | $object->categories_table_name | ||
| 108 | ) | ||
| 109 | ) | ||
| 110 | ->andWhere([Product::tableName() . ".`active`" => 1]) | ||
| 111 | ->andWhere(['category_id' => $this->currentSelections['last_category_id']]); | ||
| 112 | |||
| 113 |                     if (count($this->currentSelections['properties']) > 0) { | ||
| 114 |                         Yii::beginProfile("Apply currency selections(properties)"); | ||
| 115 |                         foreach ($this->currentSelections['properties'] as $property_id => $values) { | ||
| 116 | |||
| 117 | $joinTableName = 'OSVJoinTable'.$property_id; | ||
| 118 | $query->join( | ||
| 119 | 'JOIN', | ||
| 120 | ObjectStaticValues::tableName() . ' '.$joinTableName, | ||
| 121 | $joinTableName.'.object_id = :objectId AND ' | ||
| 122 | . $joinTableName.'.object_model_id = ' . $object->categories_table_name . '.object_model_id ', | ||
|  | |||
| 123 | [ | ||
| 124 | ':objectId' => $object->id, | ||
| 125 | ] | ||
| 126 | ); | ||
| 127 | |||
| 128 | |||
| 129 | $query->andWhere(['in', '`'.$joinTableName.'`.`property_static_value_id`', $values]); | ||
| 130 | } | ||
| 131 |                         Yii::endProfile("Apply currency selections(properties)"); | ||
| 132 | } | ||
| 133 |                     Yii::endProfile("ObjectIds for this category"); | ||
| 134 | |||
| 135 | |||
| 136 |                     $ids = array_map('intval', $query->column()); | ||
| 137 | |||
| 138 | $query = null; | ||
| 139 | |||
| 140 | |||
| 141 |                     Yii::beginProfile("all PSV ids"); | ||
| 142 | $data['propertyStaticValueIds'] = []; | ||
| 143 |                     if (count($ids) !== 0) { | ||
| 144 | $q4psv = (new Query()) | ||
| 145 |                             ->select('property_static_value_id') | ||
| 146 | ->from(ObjectStaticValues::tableName()) | ||
| 147 | ->distinct() | ||
| 148 | ->where(['object_id' => $object->id]) | ||
| 149 |                             ->andWhere('object_model_id in (' . implode(',', $ids) . ')'); | ||
| 150 | |||
| 151 | |||
| 152 |                         $data['propertyStaticValueIds'] = array_map('intval', $q4psv->column()); | ||
| 153 | } | ||
| 154 |                     Yii::endProfile("all PSV ids"); | ||
| 155 | |||
| 156 | |||
| 157 | $ids = null; | ||
| 158 | |||
| 159 |                     Yii::beginProfile("Property ids from PSV ids"); | ||
| 160 | $data['propertyIds'] = []; | ||
| 161 |                     if (count($data['propertyStaticValueIds']) !== 0) { | ||
| 162 | $data['propertyIds'] = PropertyStaticValues::find() | ||
| 163 |                             ->select('property_id') | ||
| 164 | ->distinct() | ||
| 165 | ->where(['dont_filter' => 0]) | ||
| 166 |                             ->andWhere('id IN (' . implode(',', $data['propertyStaticValueIds']) . ')') | ||
| 167 | ->asArray() | ||
| 168 | ->column(); | ||
| 169 | } | ||
| 170 |                     Yii::endProfile("Property ids from PSV ids"); | ||
| 171 | |||
| 172 | Yii::$app->cache->set( | ||
| 173 | $cacheKey, | ||
| 174 | $data, | ||
| 175 | 86400, | ||
| 176 | new TagDependency([ | ||
| 177 | 'tags' => [ | ||
| 178 | \devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag($object->object_class) | ||
| 179 | ], | ||
| 180 | ]) | ||
| 181 | ); | ||
| 182 | $object = null; | ||
| 183 | } | ||
| 184 | } | ||
| 185 |             Yii::endProfile("onlyAvailableFilters"); | ||
| 186 | } | ||
| 187 | |||
| 188 | $this->possibleSelections = []; | ||
| 189 | |||
| 190 | $groups = PropertyGroup::getForObjectId($this->objectId); | ||
| 191 | |||
| 192 |         foreach ($groups as $group) { | ||
| 193 | |||
| 194 |             if ($this->onlyGroupsIds !== null) { | ||
| 195 |                 if (in_array($group->id, $this->onlyGroupsIds) === false) { | ||
| 196 | // skip this group | ||
| 197 | continue; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 |             if ($group->is_internal) { | ||
| 202 | continue; | ||
| 203 | } | ||
| 204 | $this->possibleSelections[$group->id] = [ | ||
| 205 | 'group' => $group, | ||
| 206 | 'selections' => [], | ||
| 207 | 'static_selections' => [], | ||
| 208 | 'dynamic_selections' => [], | ||
| 209 | ]; | ||
| 210 | $props = Property::getForGroupId($group->id); | ||
| 211 |             foreach ($props as $p) { | ||
| 212 | |||
| 213 |                 if ($this->onlyAvailableFilters && !in_array($p->id, $data['propertyIds'])) { | ||
| 214 |                     if ($this->disableInsteadOfHide === false) { | ||
| 215 | continue; | ||
| 216 | } | ||
| 217 | } | ||
| 218 |                 if ($p->dont_filter) { | ||
| 219 | continue; | ||
| 220 | } | ||
| 221 |                 if ($p->has_static_values) { | ||
| 222 | $propertyStaticValues = PropertyStaticValues::getValuesForPropertyId($p->id); | ||
| 223 |                     foreach ($propertyStaticValues as $key => $propertyStaticValue) { | ||
| 224 | |||
| 225 |                         if ($propertyStaticValue['dont_filter']) { | ||
| 226 | unset($propertyStaticValues[$key]); | ||
| 227 | } | ||
| 228 | } | ||
| 229 |                     if ($this->onlyAvailableFilters) { | ||
| 230 |                         foreach ($propertyStaticValues as $key => $propertyStaticValue) { | ||
| 231 | |||
| 232 |                             if (!in_array($propertyStaticValue['id'], $data['propertyStaticValueIds'])) { | ||
| 233 |                                 if ($this->disableInsteadOfHide === true) { | ||
| 234 | $this->disabled_ids[]=$propertyStaticValue['id']; | ||
| 235 |                                 } else { | ||
| 236 | unset($propertyStaticValues[$key]); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | $this->possibleSelections[$group->id]['static_selections'][$p->id] = $propertyStaticValues; | ||
| 243 |                 } elseif ($p->is_column_type_stored && $p->value_type == 'NUMBER') { | ||
| 244 | $this->possibleSelections[$group->id]['dynamic_selections'][] = $p->id; | ||
| 245 | } | ||
| 246 | |||
| 247 | } | ||
| 248 |             if (count($this->possibleSelections[$group->id]) === 0) { | ||
| 249 | unset($this->possibleSelections[$group->id]); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | } | ||
| 253 | } | 
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.