Oauth2EnabledQueryTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A enabled() 0 15 3
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\models\queries\traits;
4
5
use rhertogh\Yii2Oauth2Server\interfaces\models\base\Oauth2ActiveRecordInterface;
6
use yii\db\ActiveQuery;
7
8
trait Oauth2EnabledQueryTrait
9
{
10
    /**
11
     * @inheritDoc
12
     */
13 5
    public function enabled($enabled = true)
14
    {
15
        /** @var ActiveQuery|mixed $this */
16 5
        if (!is_null($enabled)) {
17 5
            if (is_null($this->from)) {
18
                /** @var Oauth2ActiveRecordInterface $modelClass */
19 4
                $modelClass = $this->modelClass;
20 4
                $table = $modelClass::tableName();
21
            } else {
22 1
                $table = array_key_first($this->from);
23
            }
24 5
            $this->andWhere([ "$table.enabled" => $enabled]);
25
        }
26
27 5
        return $this;
28
    }
29
}
30