WrongDiscriminatorColumnException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolution() 0 8 1
A getName() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Exception\TableInheritance;
6
7
use Cycle\Schema\Definition\Entity;
8
use Cycle\Schema\Exception\TableInheritanceException;
9
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
10
11
class WrongDiscriminatorColumnException extends TableInheritanceException implements FriendlyExceptionInterface
12
{
13 4
    public function __construct(private Entity $entity, string $discriminatorColumn)
14
    {
15 4
        parent::__construct(sprintf(
16 4
            'Discriminator column `%s` is not found among fields of the `%s` role.',
17
            $discriminatorColumn,
18 4
            (string) ($this->entity->getRole() ?? $this->entity->getClass()),
19
        ));
20 4
    }
21
22 2
    public function getName(): string
23
    {
24 2
        return 'Discriminator column is not found among the entity fields.';
25
    }
26
27 2
    public function getSolution(): ?string
28
    {
29 2
        $fields = implode('`, `', $this->entity->getFields()->getNames());
30
31 2
        return sprintf(
32 2
            'You have to specify one of the defined fields of the `%s` role: `%s`',
33 2
            (string) ($this->entity->getRole() ?? $this->entity->getClass()),
34
            $fields,
35
        );
36
    }
37
}
38