Test Failed
Push — master ( f74f09...dc3255 )
by Petr
02:47
created

ColumnsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isColumnNameFromBasic() 0 6 1
A isColumnNameFromTree() 0 8 1
A translateColumn() 0 10 1
1
<?php
2
3
namespace kalanis\nested_tree\Support;
4
5
/**
6
 * Trait to work with names of properties within Node class which shall not be added / updated via this package.
7
 */
8
trait ColumnsTrait
9
{
10
    protected function translateColumn(TableSettings $settings, string $name) : string
11
    {
12
        return match ($name) {
13
            'id' => $settings->idColumnName,
14
            'parentId' => $settings->parentIdColumnName,
15
            'level' => $settings->levelColumnName,
16
            'left' => $settings->leftColumnName,
17
            'right' => $settings->rightColumnName,
18
            'position' => $settings->positionColumnName,
19
            default => $name,
20
        };
21
    }
22
23
    protected function isColumnNameFromBasic(string $name) : bool
24
    {
25
        return in_array($name, [
26
            'id',
27
            'childrenIds',
28
            'childrenNodes',
29
        ]);
30
    }
31
32
    protected function isColumnNameFromTree(string $name) : bool
33
    {
34
        return in_array($name, [
35
            'parentId',
36
            'left',
37
            'right',
38
            'level',
39
            'position',
40
        ]);
41
    }
42
}
43