| Conditions | 11 |
| Paths | 24 |
| Total Lines | 51 |
| Code Lines | 35 |
| 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 |
||
| 116 | public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = []) |
||
| 117 | { |
||
| 118 | if (isset($parameters['properties'])) { |
||
| 119 | $used_params[] = 'properties'; |
||
| 120 | foreach ($parameters['properties'] as $id => $values) { |
||
| 121 | if (count($values) > 1) { |
||
| 122 | return '?' . http_build_query(['properties' => $parameters['properties']]); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if (isset($parameters['properties'][$this->property_id]) && |
||
| 127 | is_array($parameters['properties'][$this->property_id]) |
||
| 128 | ) { |
||
| 129 | $property_id = $this->property_id; |
||
| 130 | $psvs = Yii::$app->db->cache( |
||
| 131 | function($db) use ($property_id, $parameters) { |
||
| 132 | $vals = array_values($parameters['properties'][$property_id]); |
||
| 133 | $vals = array_map(function($item){ |
||
| 134 | return intval($item); |
||
| 135 | }, $vals); |
||
| 136 | return PropertyStaticValues::find() |
||
| 137 | ->where(['id' => $vals]) |
||
| 138 | ->orderBy('sort_order ASC, name ASC') |
||
| 139 | ->asArray(true) |
||
| 140 | ->all(); |
||
| 141 | }, |
||
| 142 | 86400, new TagDependency(['tags'=>[ActiveRecordHelper::getCommonTag(PropertyStaticValues::className())]]) |
||
| 143 | ); |
||
| 144 | |||
| 145 | foreach ($psvs as $psv) { |
||
| 146 | if (count($this->include_if_value) > 0) { |
||
| 147 | if (!in_array($psv['value'], $this->include_if_value)) { |
||
| 148 | return false; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | if (!empty($psvs)) { |
||
| 153 | foreach ($psvs as $psv) { |
||
| 154 | $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $psv['id']); |
||
| 155 | } |
||
| 156 | return implode('/', ArrayHelper::getColumn($psvs, 'slug')); |
||
| 157 | } else { |
||
| 158 | return false; |
||
| 159 | } |
||
| 160 | } else { |
||
| 161 | return $this->checkIncludeIfValue(); |
||
| 162 | } |
||
| 163 | } else { |
||
| 164 | return $this->checkIncludeIfValue(); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.