SlugAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 2
1
<?php
2
3
namespace zacksleo\yii2\ad\actions;
4
5
use yii\base\Action;
6
use zacksleo\yii2\ad\models\Ad;
7
use zacksleo\yii2\ad\models\AdPosition;
8
9
class SlugAction extends Action
10
{
11
    public $slug;
12
13
    public function run()
14
    {
15
        if (($position = AdPosition::findOne(['slug' => $this->slug, 'status' => AdPosition::STATUS_ACTIVE])) == null) {
16
            return [];
17
        }
18
        return Ad::find()->orderBy('order')
19
            ->where(
20
                [
21
                    'position_id' => $position->id,
22
                    'status' => Ad::STATUS_ACTIVE
23
                ]
24
            )->andWhere(['<=', 'available_from', time()])
25
            ->andWhere(['>', 'available_to', time()])
26
            ->all();
27
    }
28
}
29