Test Failed
Push — main ( 0fa7eb...e933de )
by Daniel
04:22
created

ArtistRepository::getAllHavingNoRelations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 13
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
use Uxmp\Core\Orm\Model\Artist;
9
use Uxmp\Core\Orm\Model\ArtistInterface;
10
11
/**
12
 * @extends EntityRepository<ArtistInterface>
13
 */
14
final class ArtistRepository extends EntityRepository implements ArtistRepositoryInterface
15
{
16 1
    public function prototype(): ArtistInterface
17
    {
18 1
        return new Artist();
19
    }
20
21 1
    public function save(ArtistInterface $artist): void
22
    {
23 1
        $this->getEntityManager()->persist($artist);
24 1
        $this->getEntityManager()->flush();
25
    }
26
27 1
    public function delete(ArtistInterface $artist): void
28
    {
29 1
        $this->getEntityManager()->remove($artist);
30 1
        $this->getEntityManager()->flush();
31 1
    }
32
33
    public function findByMbId(string $mbid): ?ArtistInterface
34
    {
35
        return $this->findOneBy([
36
            'mbid' => $mbid,
37
        ]);
38
    }
39
40
    public function getAllHavingNoRelations(): iterable
41
    {
42
        return $this->getEntityManager()
43
            ->createQuery(
44
                <<<DQL
45
                    SELECT artist
46
                    FROM Uxmp\Core\Orm\Model\Artist artist
47
                    LEFT JOIN Uxmp\Core\Orm\Model\Album album
48
                    WITH album.artist_id = artist.id
49
                    GROUP BY artist HAVING COUNT(album.id) = 0
50
                    DQL
51
            )
52
            ->toIterable();
53
    }
54
}
55