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

PlayerStrategy::process()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 3
nop 0
dl 0
loc 25
rs 9.3888
c 0
b 0
f 0
1
<?php
2
namespace VideoGamesRecords\DwhBundle\Manager\Strategy\Table;
3
4
use DateInterval;
5
use DateTime;
6
use Exception;
7
use VideoGamesRecords\DwhBundle\Contracts\Strategy\TableStrategyInterface;
8
use VideoGamesRecords\DwhBundle\Entity\Player as DwhPlayer;
9
10
11
class PlayerStrategy extends AbstractTableManager implements TableStrategyInterface
12
{
13
14
    public function supports(string $name): bool
15
    {
16
        return $name === self::TYPE_PLAYER;
17
    }
18
19
20
    /**
21
     * @throws Exception
22
     */
23
    public function process(): void
24
    {
25
        $date1 = new DateTime();
26
        $date1->sub(new DateInterval('P1D'));
27
        $date2 = new DateTime();
28
29
        $data1 = $this->provider->getNbPostDay($date1, $date2);
30
        $data2 = $this->provider->getDataRank();
0 ignored issues
show
Bug introduced by
The method getDataRank() 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

30
        /** @scrutinizer ignore-call */ 
31
        $data2 = $this->provider->getDataRank();

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...
31
        $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

31
        /** @scrutinizer ignore-call */ 
32
        $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...
32
33
        foreach ($list as $row) {
34
            $idPlayer = $row['id'];
35
            $dwhPlayer = new DwhPlayer();
36
            $dwhPlayer->setDate($date1->format('Y-m-d'));
37
            $dwhPlayer->setFromArray($row);
38
            $dwhPlayer->setNbPostDay((isset($data1[$idPlayer])) ? $data1[$idPlayer] : 0);
39
            if (isset($data2[$idPlayer])) {
40
                foreach ($data2[$idPlayer] as $key => $value) {
41
                    $dwhPlayer->setChartRank($key, $value);
42
                }
43
            }
44
            $this->em->persist($dwhPlayer);
45
        }
46
47
        $this->em->flush();
48
    }
49
50
    /**
51
     * @throws Exception
52
     */
53
    public function purge(): void
54
    {
55
        $date = new DateTime();
56
        $date = $date->sub(DateInterval::createFromDateString('3 years'));
57
58
        //----- delete
59
        $query = $this->em->createQuery('DELETE VideoGamesRecords\DwhBundle\Entity\Player p WHERE p.date < :date');
60
        $query->setParameter('date', $date->format('Y-m-d'));
61
        $query->execute();
62
    }
63
}
64