Conditions | 11 |
Paths | 30 |
Total Lines | 56 |
Code Lines | 40 |
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 |
||
56 | public function getNextPart($full_url, $next_part, &$previous_parts) |
||
57 | { |
||
58 | $property = Property::findById($this->property_id); |
||
59 | if (is_null($property)) { |
||
60 | return false; |
||
61 | } |
||
62 | if ($property->has_static_values && $property->has_slugs_in_values) { |
||
63 | $cacheTags = []; |
||
64 | $static_values = PropertyStaticValues::getValuesForPropertyId($this->property_id); |
||
65 | $slugs = explode('/', $next_part); |
||
66 | $currentSlug = 0; |
||
67 | $slugsCount = count($slugs); |
||
68 | $appliedParts = []; |
||
69 | foreach ($static_values as $value) { |
||
70 | if ($slugs[$currentSlug] === $value['slug']) { |
||
71 | $appliedParts[] = $value['slug']; |
||
72 | if (isset($this->parameters['properties'][$this->property_id])) { |
||
73 | $this->parameters['properties'][$this->property_id][] = $value['id']; |
||
74 | } else { |
||
75 | $this->parameters = [ |
||
76 | 'properties' => [ |
||
77 | $this->property_id => [$value['id']], |
||
78 | ], |
||
79 | ]; |
||
80 | } |
||
81 | if (!empty($value['title_append'])) { |
||
82 | if ($value["title_prepend"] == 1) { |
||
83 | $this->addParam("title_prepend", $value["title_append"]); |
||
84 | } else { |
||
85 | $this->addParam("title_append", $value["title_append"]); |
||
86 | } |
||
87 | } |
||
88 | $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $value['id']); |
||
89 | $currentSlug++; |
||
90 | if ($currentSlug == $slugsCount) { |
||
91 | break; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | if ($currentSlug > 0) { |
||
96 | $appliedPartsString = implode('/', $appliedParts); |
||
97 | $part = new self( |
||
98 | [ |
||
99 | 'gathered_part' => $appliedPartsString, |
||
100 | 'rest_part' => mb_substr($next_part, mb_strlen($appliedPartsString)), |
||
101 | 'parameters' => $this->parameters, |
||
102 | 'cacheTags' => $cacheTags, |
||
103 | ] |
||
104 | ); |
||
105 | return $part; |
||
106 | } |
||
107 | return false; |
||
108 | } else { |
||
109 | return false; |
||
110 | } |
||
111 | } |
||
112 | |||
162 |
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
@return
annotation as described here.