Passed
Push — develop ( 716d59...3a1959 )
by David
14:24
created

Artist::setName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Repository\ArtistRepository;
8
use Doctrine\ORM\Mapping as ORM;
9
use Ecodev\Felix\Api\Exception;
10
11
/**
12
 * An artist.
13
 */
14
#[ORM\UniqueConstraint(name: 'unique_name', columns: ['name'])]
15
#[ORM\Entity(ArtistRepository::class)]
16
class Artist extends Thesaurus
17
{
18
    public function setName(string $name): void
19
    {
20
        /** @var ArtistRepository $artistRepository */
21
        $artistRepository = _em()->getRepository(self::class);
22
23
        $exists = $artistRepository->findOneBy(['name' => $name]);
24
        if ($exists && $exists->getId() !== $this->getId()) {
25
            throw new Exception('Le nom de cet artiste existe déjà.');
26
        }
27
        parent::setName($name);
28
    }
29
}
30