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

EmbeddedPrimaryKeyException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

3 Methods

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