DiscriminatorColumnNotPresentException   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 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolution() 0 9 1
A getName() 0 3 1
A __construct() 0 5 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 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