Conditions | 2 |
Paths | 2 |
Total Lines | 80 |
Code Lines | 68 |
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 |
||
64 | public function getChangeLogForSection($section, $limit = 10) { |
||
65 | $stmt = \AL\Db\execute_query( |
||
66 | "ChangeLogDAO: getChangeLogForSection", |
||
67 | $this->mysqli, |
||
68 | "SELECT |
||
69 | change_log_id, |
||
70 | section, |
||
71 | section_id, |
||
72 | section_name, |
||
73 | sub_section, |
||
74 | sub_section_id, |
||
75 | sub_section_name, |
||
76 | change_log.user_id, |
||
77 | users.userid, |
||
78 | users.email, |
||
79 | users.join_date, |
||
80 | users.karma, |
||
81 | users.show_email, |
||
82 | users.avatar_ext, |
||
83 | action, |
||
84 | timestamp |
||
85 | FROM change_log |
||
86 | LEFT JOIN users ON (change_log.user_id = users.user_id) |
||
87 | WHERE change_log.section = ? |
||
88 | ORDER BY timestamp DESC LIMIT ?", |
||
89 | "si", $section, $limit |
||
90 | ); |
||
91 | |||
92 | \AL\Db\bind_result( |
||
93 | "ChangeLogDAO: getChangeLogForSection", |
||
94 | $stmt, |
||
95 | $change_log_id, |
||
96 | $section, |
||
97 | $section_id, |
||
98 | $section_name, |
||
99 | $sub_section, |
||
100 | $sub_section_id, |
||
101 | $sub_section_name, |
||
102 | $user_id, |
||
103 | $user_name, |
||
104 | $user_email, |
||
105 | $user_join_date, |
||
106 | $user_karma, |
||
107 | $user_show_email, |
||
108 | $user_avatar_ext, |
||
109 | $action, |
||
110 | $timestamp |
||
111 | ); |
||
112 | |||
113 | $changelogs = []; |
||
114 | |||
115 | while ($stmt->fetch()) { |
||
116 | $changelog = new \AL\Common\Model\Database\ChangeLog( |
||
117 | $change_log_id, |
||
118 | $section, |
||
119 | $section_id, |
||
120 | $section_name, |
||
121 | $sub_section, |
||
122 | $sub_section_id, |
||
123 | $sub_section_name, |
||
124 | $user_id, |
||
125 | $action, |
||
126 | $timestamp |
||
127 | ); |
||
128 | $changelog->setUser(new \AL\Common\Model\User\User( |
||
129 | $user_id, |
||
130 | $user_name, |
||
131 | $user_email, |
||
132 | $user_join_date, |
||
133 | $user_karma, |
||
134 | $user_show_email, |
||
135 | $user_avatar_ext |
||
136 | )); |
||
137 | |||
138 | $changelogs[] = $changelog; |
||
139 | } |
||
140 | |||
141 | $stmt->close(); |
||
142 | |||
143 | return $changelogs; |
||
144 | } |
||
146 |