WrongParentKeyColumnException::getSolution()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 5
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 WrongParentKeyColumnException extends TableInheritanceException implements FriendlyExceptionInterface
12
{
13 4
    public function __construct(private Entity $entity, string $outerKey)
14
    {
15 4
        parent::__construct(sprintf(
16 4
            'Outer key column `%s` is not found among fields of the `%s` role.',
17
            $outerKey,
18 4
            (string) ($this->entity->getRole() ?? $this->entity->getClass()),
19
        ));
20 4
    }
21
22 2
    public function getName(): string
23
    {
24 2
        return 'Outer key column is not found among parent 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