Passed
Push — master ( 62ccc4...3821b3 )
by Roman
01:54
created

TestController::actionIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace tests\app\controllers;
4
5
use tests\app\jobs\NotVoidJob;
6
use tests\app\jobs\RecursionJob;
7
use tests\app\jobs\SimpleJob;
8
use tests\app\jobs\WrongJob;
9
use Yii;
10
use yii\web\Controller;
11
use zhuravljov\yii\queue\monitor\base\FlashTrait;
12
13
class TestController extends Controller
14
{
15
    use FlashTrait;
0 ignored issues
show
Bug introduced by
The trait zhuravljov\yii\queue\monitor\base\FlashTrait requires the property $session which is not provided by tests\app\controllers\TestController.
Loading history...
16
17
    /**
18
     * Home page with redirecting to a base page of the module.
19
     */
20
    public function actionIndex()
21
    {
22
        return $this->redirect(['/qmonitor']);
23
    }
24
25
    public function actionPushSimpleJob()
26
    {
27
        $this->getQueue()->push(new SimpleJob());
28
        return $this->success('A simple job has been pushed.')->goBackward();
29
    }
30
31
    public function actionPushRecursionJob()
32
    {
33
        $this->getQueue()->push(new RecursionJob());
34
        return $this->success('A recursion job has been pushed.')->goBackward();
35
    }
36
37
    public function actionPushManyRecursionJobs($count = 10)
38
    {
39
        for ($i = 0; $i < $count; $i++) {
40
            $this->getQueue()->push(new RecursionJob());
41
        }
42
        return $this->success("$count recursion jobs have been pushed.")->goBackward();
43
    }
44
45
    public function actionPushNotVoidJob()
46
    {
47
        $this->getQueue()->push(new NotVoidJob());
48
        return $this->success('Not void job has been pushed.')->goBackward();
49
    }
50
51
    public function actionPushWrongJob()
52
    {
53
        $this->getQueue()->push(new WrongJob());
54
        return $this->success('Wrong job has been pushed.')->goBackward();
55
    }
56
57
    /**
58
     * @return \yii\queue\Queue
59
     */
60
    protected function getQueue()
61
    {
62
        return Yii::$app->queue;
63
    }
64
65
    /**
66
     * @return \yii\web\Response
67
     */
68
    protected function goBackward()
69
    {
70
        return $this->redirect(Yii::$app->request->getReferrer() ?: Yii::$app->getHomeUrl());
71
    }
72
}
73