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

PostTopWeekHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
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 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 35 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 PostTopWeekHandler 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('P7D'));
40
41
        $date2Begin = clone($date1Begin);
42
        $date2End = clone($date1End);
43
44
        $date2Begin->sub(new DateInterval('P7D'));
45
        $date2End->sub(new DateInterval('P7D'));
46
47
        $week = $date1Begin->format('W');
48
49
        $gamesData = $this->topGameProvider->getTop($date1Begin, $date1End, $date2Begin, $date2End, 20);
50
        $gamesHtmlEn = $this->getHtmlTopGame($gamesData, 'en');
51
        $gamesHtmlFr = $this->getHtmlTopGame($gamesData, 'fr');
52
53
        $playersData = $this->topPlayerProvider->getTop($date1Begin, $date1End, $date2Begin, $date2End, 20);
54
        $playersHtmlEn = $this->getHtmlTopPlayer($playersData, 'en');
55
        $playersHtmlFr = $this->getHtmlTopPlayer($playersData, 'fr');
56
57
        $textEn = $gamesHtmlEn . '<br /><br />' . $playersHtmlEn;
58
        $textFr = $gamesHtmlFr . '<br /><br />' . $playersHtmlFr;
59
60
        $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

60
        $this->writer->/** @scrutinizer ignore-call */ 
61
                       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...
61
            array(
62
                'en' => 'Top of week #' . $week,
63
                'fr' => 'Top de la semaine #' . $week,
64
            ),
65
            array(
66
                'en' => $textEn,
67
                'fr' => $textFr,
68
            )
69
        );
70
    }
71
}