Passed
Branch develop (38ee07)
by BENARD
05:37
created

PostTopYearHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 32
c 1
b 0
f 0
dl 0
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 36 1
A __construct() 0 8 1
1
<?php
2
namespace VideoGamesRecords\CoreBundle\Service\Article;
3
4
use DateInterval;
5
use DateTime;
6
use Exception;
7
use VideoGamesRecords\DwhBundle\Service\TopGameProvider;
0 ignored issues
show
Bug introduced by
The type VideoGamesRecords\DwhBun...Service\TopGameProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use VideoGamesRecords\DwhBundle\Service\TopPlayerProvider;
0 ignored issues
show
Bug introduced by
The type VideoGamesRecords\DwhBun...rvice\TopPlayerProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use ProjetNormandie\ArticleBundle\Service\Writer;
10
11
class PostTopYearHandler implements PostTopHandlerInterface
12
{
13
    use HtmlTopTrait;
14
15
    private TopGameProvider $topGameProvider;
16
    private TopPlayerProvider $topPlayerProvider;
17
    private Writer $writer;
18
19
    public function __construct(
20
        TopGameProvider $topGameProvider,
21
        TopPlayerProvider $topPlayerProvider,
22
        Writer $writer
23
    ) {
24
        $this->topGameProvider = $topGameProvider;
25
        $this->topPlayerProvider = $topPlayerProvider;
26
        $this->writer = $writer;
27
    }
28
29
    /**
30
     * @param $day
31
     * @throws Exception
32
     */
33
    public function handle($day): void
34
    {
35
        $date1Begin = new DateTime($day);
36
        $date1End = new DateTime($day);
37
38
        $date1End->sub(new DateInterval('P1D'));
39
        $date1Begin->sub(new DateInterval('P1Y'));
40
41
        $date2Begin = clone($date1Begin);
42
        $date2End = clone($date1End);
43
44
        $date2Begin->sub(new DateInterval('P1Y'));
45
        $date2End->sub(new DateInterval('P1Y'));
46
47
        $year = $date1Begin->format('Y');
48
49
        $gamesData = $this->topGameProvider->getTop($date1Begin, $date1End, $date2Begin, $date2End, 100);
50
        $gamesHtmlEn = $this->getHtmlTopGame($gamesData, 'en');
51
        $gamesHtmlFr = $this->getHtmlTopGame($gamesData, 'fr');
52
53
54
        $playersData = $this->topPlayerProvider->getTop($date1Begin, $date1End, $date2Begin, $date2End, 100);
55
        $playersHtmlEn = $this->getHtmlTopPlayer($playersData, 'en');
56
        $playersHtmlFr = $this->getHtmlTopPlayer($playersData, 'fr');
57
58
        $textEn = $gamesHtmlEn . '<br /><br />' . $playersHtmlEn;
59
        $textFr = $gamesHtmlFr . '<br /><br />' . $playersHtmlFr;
60
61
        $this->writer->write(
0 ignored issues
show
Bug introduced by
The call to ProjetNormandie\ArticleB...Service\Writer::write() has too few arguments starting with author. ( Ignorable by Annotation )

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

61
        $this->writer->/** @scrutinizer ignore-call */ 
62
                       write(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
62
            array(
63
                'en' => 'Top of year #' . $year,
64
                'fr' => 'Top de l\'année #' . $year,
65
            ),
66
            array(
67
                'en' => $textEn,
68
                'fr' => $textFr,
69
            )
70
        );
71
    }
72
}