HierarchicalTerm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 23
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
getParent() 0 1 ?
hasParent() 0 1 ?
getChildren() 0 1 ?
hasChildren() 0 1 ?
A detectLoop() 0 14 4
1
<?php
2
3
namespace nkostadinov\taxonomy\components\terms;
4
5
/**
6
 * @author ntraykov
7
 */
8
abstract class HierarchicalTerm extends BaseTerm
9
{
10
    protected function detectLoop($parent, $child)
11
    {
12
        if ($parent === $child) {
13
            return true;
14
        }
15
16
        foreach ($this->getChildren($child) as $grandChild) {
17
            if ($this->detectLoop($parent, $grandChild)) {
18
                return true;
19
            }
20
        }
21
22
        return false;
23
    }
24
25
    abstract public function getParent($term);
26
    abstract public function hasParent($term);
27
28
    abstract public function getChildren($term);
29
    abstract public function hasChildren($term);
30
}
31