Conditions | 17 |
Paths | 3 |
Total Lines | 55 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
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 |
||
136 | private function detectLegacyPageOwner() { |
||
137 | |||
138 | $guid = $this->invoker->call(ELGG_IGNORE_ACCESS, function() { |
||
139 | |||
140 | $username = $this->request->getParam('username'); |
||
141 | if ($user = $this->users_table->getByUsername($username)) { |
||
142 | return $user->guid; |
||
143 | } |
||
144 | |||
145 | $owner = $this->request->getParam('owner_guid'); |
||
146 | if (is_numeric($owner)) { |
||
147 | if ($user = $this->entity_table->get((int) $owner)) { |
||
148 | return $user->guid; |
||
149 | } |
||
150 | } |
||
151 | }); |
||
152 | |||
153 | if (is_int($guid)) { |
||
154 | return $guid; |
||
155 | } |
||
156 | |||
157 | // @todo feels hacky |
||
158 | $guid = $this->invoker->call(ELGG_IGNORE_ACCESS, function() { |
||
159 | $segments = $this->request->getUrlSegments(); |
||
160 | if (!isset($segments[1]) || !isset($segments[2])) { |
||
161 | return; |
||
162 | } |
||
163 | |||
164 | switch ($segments[1]) { |
||
165 | case 'owner': |
||
166 | case 'friends': |
||
167 | $user = $this->users_table->getByUsername($segments[2]); |
||
168 | if ($user) { |
||
169 | return $user->guid; |
||
170 | } |
||
171 | break; |
||
172 | case 'view': |
||
173 | case 'edit': |
||
174 | $entity = $this->entity_table->get($segments[2]); |
||
1 ignored issue
–
show
|
|||
175 | if ($entity) { |
||
176 | return $entity->container_guid; |
||
177 | } |
||
178 | break; |
||
179 | case 'add': |
||
180 | case 'group': |
||
181 | $entity = $this->entity_table->get($segments[2]); |
||
182 | if ($entity) { |
||
183 | return $entity->guid; |
||
184 | } |
||
185 | break; |
||
186 | } |
||
187 | }); |
||
188 | |||
189 | if (is_int($guid)) { |
||
190 | return $guid; |
||
191 | } |
||
228 |