| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| 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 |
||
| 51 | public function indexActionGet(): object |
||
| 52 | { |
||
| 53 | $page = $this->di->get("page"); |
||
| 54 | $question = new Question(); |
||
| 55 | $user = new User(); |
||
| 56 | $tag = new Tag(); |
||
| 57 | $user_id = $this->di->get("session")->get("user_id"); |
||
| 58 | $db = $this->di->get("dbqb"); |
||
| 59 | $question->setDb($db); |
||
| 60 | $user->setDb($db); |
||
| 61 | $tag->setDb($db); |
||
| 62 | $mostActiveUsers = $user->findAllWhere("id in ( |
||
| 63 | select user_id |
||
| 64 | from (select sum(count) as count, user_id |
||
| 65 | from ( |
||
| 66 | select count(id) as count, user_id |
||
| 67 | from Question |
||
| 68 | group by user_id |
||
| 69 | union |
||
| 70 | select count(id) as count, user_id |
||
| 71 | from Comment |
||
| 72 | group by user_id |
||
| 73 | union |
||
| 74 | select count(id) as count, user_id |
||
| 75 | from Answer |
||
| 76 | group by user_id |
||
| 77 | ) |
||
| 78 | group by user_id |
||
| 79 | ) order by count limit 10 |
||
| 80 | )", []); |
||
| 81 | $mostPopularTags = $tag->findAllWhere("id in ( |
||
| 82 | select tag_id |
||
| 83 | from ( |
||
| 84 | select count(question_id) as count, tag_id |
||
| 85 | from TagQuestion |
||
| 86 | group by tag_id |
||
| 87 | ) order by count desc limit 10 |
||
| 88 | )", []); |
||
| 89 | $mostRecentQuestions = $db->connect() |
||
| 90 | ->execute( |
||
| 91 | "select * from Question order by created desc limit 5" |
||
| 92 | , []) |
||
| 93 | ->fetchAllClass(Question::class); |
||
| 94 | $data = [ |
||
| 95 | "questions" => $question->findAll(), |
||
| 96 | "mostActiveUsers" => $mostActiveUsers, |
||
| 97 | "mostPopularTags" => $mostPopularTags, |
||
| 98 | "mostRecentQuestions" => $mostRecentQuestions, |
||
| 99 | "user" => $user->findById($user_id), |
||
| 100 | "title" => "Index page" |
||
| 101 | ]; |
||
| 102 | |||
| 103 | $page->add("forum/index", $data); |
||
| 104 | return $page->render($data); |
||
| 105 | } |
||
| 106 | |||
| 108 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.