NodeAlNi   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 46
loc 46
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 4 4 1
A find() 4 4 1
A behaviors() 13 13 1
A transactions() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @link https://github.com/paulzi/yii2-auto-tree
4
 * @copyright Copyright (c) 2015 PaulZi <[email protected]>
5
 * @license MIT (https://github.com/paulzi/yii2-auto-tree/blob/master/LICENSE)
6
 */
7
8
namespace paulzi\autotree\tests\models;
9
10
use paulzi\adjacencyList\AdjacencyListBehavior;
11
use paulzi\nestedintervals\NestedIntervalsBehavior;
12
use paulzi\autotree\AutoTreeTrait;
13
14
/**
15
 * @author PaulZi <[email protected]>
16
 *
17
 * @property integer $id
18
 * @property integer $parent_id
19
 * @property integer $sort
20
 * @property integer $tree
21
 * @property integer $lft
22
 * @property integer $rgt
23
 * @property integer $depth
24
 * @property string $path
25
 * @property string $slug
26
 *
27
 * @property NodeAlNi[] $parents
28
 * @property NodeAlNi $parent
29
 * @property NodeAlNi $root
30
 * @property NodeAlNi[] $descendants
31
 * @property NodeAlNi[] $children
32
 * @property NodeAlNi[] $leaves
33
 * @property NodeAlNi $prev
34
 * @property NodeAlNi $next
35
 *
36
 * @method static NodeAlNi|null findOne() findOne($condition)
37
 *
38
 * @mixin AdjacencyListBehavior
39
 * @mixin NestedIntervalsBehavior
40
 */
41 View Code Duplication
class NodeAlNi extends \yii\db\ActiveRecord
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
{
43
    use AutoTreeTrait;
44
45
    /**
46
     * @inheritdoc
47
     */
48 21
    public static function tableName()
49
    {
50 21
        return '{{%tree}}';
51
    }
52
    /**
53
     * @inheritdoc
54
     */
55 21
    public function behaviors()
56
    {
57
        return [
58
            [
59 21
                'class'         => AdjacencyListBehavior::className(),
60
                'sortable'      => false,
61
            ],
62
            [
63 21
                'class'         => NestedIntervalsBehavior::className(),
64 21
                'treeAttribute' => 'tree',
65
            ],
66
        ];
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 10
    public function transactions()
73
    {
74
        return [
75 10
            self::SCENARIO_DEFAULT => self::OP_ALL,
76
        ];
77
    }
78
79
    /**
80
     * @return NodeQuery
81
     */
82 21
    public static function find()
83
    {
84 21
        return new NodeQuery(get_called_class());
85
    }
86
}