ProductController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
nc 1
nop 0
dl 0
loc 17
c 0
b 0
f 0
cc 1
rs 9.9
1
<?php
2
3
namespace app\controllers;
4
5
use yii\web\NotFoundHttpException;
6
use yii\filters\{AccessControl, VerbFilter};
7
use yii\helpers\ArrayHelper;
8
use Itstructure\MFUploader\models\OwnerMediafile;
9
use app\models\Product;
10
11
/**
12
 * Class ProductController
13
 *
14
 * @package app\controllers
15
 */
16
class ProductController extends BaseController
17
{
18
    /**
19
     * @return array
20
     */
21
    public function behaviors()
22
    {
23
        return ArrayHelper::merge(parent::behaviors(), [
24
            'access' => [
25
                'class' => AccessControl::class,
26
                'rules' => [
27
                    [
28
                        'allow' => true,
29
                        'actions' => ['view'],
30
                        'roles' => ['?', '@'],
31
                    ],
32
                ],
33
            ],
34
            'verbs' => [
35
                'class' => VerbFilter::class,
36
                'actions' => [
37
                    'view' => ['get'],
38
                ],
39
            ],
40
        ]);
41
    }
42
43
    /**
44
     * Displays product page.
45
     *
46
     * @return string
47
     *
48
     * @throws NotFoundHttpException
49
     */
50
    public function actionView($alias)
51
    {
52
        $model = Product::find()->where([
53
            'alias' => $alias
54
        ])->andWhere([
55
            'active' => 1
56
        ])->one();
57
58
        if (null === $model) {
59
            throw new NotFoundHttpException('Product not fount with alias = '.$alias.'.');
60
        }
61
62
        $this->setMetaParams($model);
0 ignored issues
show
Bug introduced by
It seems like $model can also be of type array; however, parameter $model of app\controllers\BaseController::setMetaParams() does only seem to accept null|yii\db\ActiveRecord, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        $this->setMetaParams(/** @scrutinizer ignore-type */ $model);
Loading history...
63
64
        $images = OwnerMediafile::getImageFiles(Product::tableName(), $model->id);
0 ignored issues
show
Bug introduced by
It seems like $model->id can also be of type null; however, parameter $ownerId of Itstructure\MFUploader\m...iafile::getImageFiles() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $images = OwnerMediafile::getImageFiles(Product::tableName(), /** @scrutinizer ignore-type */ $model->id);
Loading history...
65
66
        return $this->render('view', [
67
            'model' => $model,
68
            'images' => $images
69
        ]);
70
    }
71
}
72