TrashQueryBehavior::withRemoved()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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