EdgeConditionTrait::isSuitableEdge()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Smoren\GraphTools\Conditions\Traits;
4
5
use Smoren\GraphTools\Conditions\EdgeCondition;
6
use Smoren\GraphTools\Conditions\FilterCondition;
7
use Smoren\GraphTools\Conditions\Interfaces\EdgeConditionInterface;
8
use Smoren\GraphTools\Models\Interfaces\EdgeInterface;
9
10
/**
11
 * Trait for edge condition implementation
12
 * @implements EdgeConditionInterface<mixed>
13
 * @property array<string>|null $edgeTypesOnly edge types whitelist
14
 * @property array<string> $edgeTypesExclude edge types blacklist
15
 */
16
trait EdgeConditionTrait
17
{
18
    /**
19
     * @inheritDoc
20
     */
21
    public function getEdgeTypesOnly(): ?array
22
    {
23
        return $this->edgeTypesOnly;
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function getEdgeTypesExcluded(): array
30
    {
31
        return $this->edgeTypesExclude;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function onlyEdgeTypes(?array $types): self
38
    {
39
        $this->edgeTypesOnly = $types;
40
        return $this;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function excludeEdgeTypes(array $types): self
47
    {
48
        $this->edgeTypesExclude = $types;
49
        return $this;
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function isSuitableEdge(EdgeInterface $edge): bool
56
    {
57
        if($this->edgeTypesOnly !== null && !in_array($edge->getType(), $this->edgeTypesOnly)) {
58
            return false;
59
        }
60
61
        if(in_array($edge->getType(), $this->edgeTypesExclude)) {
62
            return false;
63
        }
64
65
        return true;
66
    }
67
}
68