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

GetHtmlTopGameTrait::getHtmlTopGame()   B

Complexity

Conditions 7
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.3306
c 1
b 0
f 0
cc 7
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 GetHtmlTopGameTrait
6
{
7
    /**
8
     * @param        $data
9
     * @param string $locale
10
     * @return string
11
     */
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(),
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

46
                    $this->/** @scrutinizer ignore-call */ 
47
                           getHtmLine(),
Loading history...
47
                    $row['rank'],
48
                    '/' . $locale . '/' . $row['game']->getUrl(),
49
                    $row['game']->getName(),
50
                    $row['nb'],
51
                    $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

51
                    $this->/** @scrutinizer ignore-call */ 
52
                           diff($row, count($data['list']))
Loading history...
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['nbItem'],
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