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

CustomizedInteractionChecker::check()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.2162

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 5
nop 1
dl 0
loc 36
ccs 17
cts 24
cp 0.7083
crap 8.2162
rs 8.6186
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Lib\Interaction;
4
5
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...
6
use Stu\Lib\Information\InformationInterface;
7
use Stu\Lib\Interaction\Member\InteractionMemberInterface;
8
9
class CustomizedInteractionChecker implements CustomizedInteractionCheckerInterface
10
{
11
    private InteractionMemberInterface $source;
12
    private InteractionMemberInterface $target;
13
14
    /** @var array<InteractionCheckType> */
15
    private array $checkTypes;
16
17 15
    public function setSource(InteractionMemberInterface $source): void
18
    {
19 15
        $this->source = $source;
20
    }
21
22 15
    public function setTarget(InteractionMemberInterface $target): void
23
    {
24 15
        $this->target = $target;
25
    }
26
27
    /** @param array<InteractionCheckType> $checkTypes */
28 15
    public function setCheckTypes(array $checkTypes): void
29
    {
30 15
        $this->checkTypes = $checkTypes;
31
    }
32
33 15
    #[Override]
34
    public function check(InformationInterface $information): bool
35
    {
36 15
        $targetUser = $this->target->getUser();
37
        if (
38 15
            $this->shouldCheck(InteractionCheckType::EXPECT_TARGET_NO_VACATION)
39 15
            && $targetUser !== null
40 15
            && $targetUser->isVacationRequestOldEnough()
41
        ) {
42
            $information->addInformation(InteractionCheckType::EXPECT_TARGET_NO_VACATION->getReason());
43
            return false;
44
        }
45
46 15
        if ($this->source->getLocation() !== $this->target->getLocation()) {
47
            return false;
48
        }
49
50 15
        $refused = $this->source->canAccess(
51 15
            $this->target,
52 15
            fn(InteractionCheckType $checkType): bool => $this->shouldCheck($checkType)
53 15
        );
54 15
        if ($refused !== null) {
55
            $information->addInformation($refused->getReason());
56
            return false;
57
        }
58
59 15
        $refused = $this->target->canBeAccessedFrom(
60 15
            $this->source,
61 15
            fn(InteractionCheckType $checkType): bool => $this->shouldCheck($checkType)
62 15
        );
63 15
        if ($refused !== null) {
64
            $information->addInformation($refused->getReason());
65
            return false;
66
        }
67
68 15
        return true;
69
    }
70
71 15
    private function shouldCheck(InteractionCheckType $checkType): bool
72
    {
73 15
        return in_array($checkType, $this->checkTypes);
74
    }
75
}
76