Passed
Branch develop (ebac2f)
by BENARD
10:03
created

GetHtmlTopPlayerTrait::getHtmlTopPlayer()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 57
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 41
dl 0
loc 57
rs 8.0195
c 1
b 0
f 0
cc 8
nc 3
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\Traits\Top;
4
5
trait GetHtmlTopPlayerTrait
6
{
7
    /**
8
     * @param        $data
9
     * @param string $locale
10
     * @return string
11
     */
12
    private function getHtmlTopPlayer($data, string $locale = 'en'): string
13
    {
14
        $html = '';
15
16
        if (count($data['list']) > 0) {
17
            $html .= '<div class="article-top article-top__players">';
18
            for ($i = 0; $i <= 2; $i++) {
19
                if (array_key_exists($i, $data['list'])) {
20
                    $html .= sprintf(
21
                        '<a href="%s"><img src="https://backoffice.video-games-records.com/users/%d/avatar" alt="%s" class="article-top__player" /></a>',
22
                        '/' . $locale . '/' . $data['list'][$i]['player']->getUrl(),
23
                        $data['list'][$i]['player']->getId(),
24
                        $data['list'][$i]['player']->getPseudo()
25
                    );
26
                }
27
                if ($i == 0) {
28
                    $html .= '<br />';
29
                }
30
            }
31
32
            $html .= '<table class="article-top__table">';
33
            $html .= '<thead>';
34
            $html .= '<tr>';
35
            $html .= '<th scope="col"><abbr title="Rank">#</abbr></th>';
36
            $html .= '<th scope="col">Player</th>';
37
            $html .= '<th scope="col">Posts submitted</th>';
38
            $html .= '<th scope="col">Position change</th>';
39
            $html .= '</tr>';
40
            $html .= '</tr>';
41
            $html .= '<tbody>';
42
43
            foreach ($data['list'] as $row) {
44
                $html .= sprintf(
45
                    $this->getHtmLine(),
0 ignored issues
show
Bug introduced by
It seems like getHtmLine() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
                    $this->/** @scrutinizer ignore-call */ 
46
                           getHtmLine(),
Loading history...
46
                    $row['rank'],
47
                    '/' . $locale . '/' . $row['player']->getUrl(),
48
                    (($row['player'] != null) ? $row['player']->getPseudo() : '???'),
49
                    $row['nb'],
50
                    $this->diff($row, count($data['list']))
0 ignored issues
show
Bug introduced by
It seems like diff() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
                    $this->/** @scrutinizer ignore-call */ 
51
                           diff($row, count($data['list']))
Loading history...
51
                );
52
            }
53
54
            if ($data['nbTotalPost'] > $data['nbPostFromList']) {
55
                $html .= sprintf(
56
                    $this->getHtmlBottom1(),
0 ignored issues
show
Bug introduced by
It seems like getHtmlBottom1() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                    $this->/** @scrutinizer ignore-call */ 
57
                           getHtmlBottom1(),
Loading history...
57
                    count($data['list']) + 1,
58
                    $data['nb'],
59
                    $data['nbTotalPost'] - $data['nbPostFromList']
60
                );
61
            }
62
            $html .= sprintf($this->getHtmlBottom2(), $data['nbTotalPost']);
0 ignored issues
show
Bug introduced by
It seems like getHtmlBottom2() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
            $html .= sprintf($this->/** @scrutinizer ignore-call */ getHtmlBottom2(), $data['nbTotalPost']);
Loading history...
63
            $html .= '</tbody>';
64
            $html .= '</table>';
65
            $html .= '</div>';
66
        }
67
68
        return $html;
69
    }
70
}
71