HierarchicalTerm::hasParent()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
nc 1
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