Completed
Push — master ( 1b075a...ca8e9f )
by Jeff
16:54
created

ContentTypeController::actionToggle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace app\controllers;
4
5
use Yii;
6
use app\models\ContentType;
7
use yii\data\ActiveDataProvider;
8
use yii\web\NotFoundHttpException;
9
use yii\filters\AccessControl;
10
use yii\filters\VerbFilter;
11
12
/**
13
 * ContentController implements the CRUD actions for ContentType model.
14
 */
15
class ContentTypeController extends BaseController
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 View Code Duplication
    public function behaviors()
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...
21
    {
22
        return [
23
            'verbs' => [
24
                'class' => VerbFilter::className(),
25
                'actions' => [
26
                    'delete' => ['POST'],
27
                ],
28
            ],
29
            'access' => [
30
                'class' => AccessControl::className(),
31
                'only' => ['index'],
32
                'rules' => [
33
                    ['allow' => true, 'actions' => ['index'], 'roles' => ['setContentTypes']],
34
                ],
35
            ],
36
        ];
37
    }
38
39
    /**
40
     * Lists all ContentType models.
41
     *
42
     * @return string
43
     */
44
    public function actionIndex()
45
    {
46
        $dataProvider = new ActiveDataProvider([
47
            'query' => ContentType::find(),
48
        ]);
49
50
        return $this->render('index', [
51
            'dataProvider' => $dataProvider,
52
        ]);
53
    }
54
55
    /**
56
     * Enables or disables a Device.
57
     *
58
     * @param int $id screen id
59
     *
60
     * @return \yii\web\Response
61
     */
62 View Code Duplication
    public function actionToggle($id)
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...
63
    {
64
        $model = $this->findModel($id);
65
66
        $model->enabled = !$model->enabled;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<app\models\ContentType>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property enabled does not exist on object<app\models\ContentType>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
        $model->save();
68
69
        return $this->smartGoBack();
70
    }
71
72
    /**
73
     * Finds the ContentType model based on its primary key value.
74
     * If the model is not found, a 404 HTTP exception will be thrown.
75
     *
76
     * @param int $id
77
     *
78
     * @return ContentType the loaded model
79
     *
80
     * @throws NotFoundHttpException if the model cannot be found
81
     */
82 View Code Duplication
    protected function findModel($id)
1 ignored issue
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...
83
    {
84
        if (($model = ContentType::findOne($id)) !== null) {
85
            return $model;
86
        } else {
87
            throw new NotFoundHttpException(Yii::t('app', 'The requested content does not exist.'));
88
        }
89
    }
90
}
91