TopCreator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 31 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\Creator;
6
7
use Datetime;
8
use DateInterval;
9
use Exception;
10
use VideoGamesRecords\DwhBundle\Contracts\DwhInterface;
11
use VideoGamesRecords\DwhBundle\DataProvider\TopProvider;
12
use VideoGamesRecords\DwhBundle\Traits\Top\GetHtmlTopTrait;
13
14
class TopCreator implements DwhInterface
15
{
16
    use GetHtmlTopTrait;
17
18
    protected TopProvider $topProvider;
19
    protected string $interval;
20
    protected int $nbElement;
21
22
    public function __construct(
23
        TopProvider $topProvider,
24
        string $interval,
25
        int $nbElement
26
    ) {
27
        $this->topProvider = $topProvider;
28
        $this->interval = $interval;
29
        $this->nbElement = $nbElement;
30
    }
31
32
    /**
33
     * @param $day
34
     * @return string[]
35
     * @throws Exception
36
     */
37
    public function handle($day): array
38
    {
39
        $date1Begin = new DateTime($day);
40
        $date1End = new DateTime($day);
41
42
        $date1End->sub(new DateInterval('P1D'));
43
        $date1Begin->sub(new DateInterval($this->interval));
44
45
        $date2Begin = clone($date1Begin);
46
        $date2End = clone($date1End);
47
48
        $date2Begin->sub(new DateInterval($this->interval));
49
        $date2End->sub(new DateInterval($this->interval));
50
51
52
        $gamesData = $this->topProvider->getStrategy(self::TYPE_GAME)
53
            ->getTop($date1Begin, $date1End, $date2Begin, $date2End, $this->nbElement);
54
        $gamesHtmlEn = $this->getHtmlTopGame($gamesData);
55
        $gamesHtmlFr = $this->getHtmlTopGame($gamesData, 'fr');
56
57
        $playersData = $this->topProvider->getStrategy(self::TYPE_PLAYER)
58
            ->getTop($date1Begin, $date1End, $date2Begin, $date2End, $this->nbElement);
59
        $playersHtmlEn = $this->getHtmlTopPlayer($playersData);
60
        $playersHtmlFr = $this->getHtmlTopPlayer($playersData, 'fr');
61
62
        $textEn = $gamesHtmlEn . '<br /><br />' . $playersHtmlEn;
63
        $textFr = $gamesHtmlFr . '<br /><br />' . $playersHtmlFr;
64
65
        return [
66
            'fr' => $textFr,
67
            'en' => $textEn
68
        ];
69
    }
70
}
71