Passed
Push — master ( e661f4...30021e )
by Nico
25:16 queued 10:59
created

PlayerRelationDeterminator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Player\Relation;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Orm\Entity\UserInterface;
9
10
/**
11
 * Some locations require to determine if a certain user is friendly towards the player
12
 */
13
final class PlayerRelationDeterminator implements PlayerRelationDeterminatorInterface
14
{
15 16
    public function __construct(
16
        private FriendDeterminator $friendDeterminator,
17
        private EnemyDeterminator $enemyDeterminator
18 16
    ) {}
19
20 21
    #[Override]
21
    public function isFriend(?UserInterface $user, ?UserInterface $otherUser): bool
22
    {
23 21
        if ($user === null || $otherUser === null) {
24
            return false;
25
        }
26
27 21
        if ($user === $otherUser) {
28 13
            return true;
29
        }
30
31 8
        $friendRelation = $this->friendDeterminator->isFriend($user, $otherUser);
32 8
        if ($friendRelation->isDominant()) {
33 2
            return true;
34
        }
35
36 6
        $enemyRelation = $this->enemyDeterminator->isEnemy($user, $otherUser);
37 6
        if ($enemyRelation->isDominant()) {
38 2
            return false;
39
        }
40
41 4
        return $friendRelation !== PlayerRelationTypeEnum::NONE;
42
    }
43
44 7
    #[Override]
45
    public function isEnemy(UserInterface $user, UserInterface $otherUser): bool
46
    {
47 7
        $enemyRelation = $this->enemyDeterminator->isEnemy($user, $otherUser);
48 7
        if ($enemyRelation->isDominant()) {
49 2
            return true;
50
        }
51
52 5
        $friendRelation = $this->friendDeterminator->isFriend($user, $otherUser);
53 5
        if ($friendRelation->isDominant()) {
54 2
            return false;
55
        }
56
57 3
        return $enemyRelation !== PlayerRelationTypeEnum::NONE;
58
    }
59
}
60