We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 21 |
Paths | > 20000 |
Total Lines | 174 |
Code Lines | 121 |
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 declare(strict_types=1); |
||
63 | function album_entry(int $album_id): void { |
||
64 | $db = Database::getInstance(); |
||
65 | $session = Smr\Session::getInstance(); |
||
66 | |||
67 | // list of all first letter nicks |
||
68 | create_link_list(); |
||
69 | |||
70 | if ($session->hasAccount() && $album_id != $session->getAccountID()) { |
||
71 | $db->write('UPDATE album |
||
72 | SET page_views = page_views + 1 |
||
73 | WHERE account_id = ' . $db->escapeNumber($album_id) . ' AND |
||
74 | approved = \'YES\''); |
||
75 | } |
||
76 | |||
77 | $dbResult = $db->read('SELECT * |
||
78 | FROM album |
||
79 | WHERE account_id = ' . $db->escapeNumber($album_id) . ' AND |
||
80 | approved = \'YES\''); |
||
81 | if ($dbResult->hasRecord()) { |
||
82 | $dbRecord = $dbResult->record(); |
||
83 | $location = $dbRecord->getNullableString('location'); |
||
84 | $email = $dbRecord->getNullableString('email'); |
||
85 | $website = $dbRecord->getNullableString('website'); |
||
86 | $day = $dbRecord->getInt('day'); |
||
87 | $month = $dbRecord->getInt('month'); |
||
88 | $year = $dbRecord->getInt('year'); |
||
89 | $other = nl2br($dbRecord->getString('other')); |
||
90 | $page_views = $dbRecord->getInt('page_views'); |
||
91 | $disabled = $dbRecord->getBoolean('disabled'); |
||
92 | } else { |
||
93 | echo('<h1>Error</h1>'); |
||
94 | echo('This user doesn\'t have an entry in our album!'); |
||
95 | return; |
||
96 | } |
||
97 | |||
98 | // get this user's nick |
||
99 | $nick = get_album_nick($album_id); |
||
100 | |||
101 | echo('<table border="0" cellpadding="5" cellspacing="0">'); |
||
102 | echo('<tr>'); |
||
103 | echo('<td colspan="2">'); |
||
104 | echo '<div style="margin-left: auto; margin-right: auto; width: 50%">'; |
||
105 | echo('<table style="width: 100%">'); |
||
106 | echo('<tr>'); |
||
107 | |||
108 | $dbResult = $db->read('SELECT hof_name |
||
109 | FROM album JOIN account USING(account_id) |
||
110 | WHERE hof_name < ' . $db->escapeString($nick) . ' AND |
||
111 | approved = \'YES\' |
||
112 | ORDER BY hof_name DESC |
||
113 | LIMIT 1'); |
||
114 | echo '<td class="center" style="width: 30%" valign="middle">'; |
||
115 | if ($dbResult->hasRecord()) { |
||
116 | $priv_nick = $dbResult->record()->getString('hof_name'); |
||
117 | echo '<a href="?nick=' . urlencode($priv_nick) . '"><img src="/images/album/rew.jpg" alt="' . $priv_nick . '" border="0"></a> '; |
||
118 | } |
||
119 | echo '</td>'; |
||
120 | echo('<td class="center" valign="middle"><span style="font-size:150%;">' . $nick . '</span><br /><span style="font-size:75%;">Views: ' . $page_views . '</span></td>'); |
||
121 | |||
122 | $dbResult = $db->read('SELECT hof_name |
||
123 | FROM album JOIN account USING(account_id) |
||
124 | WHERE hof_name > ' . $db->escapeString($nick) . ' AND |
||
125 | approved = \'YES\' |
||
126 | ORDER BY hof_name |
||
127 | LIMIT 1'); |
||
128 | echo '<td class="center" style="width: 30%" valign="middle">'; |
||
129 | if ($dbResult->hasRecord()) { |
||
130 | $next_nick = $dbResult->record()->getString('hof_name'); |
||
131 | echo ' <a href="?nick=' . urlencode($next_nick) . '"><img src="/images/album/fwd.jpg" alt="' . $next_nick . '" border="0"></a>'; |
||
132 | } |
||
133 | echo '</td>'; |
||
134 | |||
135 | echo('</tr>'); |
||
136 | echo('</table>'); |
||
137 | echo '</div>'; |
||
138 | echo('</td>'); |
||
139 | echo('</tr>'); |
||
140 | echo('<tr>'); |
||
141 | echo('<td colspan="2" class="center" valign="middle">'); |
||
142 | |||
143 | if ($disabled === false) { |
||
144 | echo('<img src="../upload/' . $album_id . '">'); |
||
145 | } else { |
||
146 | echo('<img src="../images/album/disabled.jpg">'); |
||
147 | } |
||
148 | |||
149 | echo('</td>'); |
||
150 | echo('</tr>'); |
||
151 | |||
152 | if (empty($location)) { |
||
153 | $location = 'N/A'; |
||
154 | } |
||
155 | echo('<tr>'); |
||
156 | echo('<td class="right bold" width="10%">Location:</td><td>' . $location . '</td>'); |
||
157 | echo('</tr>'); |
||
158 | |||
159 | if (empty($email)) { |
||
160 | $email = 'N/A'; |
||
161 | } |
||
162 | echo('<tr>'); |
||
163 | echo('<td class="right bold" width="10%">E-mail:</td><td>' . $email . '</td>'); |
||
164 | echo('</tr>'); |
||
165 | |||
166 | if (empty($website)) { |
||
167 | $website = 'N/A'; |
||
168 | } else { |
||
169 | $website = '<a href="' . $website . '" target="_new">' . $website . '</a>'; |
||
170 | } |
||
171 | echo('<tr>'); |
||
172 | echo('<td class="right bold" width="10%">Website:</td><td>' . $website . '</td>'); |
||
173 | echo('</tr>'); |
||
174 | |||
175 | echo('<tr>'); |
||
176 | if (!empty($day) && !empty($month) && !empty($year)) { |
||
177 | $birthdate = $month . ' / ' . $day . ' / ' . $year; |
||
178 | } |
||
179 | if (empty($birthdate) && !empty($year)) { |
||
180 | $birthdate = 'Year ' . $year; |
||
181 | } |
||
182 | if (empty($birthdate)) { |
||
183 | $birthdate = 'N/A'; |
||
184 | } |
||
185 | echo('<td class="right bold" width="10%">Birthdate:</td><td>' . $birthdate . '</td>'); |
||
186 | echo('</tr>'); |
||
187 | |||
188 | if (empty($other)) { |
||
189 | $other = 'N/A'; |
||
190 | } |
||
191 | echo('<tr>'); |
||
192 | echo('<td class="right bold" valign="top" width="10%">Other Info:</td><td>' . $other . '</td>'); |
||
193 | echo('</tr>'); |
||
194 | |||
195 | echo('<tr>'); |
||
196 | echo('<td colspan="2">'); |
||
197 | echo('<u>Comments</u><br /><br />'); |
||
198 | |||
199 | $dateFormat = $session->hasAccount() ? $session->getAccount()->getDateTimeFormat() : DEFAULT_DATE_TIME_FORMAT; |
||
200 | $dbResult = $db->read('SELECT * |
||
201 | FROM album_has_comments |
||
202 | WHERE album_id = ' . $db->escapeNumber($album_id)); |
||
203 | foreach ($dbResult->records() as $dbRecord) { |
||
204 | $time = $dbRecord->getInt('time'); |
||
205 | $postee = get_album_nick($dbRecord->getInt('post_id')); |
||
206 | $msg = $dbRecord->getString('msg'); |
||
207 | |||
208 | echo('<span style="font-size:85%;">[' . date($dateFormat, $time) . '] <' . $postee . '> ' . $msg . '</span><br />'); |
||
209 | } |
||
210 | |||
211 | if ($session->hasAccount()) { |
||
212 | echo('<form action="album_comment_processing.php">'); |
||
213 | echo('<input type="hidden" name="album_id" value="' . $album_id . '">'); |
||
214 | echo('<table>'); |
||
215 | echo('<tr>'); |
||
216 | echo('<td style="color:green; font-size:70%;">Nick:<br /><input type="text" size="10" name="nick" value="' . htmlspecialchars(get_album_nick($session->getAccountID())) . '" readonly></td>'); |
||
217 | echo('<td style="color:green; font-size:70%;">Comment:<br /><input type="text" size="50" name="comment" required></td>'); |
||
218 | echo('<td style="color:green; font-size:70%;"><br /><input type="submit" name="action" value="Send"></td>'); |
||
219 | $dbResult = $db->read('SELECT 1 |
||
220 | FROM account_has_permission |
||
221 | WHERE account_id = ' . $db->escapeNumber($session->getAccountID()) . ' AND |
||
222 | permission_id = ' . $db->escapeNumber(PERMISSION_MODERATE_PHOTO_ALBUM)); |
||
223 | if ($dbResult->hasRecord()) { |
||
224 | echo('<td style="color:green; font-size:70%;"><br /><input type="submit" name="action" value="Moderate"></td>'); |
||
225 | } |
||
226 | |||
227 | echo('</tr>'); |
||
228 | echo('</table>'); |
||
229 | echo('</form>'); |
||
230 | } else { |
||
231 | echo('<p>Please <a href="/login.php?return_page=/album/?nick=' . urlencode($nick) . '"><u>login</u></a> if you want comment on this picture!</p>'); |
||
232 | } |
||
233 | |||
234 | echo('</td>'); |
||
235 | echo('</tr>'); |
||
236 | echo('</table>'); |
||
237 | |||
316 |