Passed
Pull Request — master (#1823)
by Nico
30:25
created

PlayerRelationDeterminator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isFriend() 0 13 3
A isEnemy() 0 13 3
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