DiscriminatorColumnNotPresentException::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 DiscriminatorColumnNotPresentException extends TableInheritanceException implements FriendlyExceptionInterface
12
{
13 4
    public function __construct(private Entity $entity)
14
    {
15 4
        parent::__construct(sprintf(
16 4
            'Discriminator column for the `%s` role should be defined.',
17 4
            (string) ($this->entity->getRole() ?? $this->entity->getClass()),
18
        ));
19 4
    }
20
21 2
    public function getName(): string
22
    {
23 2
        return 'Discriminator column is not present.';
24
    }
25
26 2
    public function getSolution(): ?string
27
    {
28 2
        $fields = implode('`, `', $this->entity->getFields()->getNames());
29
30 2
        return sprintf(
31 2
            "Discriminator column is required for Single Table Inheritance schema.\n" .
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