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

GameStrategy::process()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 2
nop 0
dl 0
loc 23
rs 9.7333
c 0
b 0
f 0
1
<?php
2
namespace VideoGamesRecords\DwhBundle\Manager\Strategy\Table;
3
4
use DateInterval;
5
use DateTime;
6
use Doctrine\ORM\OptimisticLockException;
7
use Exception;
8
use VideoGamesRecords\DwhBundle\Contracts\Strategy\TableStrategyInterface;
9
use VideoGamesRecords\DwhBundle\Entity\Game as DwhGame;
10
11
class GameStrategy extends AbstractTableManager implements TableStrategyInterface
12
{
13
14
    public function supports(string $name): bool
15
    {
16
        return $name === self::TYPE_GAME;
17
    }
18
19
    /**
20
     * @throws OptimisticLockException
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
        $games = $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

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