Passed
Push — master ( 8387eb...5a11dc )
by Janko
07:59
created

AllianceRelationWrapper::getImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 8
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