Passed
Push — main ( 48955e...53f2e5 )
by Daniel
04:08
created

GenreMapRepository::deleteByAlbum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 14
ccs 13
cts 13
cp 1
rs 9.9
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use JetBrains\PhpStorm\Pure;
9
use Uxmp\Core\Orm\Model\AlbumInterface;
10
use Uxmp\Core\Orm\Model\GenreMap;
11
use Uxmp\Core\Orm\Model\GenreMapEnum;
12
use Uxmp\Core\Orm\Model\GenreMapInterface;
13
14
/**
15
 * @extends EntityRepository<GenreMap>
16
 *
17
 * @method null|GenreMapInterface findOneBy(mixed[] $criteria)
18
 */
19
final class GenreMapRepository extends EntityRepository implements GenreMapRepositoryInterface
20
{
21 1
    #[Pure]
22
    public function prototype(): GenreMapInterface
23
    {
24 1
        return new GenreMap();
25
    }
26
27 1
    public function save(GenreMapInterface $genreMap): void
28
    {
29 1
        $this->getEntityManager()->persist($genreMap);
30 1
        $this->getEntityManager()->flush();
31
    }
32
33 1
    public function delete(GenreMapInterface $genreMap): void
34
    {
35 1
        $this->getEntityManager()->remove($genreMap);
36 1
        $this->getEntityManager()->flush();
37
    }
38
39
    /**
40
     * @return iterable<GenreMapInterface>
41
     */
42 1
    public function findByAlbum(AlbumInterface $album): iterable
43
    {
44 1
        return $this->findBy([
45 1
            'mapped_item_type' => GenreMapEnum::ALBUM,
46 1
            'mapped_item_id' => $album->getId(),
47 1
        ]);
48
    }
49
50 1
    public function deleteByAlbum(AlbumInterface $album): void
51
    {
52 1
        $this
53 1
            ->getEntityManager()
54 1
            ->createQueryBuilder()
55 1
            ->delete(GenreMap::class, 'gm')
56 1
            ->where('gm.mapped_item_type = :itemType')
57 1
            ->andWhere('gm.mapped_item_id = :itemId')
58 1
            ->setParameters([
59 1
                'itemType' => GenreMapEnum::ALBUM,
60 1
                'itemId' => $album->getId(),
61 1
            ])
62 1
            ->getQuery()
63 1
            ->execute();
64
    }
65
}
66