Issues (73)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

controllers/DeviceController.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace app\controllers;
4
5
use Yii;
6
use app\models\Device;
7
use app\models\Screen;
8
use yii\helpers\ArrayHelper;
9
use yii\data\ActiveDataProvider;
10
use yii\web\NotFoundHttpException;
11
use yii\filters\VerbFilter;
12
use yii\filters\AccessControl;
13
14
/**
15
 * ScreenController implements the CRUD actions for Device model.
16
 */
17
class DeviceController extends BaseController
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 View Code Duplication
    public function behaviors()
0 ignored issues
show
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...
23
    {
24
        return [
25
            'verbs' => [
26
                'class' => VerbFilter::class,
27
                'actions' => [
28
                    'delete' => ['POST'],
29
                ],
30
            ],
31
            'access' => [
32
                'class' => AccessControl::class,
33
                'only' => ['index', 'view', 'create', 'update', 'delete', 'link', 'unlink'],
34
                'rules' => [
35
                    ['allow' => true, 'actions' => ['index', 'view', 'create', 'update', 'delete', 'link', 'unlink'], 'roles' => ['setDevices']],
36
                ],
37
            ],
38
        ];
39
    }
40
41
    /**
42
     * Lists all Device models.
43
     *
44
     * @return string
45
     */
46 View Code Duplication
    public function actionIndex()
0 ignored issues
show
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...
47
    {
48
        $dataProvider = new ActiveDataProvider([
49
            'query' => Device::find(),
50
        ]);
51
52
        return $this->render('index', [
53
            'dataProvider' => $dataProvider,
54
        ]);
55
    }
56
57
    /**
58
     * Displays a single Device model.
59
     *
60
     * @param int $id
61
     *
62
     * @return string
63
     */
64
    public function actionView($id)
65
    {
66
        $model = $this->findModel($id);
67
68
        $dataProvider = new ActiveDataProvider([
69
            'query' => $model->getScreens(),
70
        ]);
71
72
        return $this->render('view', [
73
            'model' => $model,
74
            'dataProvider' => $dataProvider,
75
        ]);
76
    }
77
78
    /**
79
     * Updates an existing Device model.
80
     * If update is successful, the browser will be redirected to the 'view' page.
81
     *
82
     * @param int $id
83
     *
84
     * @return \yii\web\Response|string redirect or render
85
     */
86
    public function actionUpdate($id)
87
    {
88
        $model = $this->findModel($id);
89
90
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
91
            return $this->redirect(['view', 'id' => $model->id]);
92
        } else {
93
            return $this->render('update', [
94
                'model' => $model,
95
            ]);
96
        }
97
    }
98
99
    /**
100
     * Deletes an existing Device model.
101
     * If deletion is successful, the browser will be redirected to the 'index' page.
102
     *
103
     * @param int $id
104
     *
105
     * @return \yii\web\Response
106
     */
107
    public function actionDelete($id)
108
    {
109
        $this->findModel($id)->delete();
110
111
        return $this->redirect(['index']);
112
    }
113
114
    /**
115
     * Adds a Screen to this Device or render link view.
116
     *
117
     * @param int $id
118
     * @param int $screenId
119
     *
120
     * @return \yii\web\Response|string redirec or render
121
     */
122 View Code Duplication
    public function actionLink($id, $screenId = null)
123
    {
124
        $model = $this->findModel($id);
125
126
        if ($screenId === null) {
127
            $dataProvider = new ActiveDataProvider([
128
                'query' => Screen::find()->where(['not', ['id' => ArrayHelper::getColumn($model->screens, 'id')]]),
129
            ]);
130
131
            return $this->render('link', [
132
                'model' => $model,
133
                'dataProvider' => $dataProvider,
134
            ]);
135
        } else {
136
            if (!$model->getScreens()->where(['id' => $screenId])->exists() && ($screen = Screen::findOne($screenId)) !== null) {
137
                $model->link('screens', $screen);
0 ignored issues
show
It seems like $screen defined by \app\models\Screen::findOne($screenId) on line 136 can also be of type array; however, yii\db\BaseActiveRecord::link() does only seem to accept object<yii\db\ActiveRecordInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
138
            }
139
140
            return $this->redirect(['view', 'id' => $id]);
141
        }
142
    }
143
144
    /**
145
     * Remove a Screen from a Device.
146
     *
147
     * @param int $id
148
     * @param int $screenId
149
     *
150
     * @return \yii\web\Response
151
     */
152 View Code Duplication
    public function actionUnlink($id, $screenId)
0 ignored issues
show
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...
153
    {
154
        $model = $this->findModel($id);
155
156
        if ($model->getScreens()->where(['id' => $screenId])->exists() && ($screen = Screen::findOne($screenId)) !== null) {
157
            $model->unlink('screens', $screen, true);
0 ignored issues
show
It seems like $screen defined by \app\models\Screen::findOne($screenId) on line 156 can also be of type array; however, yii\db\BaseActiveRecord::unlink() does only seem to accept object<yii\db\ActiveRecordInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
158
        }
159
160
        return $this->redirect(['view', 'id' => $id]);
161
    }
162
163
    /**
164
     * Enables or disables a Device.
165
     *
166
     * @param int $id screen id
167
     *
168
     * @return \yii\web\Response
169
     */
170 View Code Duplication
    public function actionToggle($id)
0 ignored issues
show
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...
171
    {
172
        $model = $this->findModel($id);
173
174
        $model->enabled = !$model->enabled;
175
        $model->save();
176
177
        return $this->smartGoBack();
178
    }
179
180
    /**
181
     * Finds the Device model based on its primary key value.
182
     * If the model is not found, a 404 HTTP exception will be thrown.
183
     *
184
     * @param int $id
185
     *
186
     * @return Device the loaded model
187
     *
188
     * @throws NotFoundHttpException if the model cannot be found
189
     */
190 View Code Duplication
    protected function findModel($id)
191
    {
192
        if (($model = Device::findOne($id)) !== null) {
0 ignored issues
show
Bug Compatibility introduced by
The expression \app\models\Device::findOne($id); of type yii\db\ActiveRecordInterface|array|null adds the type array to the return on line 193 which is incompatible with the return type documented by app\controllers\DeviceController::findModel of type app\models\Device.
Loading history...
193
            return $model;
194
        } else {
195
            throw new NotFoundHttpException(Yii::t('app', 'The requested device does not exist.'));
196
        }
197
    }
198
}
199