Passed
Pull Request — master (#1821)
by Nico
52:02 queued 25:23
created

PlayerRelationDeterminator::isEnemy()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Player\Relation;
6
7
use Stu\Orm\Entity\UserInterface;
8
9
/**
10
 * Some locations require to determine if a certain user is friendly towards the player
11
 */
12
final class PlayerRelationDeterminator implements PlayerRelationDeterminatorInterface
13
{
14 14
    public function __construct(
15
        private FriendDeterminator $friendDeterminator,
16
        private EnemyDeterminator $enemyDeterminator
17
    ) {
18 14
    }
19
20 7
    public function isFriend(UserInterface $user, UserInterface $otherUser): bool
21
    {
22 7
        $friendRelation = $this->friendDeterminator->isFriend($user, $otherUser);
23 7
        if ($friendRelation->isDominant()) {
24 2
            return true;
25
        }
26
27 5
        $enemyRelation = $this->enemyDeterminator->isEnemy($user, $otherUser);
28 5
        if ($enemyRelation->isDominant()) {
29 2
            return false;
30
        }
31
32 3
        return $friendRelation !== PlayerRelationTypeEnum::NONE;
33
    }
34
35 7
    public function isEnemy(UserInterface $user, UserInterface $otherUser): bool
36
    {
37 7
        $enemyRelation = $this->enemyDeterminator->isEnemy($user, $otherUser);
38 7
        if ($enemyRelation->isDominant()) {
39 2
            return true;
40
        }
41
42 5
        $friendRelation = $this->friendDeterminator->isFriend($user, $otherUser);
43 5
        if ($friendRelation->isDominant()) {
44 2
            return false;
45
        }
46
47 3
        return $enemyRelation !== PlayerRelationTypeEnum::NONE;
48
    }
49
}
50