TrashQueryBehavior   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A findRemoved() 0 3 1
A onlyRemoved() 0 4 1
A filterRemoved() 0 6 1
A withRemoved() 0 5 1
A onlyActive() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: vadim
5
 * Date: 01.05.15
6
 * Time: 17:49
7
 */
8
9
namespace sibds\behaviors;
10
11
12
use yii\behaviors\AttributeBehavior;
13
use yii\helpers\ArrayHelper;
14
15
/**
16
 * Class TrashQuery
17
 * @package sibds\behaviors
18
 * @since 0.1
19
 */
20
class TrashQueryBehavior extends AttributeBehavior
21
{
22
    public $showRemoved = false;
23
24
    public function findRemoved() {
25
        return $this->filterRemoved($this->showRemoved);
26
    }
27
28
    public function onlyRemoved() {
29
        $this->showRemoved = true;
30
        return $this->findRemoved();
31
    }
32
33
    public function withRemoved() {
34
        $model = new $this->owner->modelClass();
35
36
        return $this->owner->where([$model->trashAttribute()=>[$model->removedFlag,$model->restoredFlag]]);
37
    }
38
39
    public function onlyActive() {
40
        $this->showRemoved = false;
41
        return $this->findRemoved();
42
    }
43
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
    public function events(){
45
        return [
46
            ActiveQuery::EVENT_INIT => 'filterRemoved',
47
        ];
48
    }
49
    */
50
    public function filterRemoved($removed = false) {
51
        $model = new $this->owner->modelClass();
52
53
        return $this->owner->where($model->fullTrashAttribute($removed));
54
        //return $this->owner;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
    }
56
57
58
} 
59