Passed
Push — dev ( 7b7516...069b9a )
by Janko
06:38
created

GameTurnRepository::truncateAllGameTurns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Stu\Orm\Entity\GameTurn;
9
use Stu\Orm\Entity\GameTurnInterface;
10
11
/**
12
 * @extends EntityRepository<GameTurn>
13
 */
14
final class GameTurnRepository extends EntityRepository implements GameTurnRepositoryInterface
15
{
16
    public function getCurrent(): ?GameTurnInterface
17
    {
18
        return $this->findOneBy(
19
            [],
20
            ['turn' => 'desc']
21
        );
22
    }
23
24
    public function prototype(): GameTurnInterface
25
    {
26
        return new GameTurn();
27
    }
28
29
    public function save(GameTurnInterface $turn): void
30
    {
31
        $em = $this->getEntityManager();
32
33
        $em->persist($turn);
34
        $em->flush();
35
    }
36
37
    public function delete(GameTurnInterface $turn): void
38
    {
39
        $em = $this->getEntityManager();
40
41
        $em->remove($turn);
42
    }
43
44
    public function truncateAllGameTurns(): void
45
    {
46
        $this->getEntityManager()->createQuery(
47
            sprintf(
48
                'DELETE FROM %s gt',
49
                GameTurn::class
50
            )
51
        )->execute();
52
    }
53
}
54