TeamStrategy::process()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 2
nop 0
dl 0
loc 19
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\Manager\Strategy\Table;
6
7
use DateInterval;
8
use DateTime;
9
use Exception;
10
use VideoGamesRecords\DwhBundle\Contracts\Strategy\TableStrategyInterface;
11
use VideoGamesRecords\DwhBundle\Entity\Team as DwhTeam;
12
13
class TeamStrategy extends AbstractTableManager implements TableStrategyInterface
14
{
15
    public function supports(string $name): bool
16
    {
17
        return $name === self::TYPE_TEAM;
18
    }
19
20
21
    /**
22
     * @throws Exception
23
     */
24
    public function process(): void
25
    {
26
        $date1 = new DateTime();
27
        $date1->sub(new DateInterval('P1D'));
28
        $date2 = new DateTime();
29
30
        $data1 = $this->provider->getNbPostDay($date1, $date2);
31
        $list = $this->provider->getData();
32
33
        foreach ($list as $row) {
34
            $idTeam = $row['id'];
35
            $dwhTeam = new DwhTeam();
36
            $dwhTeam->setDate($date1->format('Y-m-d'));
37
            $dwhTeam->setFromArray($row);
38
            $dwhTeam->setNbPostDay((isset($data1[$idTeam])) ? $data1[$idTeam] : 0);
39
            $this->em->persist($dwhTeam);
40
        }
41
42
        $this->em->flush();
43
    }
44
45
    /**
46
     * @throws Exception
47
     */
48
    public function purge(): void
49
    {
50
        $date = new DateTime();
51
        $date = $date->sub(DateInterval::createFromDateString('3 years'));
52
53
        //----- delete
54
        $query = $this->em->createQuery('DELETE VideoGamesRecords\DwhBundle\Entity\Team t WHERE t.date < :date');
55
        $query->setParameter('date', $date->format('Y-m-d'));
56
        $query->execute();
57
    }
58
}
59