EmbeddedPrimaryKeyException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 20
ccs 3
cts 7
cp 0.4286
rs 10
c 1
b 0
f 0
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 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