LoopTrait::isLoop()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 3
nop 0
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\Edge\Descriptor;
13
14
use Bisarca\Graph\Vertex\VertexInterface;
15
16
trait LoopTrait
17
{
18
    /**
19
     * Checks if the edge has a starting vertex.
20
     *
21
     * @return bool
22
     */
23
    abstract public function hasVertexStart(): bool;
24
25
    /**
26
     * Gets the starting vertex.
27
     *
28
     * @return VertexInterface
29
     */
30
    abstract public function getVertexStart(): VertexInterface;
31
32
    /**
33
     * Checks if the edge has an ending vertex.
34
     *
35
     * @return bool
36
     */
37
    abstract public function hasVertexEnd(): bool;
38
39
    /**
40
     * Gets the ending vertex.
41
     *
42
     * @return VertexInterface
43
     */
44
    abstract public function getVertexEnd(): VertexInterface;
45
46
    /**
47
     * Checks if the edge is a loop.
48
     *
49
     * @return bool
50
     */
51
    public function isLoop(): bool
52
    {
53
        return $this->hasVertexStart() && $this->hasVertexEnd() &&
54
            $this->getVertexStart() === $this->getVertexEnd();
55
    }
56
}
57