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

AllianceRelationWrapper::hasText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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