ScoreInvestigationHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
c 0
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getScoreToDesactivate() 0 14 1
A __construct() 0 3 1
A handle() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Handler;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Exception\ORMException;
9
use VideoGamesRecords\CoreBundle\Entity\PlayerChart;
10
use VideoGamesRecords\CoreBundle\Entity\PlayerChartStatus;
11
12
class ScoreInvestigationHandler
13
{
14
    protected EntityManagerInterface $em;
15
16
    public function __construct(EntityManagerInterface $em)
17
    {
18
        $this->em = $em;
19
    }
20
21
    /**
22
     * @throws ORMException
23
     */
24
    public function handle(): void
25
    {
26
        $list = $this->getScoreToDesactivate();
27
        $statut = $this->em->getReference(
28
            'VideoGamesRecords\CoreBundle\Entity\PlayerChartStatus',
29
            PlayerChartStatus::ID_STATUS_NOT_PROOVED
30
        );
31
        /** @var PlayerChart $playerChart */
32
        foreach ($list as $playerChart) {
33
            $playerChart->setStatus($statut);
34
        }
35
        $this->em->flush();
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    private function getScoreToDesactivate(): array
42
    {
43
        $date = new \DateTime();
44
        $date->sub(new \DateInterval('P14D'));
45
46
        $query = $this->em->createQueryBuilder()
47
            ->select('pc')
48
            ->from('VideoGamesRecords\CoreBundle\Entity\PlayerChart', 'pc')
49
            ->where('pc.status = :idStatus')
50
            ->setParameter('idStatus', PlayerChartStatus::ID_STATUS_INVESTIGATION)
51
            ->andWhere('pc.dateInvestigation < :date')
52
            ->setParameter('date', $date->format('Y-m-d'));
53
        return $query->getQuery()
54
            ->getResult();
55
    }
56
}
57