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