Passed
Push — develop ( d39660...9ac627 )
by BENARD
18:52 queued 12:36
created

GameOfDayManager::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 13
rs 9.9
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Manager;
6
7
use Datetime;
8
use Doctrine\ORM\EntityManagerInterface;
9
use VideoGamesRecords\CoreBundle\Entity\Game;
10
use VideoGamesRecords\CoreBundle\Entity\GameDay;
11
12
class GameOfDayManager
13
{
14
    private EntityManagerInterface $em;
15
16
    public function __construct(EntityManagerInterface $em)
17
    {
18
        $this->em = $em;
19
    }
20
21
    /**
22
     * @return void
23
     */
24
    public function addTomorrowGame(): void
25
    {
26
        $tomorrow = new Datetime('tomorrow');
27
        $gameDay = $this->em->getRepository(GameDay::class)->findOneBy(array('day' => $tomorrow));
28
        if (!$gameDay) {
29
            $games = $this->em->getRepository(Game::class)->getIds();
30
            $rand_key = array_rand($games, 1);
31
            $game = $this->em->getRepository(Game::class)->findOneBy($games[$rand_key]);
32
            $gameDay = new GameDay();
33
            $gameDay->setGame($game);
34
            $gameDay->setDay($tomorrow);
35
            $this->em->persist($gameDay);
36
            $this->em->flush();
37
        }
38
    }
39
}
40