Passed
Pull Request — master (#24)
by Aleksei
03:22
created

EmbeddedPrimaryKeyException::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Exception\FieldException;
6
7
use Cycle\Schema\Definition\Entity;
8
use Cycle\Schema\Exception\FieldException;
9
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
10
11
final class EmbeddedPrimaryKeyException extends FieldException implements FriendlyExceptionInterface
12
{
13
14
    public function __construct(Entity $embed, string $fieldName)
15
    {
16
        parent::__construct("Entity `{$embed->getRole()}` has conflicted field `{$fieldName}`.");
17
    }
18
19
    public function getName(): string
20
    {
21
        return 'Embedded entity primary key collision';
22
    }
23
24
    public function getSolution(): ?string
25
    {
26
        return "The primary key of the composite entity must be projected onto the embedded entity.\n"
27
            . "However, the embedded entity already has a field with the same name.\n\n"
28
            . "Possible solutions:\n"
29
            . "- If the conflicting field applies only to an embedded entity, then rename it.\n"
30
            . '- If you want to receive the primary key value of a composite entity in this field,'
31
            . ' then remove its definition from the column list in the schema.';
32
    }
33
}
34