EmbeddedPrimaryKeyException::__construct()   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 2
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\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 8
    public function __construct(Entity $embed, string $fieldName)
14
    {
15 8
        parent::__construct("Entity `{$embed->getRole()}` has conflicted field `{$fieldName}`.");
16 8
    }
17
18
    public function getName(): string
19
    {
20
        return 'Embedded entity primary key collision';
21
    }
22
23
    public function getSolution(): ?string
24
    {
25
        return "The primary key of the composite entity must be projected onto the embedded entity.\n"
26
            . "However, the embedded entity already has a field with the same name.\n\n"
27
            . "Possible solutions:\n"
28
            . "- If the conflicting field applies only to an embedded entity, then rename it.\n"
29
            . '- If you want to receive the primary key value of a composite entity in this field,'
30
            . ' then remove its definition from the column list in the schema.';
31
    }
32
}
33