LoopTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getEdgeSet() 0 1 ?
A hasLoop() 0 10 3
A hasLoopOn() 0 13 4
1
<?php
2
3
/*
4
 * This file is part of the bisarca/graph package.
5
 *
6
 * (c) Emanuele Minotto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bisarca\Graph\Graph\Descriptor;
13
14
use Bisarca\Graph\Edge\Set;
15
use Bisarca\Graph\Vertex\VertexInterface;
16
17
trait LoopTrait
18
{
19
    /**
20
     * Gets the edges set.
21
     *
22
     * @return Set
23
     */
24
    abstract public function getEdgeSet(): Set;
25
26
    /**
27
     * Checks if the graph has an edge that is a loop.
28
     *
29
     * @return bool
30
     */
31
    public function hasLoop(): bool
32
    {
33
        $loop = false;
34
35
        foreach ($this->getEdgeSet() as $edge) {
36
            $loop = $loop || $edge->isLoop();
37
        }
38
39
        return $loop;
40
    }
41
42
    /**
43
     * Checks if the graph has an edge that is a loop and with a vertex $vertex.
44
     *
45
     * @param VertexInterface $vertex
46
     *
47
     * @return bool
48
     */
49
    public function hasLoopOn(VertexInterface $vertex): bool
50
    {
51
        $loop = false;
52
53
        foreach ($this->getEdgeSet() as $edge) {
54
            $loop = $loop || (
55
                $edge->isLoop() &&
56
                $vertex === $edge->getVertexStart()
57
            );
58
        }
59
60
        return $loop;
61
    }
62
}
63