Test Failed
Push — main ( 3531fe...1eb5c2 )
by Daniel
04:35
created

ArtistRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
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 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
    }
32
33 1
    public function findByMbId(string $mbid): ?ArtistInterface
34
    {
35 1
        return $this->findOneBy([
36 1
            'mbid' => $mbid,
37 1
        ]);
38
    }
39
40 1
    public function getAllHavingNoRelations(): iterable
41
    {
42 1
        return $this->getEntityManager()
43 1
            ->createQuery(
44 1
                <<<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 1
                    DQL
51 1
            )
52 1
            ->toIterable();
53
    }
54
55
    public function search(string $searchTerm): array
56
    {
57
        $qb = $this->getEntityManager()->createQueryBuilder();
58
59
        $qb
60
            ->select('a')
61
            ->from(Artist::class, 'a')
62
            ->where(
63
                $qb->expr()->like('a.title', ':searchTerm')
64
            )
65
            ->setParameter('searchTerm', sprintf('%%%s%%', $searchTerm))
66
        ;
67
68
        return $qb->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $qb->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
69
    }
70
}
71