EdgeConditionTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEdgeTypesOnly() 0 3 1
A onlyEdgeTypes() 0 4 1
A isSuitableEdge() 0 11 4
A excludeEdgeTypes() 0 4 1
A getEdgeTypesExcluded() 0 3 1
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