GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NotificationController::actionView()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 8.9368
c 0
b 0
f 0
cc 5
nc 8
nop 1
1
<?php
2
3
namespace app\backgroundtasks\controllers;
4
5
use app\backgroundtasks\models\NotifyMessage;
6
use app\backgroundtasks\models\Task;
7
use Yii;
8
use yii\filters\AccessControl;
9
use yii\filters\VerbFilter;
10
use yii\web\Controller;
11
use yii\web\NotFoundHttpException;
12
13
/**
14
 * Class NotificationController
15
 * @package app\backgroundtasks\controllers
16
 * @author evgen-d <[email protected]>
17
 */
18
class NotificationController extends Controller
19
{
20
    public function behaviors()
21
    {
22
        return [
23
            'access' => [
24
                'class' => AccessControl::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
25
                'rules' => [
26
                    [
27
                        'allow' => true,
28
                        'roles' => ['@'],
29
                    ],
30
                ],
31
            ],
32
            'verbs' => [
33
                'class' => VerbFilter::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
34
                'actions' => [
35
                ],
36
            ],
37
        ];
38
    }
39
40
    /**
41
     * View all notifications
42
     * @return string
43
     */
44
    public function actionIndex()
45
    {
46
        if (Yii::$app->getModule('background')->inGroup()) {
47
            $searchModel = new NotifyMessage(['scenario' => 'search']);
48
            $dataProvider = $searchModel->search($_GET);
49
        } else {
50
            $searchModel = new NotifyMessage(['scenario' => 'search']);
51
            $dataProvider = $searchModel->search($_GET, true);
52
        }
53
54
        return $this->render(
55
            'index',
56
            [
57
                'dataProvider' => $dataProvider,
58
                'searchModel' => $searchModel,
59
            ]
60
        );
61
    }
62
63
    /**
64
     * View Notification model if exist
65
     * @param $id
66
     * @return string
67
     * @throws \yii\web\NotFoundHttpException
68
     */
69
    public function actionView($id)
70
    {
71
        if (Yii::$app->getModule('background')->inGroup()) {
72
            /* @var $model NotifyMessage */
73
            $model = NotifyMessage::find()->joinWith(['task'])->where(
74
                [
75
                    'NotifyMessage.id' => $id,
76
                ]
77
            )->one();
78
        } else {
79
            /* @var $model NotifyMessage */
80
            $model = NotifyMessage::find()->joinWith(['task'])->where(
81
                [
82
                    NotifyMessage::tableName() . '.id' => $id,
83
                    Task::tableName() . '.initiator' => Yii::$app->user->id,
84
                ]
85
            )->one();
86
        }
87
88
        if ($model !== null) {
89
            switch ($model->result_status) {
90
                case NotifyMessage::STATUS_SUCCESS:
91
                    $class = 'panel-success';
92
                    break;
93
                case NotifyMessage::STATUS_FAULT:
94
                    $class = 'panel-danger';
95
                    break;
96
                default:
97
                    $class = 'panel-default';
98
                    break;
99
            }
100
            return $this->render(
101
                'view',
102
                [
103
                    'model' => $model,
104
                    'class' => $class,
105
                ]
106
            );
107
        } else {
108
            throw new NotFoundHttpException('repeated task #' . $id . ' not found');
109
        }
110
    }
111
112
    /**
113
     * Return count of new notifications
114
     * @param $current
115
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
116
     */
117
    public function actionOnlyNewNotifications($current)
118
    {
119
        if (Yii::$app->getModule('background')->inGroup()) {
120
            return NotifyMessage::find()->where('UNIX_TIMESTAMP(`ts`) > :current', [':current' => $current])->count();
121
        } else {
122
            return NotifyMessage::find()->where(
123
                [
124
                    'user_id' => Yii::$app->user->id,
125
                ]
126
            )->andWhere('UNIX_TIMESTAMP(`ts`) > :current', [':current' => $current])->count();
127
        }
128
    }
129
130
}
131