Conditions | 7 |
Paths | 3 |
Total Lines | 57 |
Code Lines | 41 |
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 |
||
13 | private function getHtmlTopGame($data, string $locale = 'en'): string |
||
14 | { |
||
15 | $html = ''; |
||
16 | |||
17 | if (count($data['list']) > 0) { |
||
18 | $html .= '<div class="article-top article-top__games">'; |
||
19 | |||
20 | for ($i = 0; $i <= 2; $i++) { |
||
21 | if (array_key_exists($i, $data['list'])) { |
||
22 | $html .= sprintf( |
||
23 | '<a href="%s"><img src="https://backoffice.video-games-records.com/game/%d/picture" alt="%s" class="article-top__game" /></a>', |
||
24 | '/' . $locale . '/' . $data['list'][$i]['game']->getUrl(), |
||
25 | $data['list'][$i]['game']->getId(), |
||
26 | $data['list'][$i]['game']->getName() |
||
27 | ); |
||
28 | } |
||
29 | if ($i == 0) { |
||
30 | $html .= '<br />'; |
||
31 | } |
||
32 | } |
||
33 | |||
34 | $html .= '<table class="article-top__table">'; |
||
35 | $html .= '<thead>'; |
||
36 | $html .= '<tr>'; |
||
37 | $html .= '<th scope="col"><abbr title="Rank">#</abbr></th>'; |
||
38 | $html .= '<th scope="col">Game</th>'; |
||
39 | $html .= '<th scope="col">Posts submitted</th>'; |
||
40 | $html .= '<th scope="col">Position change</th>'; |
||
41 | $html .= '</tr>'; |
||
42 | $html .= '</tr>'; |
||
43 | $html .= '<tbody>'; |
||
44 | |||
45 | foreach ($data['list'] as $row) { |
||
46 | $html .= sprintf( |
||
47 | $this->getHtmLine(), |
||
48 | $row['rank'], |
||
49 | '/' . $locale . '/' . $row['game']->getUrl(), |
||
50 | $row['game']->getName(), |
||
51 | $row['nb'], |
||
52 | $this->diff($row, count($data['list'])) |
||
53 | ); |
||
54 | } |
||
55 | if ($data['nbTotalPost'] > $data['nbPostFromList']) { |
||
56 | $html .= sprintf( |
||
57 | $this->getHtmlBottom1(), |
||
58 | count($data['list']) + 1, |
||
59 | $data['nbItem'], |
||
60 | $data['nbTotalPost'] - $data['nbPostFromList'] |
||
61 | ); |
||
62 | } |
||
63 | $html .= sprintf($this->getHtmlBottom2(), $data['nbTotalPost']); |
||
64 | $html .= '</tbody>'; |
||
65 | $html .= '</table>'; |
||
66 | $html .= '</div>'; |
||
67 | } |
||
68 | |||
69 | return $html; |
||
70 | } |
||
206 |