Completed
Push — master ( ccdb45...342210 )
by Dmitry
12s queued 10s
created

CrontabController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
/**
12
 * @see    http://hiqdev.com/hipanel-module-hosting
13
 * @license http://hiqdev.com/hipanel-module-hosting/license
14
 * @copyright Copyright (c) 2015 HiQDev
15
 */
16
17
namespace hipanel\modules\hosting\controllers;
18
19
use hipanel\actions\IndexAction;
20
use hipanel\actions\SmartUpdateAction;
21
use hipanel\actions\ValidateFormAction;
22
use hipanel\actions\ViewAction;
23
use hipanel\modules\hosting\models\Crontab;
24
use hipanel\filters\EasyAccessControl;
25
use Yii;
26
use yii\base\Exception;
27
use yii\web\Response;
28
29
class CrontabController extends \hipanel\base\CrudController
30
{
31
    public function behaviors()
32
    {
33
        return array_merge(parent::behaviors(), [
34
            [
35
                'class' => EasyAccessControl::class,
36
                'actions' => [
37
                    'update' => 'account.update',
38
                    '*' => 'account.read',
39
                ],
40
            ],
41
        ]);
42
    }
43
44
    public function actions()
45
    {
46
        return array_merge(parent::actions(), [
47
            'index' => [
48
                'class' => IndexAction::class,
49
                'filterStorageMap' => [
50
                    'server' => 'server.server.name',
51
                    'account' => 'hosting.account.login',
52
                    'client_id' => 'client.client.id',
53
                ],
54
            ],
55
            'view' => [
56
                'class' => ViewAction::class,
57
            ],
58
            'update' => [
59
                'class' => SmartUpdateAction::class,
60
            ],
61
            'validate-form' => [
62
                'class' => ValidateFormAction::class,
63
            ],
64
        ]);
65
    }
66
67 View Code Duplication
    public function actionRequestFetch()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        \Yii::$app->response->format = Response::FORMAT_JSON;
70
        $response = [];
71
        $id = Yii::$app->request->post('id');
72
        if ($id) {
73
            try {
74
                $response = Crontab::perform('request-fetch', ['id' => $id]);
75
            } catch (Exception $e) {
76
                $response['error'] = $e->errorInfo['response'];
0 ignored issues
show
Bug introduced by
The property errorInfo does not seem to exist in yii\base\Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
77
            }
78
        }
79
80
        return $response;
81
    }
82
83 View Code Duplication
    public function actionGetRequestState()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        Yii::$app->response->format = Response::FORMAT_JSON;
86
        $response = [];
87
        $id = Yii::$app->request->post('id');
88
        if ($id) {
89
            try {
90
                $response = Crontab::perform('get-request-state', ['id' => $id]);
91
            } catch (Exception $e) {
92
                $response['error'] = $e->errorInfo['response'];
0 ignored issues
show
Bug introduced by
The property errorInfo does not seem to exist in yii\base\Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
93
            }
94
        }
95
96
        return $response;
97
    }
98
99
    public function actionGetInfo($id)
100
    {
101
        Yii::$app->response->format = Response::FORMAT_JSON;
102
        $response = [];
103
        if ($id) {
104
            try {
105
                $response = Crontab::perform('get-info', ['id' => $id]);
106
            } catch (Exception $e) {
107
                $response = $e->errorInfo['response'];
0 ignored issues
show
Bug introduced by
The property errorInfo does not seem to exist in yii\base\Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
            }
109
        }
110
111
        return $response;
112
    }
113
}
114