Passed
Branch develop (21f7ca)
by BENARD
04:27
created

TeamStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 3
A supports() 0 3 1
A purge() 0 9 1
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\Manager\Strategy\Table;
4
5
use DateInterval;
6
use DateTime;
7
use Exception;
8
use VideoGamesRecords\DwhBundle\Contracts\Strategy\TableStrategyInterface;
9
use VideoGamesRecords\DwhBundle\Entity\Team as DwhTeam;
10
11
class TeamStrategy extends AbstractTableManager implements TableStrategyInterface
12
{
13
    public function supports(string $name): bool
14
    {
15
        return $name === self::TYPE_TEAM;
16
    }
17
18
19
    /**
20
     * @throws Exception
21
     */
22
    public function process(): void
23
    {
24
        $date1 = new DateTime();
25
        $date1->sub(new DateInterval('P1D'));
26
        $date2 = new DateTime();
27
28
        $data1 = $this->provider->getNbPostDay($date1, $date2);
29
        $list = $this->provider->getDataForDwh();
0 ignored issues
show
Bug introduced by
The method getDataForDwh() does not exist on VideoGamesRecords\DwhBun...r\CoreProviderInterface. Did you maybe mean getData()? ( Ignorable by Annotation )

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

29
        /** @scrutinizer ignore-call */ 
30
        $list = $this->provider->getDataForDwh();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        foreach ($list as $row) {
32
            $idTeam = $row['id'];
33
            $dwhTeam = new DwhTeam();
34
            $dwhTeam->setDate($date1->format('Y-m-d'));
35
            $dwhTeam->setFromArray($row);
36
            $dwhTeam->setNbPostDay((isset($data1[$idTeam])) ? $data1[$idTeam] : 0);
37
            $this->em->persist($dwhTeam);
38
        }
39
40
        $this->em->flush();
41
    }
42
43
    /**
44
     * @throws Exception
45
     */
46
    public function purge(): void
47
    {
48
        $date = new DateTime();
49
        $date = $date->sub(DateInterval::createFromDateString('3 years'));
50
51
        //----- delete
52
        $query = $this->em->createQuery('DELETE VideoGamesRecords\DwhBundle\Entity\Team t WHERE t.date < :date');
53
        $query->setParameter('date', $date->format('Y-m-d'));
54
        $query->execute();
55
    }
56
}
57