Passed
Push — master ( 8c69d0...3339fd )
by Nico
10:13 queued 05:04
created

AllianceRelationWrapper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 5%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 43
ccs 1
cts 20
cp 0.05
rs 10
c 0
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A getDate() 0 3 1
A getDescription() 0 18 4
A __construct() 0 1 1
A hasText() 0 3 1
A getId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Alliance\Lib;
6
7
use Stu\Component\Alliance\Enum\AllianceRelationTypeEnum;
8
use Stu\Orm\Entity\Alliance;
9
use Stu\Orm\Entity\AllianceRelation;
10
11
final class AllianceRelationWrapper
12
{
13 1
    public function __construct(private Alliance $alliance, private AllianceRelation $relation) {}
14
15
    public function getDescription(): string
16
    {
17
        $typeDescription = $this->relation->getType()->getDescription();
18
        $toName = $this->relation->getOpponent()->getName();
19
        $fromName = $this->relation->getAlliance()->getName();
20
21
        if ($this->relation->getType() === AllianceRelationTypeEnum::VASSAL) {
22
            if ($this->relation->getAlliance()->getId() === $this->alliance->getId()) {
23
                return sprintf('Hat die Allianz %s als %s', $toName, $typeDescription);
24
            } else {
25
                return sprintf('Ist %s der Allianz %s', $typeDescription, $fromName);
26
            }
27
        }
28
29
        if ($this->relation->getAlliance()->getId() === $this->alliance->getId()) {
30
            return sprintf('%s mit %s', $typeDescription, $toName);
31
        } else {
32
            return sprintf('%s mit %s', $typeDescription, $fromName);
33
        }
34
    }
35
36
    public function getDate(): int
37
    {
38
        return $this->relation->getDate();
39
    }
40
41
    public function getType(): AllianceRelationTypeEnum
42
    {
43
        return $this->relation->getType();
44
    }
45
46
    public function getId(): int
47
    {
48
        return $this->relation->getId();
49
    }
50
51
    public function hasText(): bool
52
    {
53
        return $this->relation->hasText();
54
    }
55
}
56