Conditions | 8 |
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 |
||
77 | private function getHtmlTopPlayer($data, string $locale = 'en'): string |
||
78 | { |
||
79 | $html = ''; |
||
80 | |||
81 | if (count($data['list']) > 0) { |
||
82 | $html .= '<div class="article-top article-top__players">'; |
||
83 | for ($i = 0; $i <= 2; $i++) { |
||
84 | if (array_key_exists($i, $data['list'])) { |
||
85 | $html .= sprintf( |
||
86 | '<a href="%s"><img src="https://backoffice.video-games-records.com/users/%d/avatar" alt="%s" class="article-top__player" /></a>', |
||
87 | '/' . $locale . '/' . $data['list'][$i]['player']->getUrl(), |
||
88 | $data['list'][$i]['player']->getId(), |
||
89 | $data['list'][$i]['player']->getPseudo() |
||
90 | ); |
||
91 | } |
||
92 | if ($i == 0) { |
||
93 | $html .= '<br />'; |
||
94 | } |
||
95 | } |
||
96 | |||
97 | $html .= '<table class="article-top__table">'; |
||
98 | $html .= '<thead>'; |
||
99 | $html .= '<tr>'; |
||
100 | $html .= '<th scope="col"><abbr title="Rank">#</abbr></th>'; |
||
101 | $html .= '<th scope="col">Player</th>'; |
||
102 | $html .= '<th scope="col">Posts submitted</th>'; |
||
103 | $html .= '<th scope="col">Position change</th>'; |
||
104 | $html .= '</tr>'; |
||
105 | $html .= '</tr>'; |
||
106 | $html .= '<tbody>'; |
||
107 | |||
108 | foreach ($data['list'] as $row) { |
||
109 | $html .= sprintf( |
||
110 | $this->getHtmLine(), |
||
111 | $row['rank'], |
||
112 | '/' . $locale . '/' . $row['player']->getUrl(), |
||
113 | (($row['player'] != null) ? $row['player']->getPseudo() : '???'), |
||
114 | $row['nb'], |
||
115 | $this->diff($row, count($data['list'])) |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | if ($data['nbTotalPost'] > $data['nbPostFromList']) { |
||
120 | $html .= sprintf( |
||
121 | $this->getHtmlBottom1(), |
||
122 | count($data['list']) + 1, |
||
123 | $data['nb'], |
||
124 | $data['nbTotalPost'] - $data['nbPostFromList'] |
||
125 | ); |
||
126 | } |
||
127 | $html .= sprintf($this->getHtmlBottom2(), $data['nbTotalPost']); |
||
128 | $html .= '</tbody>'; |
||
129 | $html .= '</table>'; |
||
130 | $html .= '</div>'; |
||
131 | } |
||
132 | |||
133 | return $html; |
||
134 | } |
||
206 |