AnswerController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * HiPanel tickets module
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-ticket
6
 * @package   hipanel-module-ticket
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\ticket\controllers;
12
13
use hipanel\actions\RedirectAction;
14
use hipanel\actions\SmartPerformAction;
15
use hipanel\filters\EasyAccessControl;
16
use Yii;
17
18
class AnswerController extends \hipanel\base\CrudController
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 array_merge(parent::behaviors(), [
23
            [
24
                'class' => EasyAccessControl::class,
25
                'actions' => [
26
                    'update' => 'ticket.answer',
27
                    '*' => 'ticket.read',
28
                ],
29
            ],
30
        ]);
31
    }
32
33
    public function actions()
34
    {
35
        return [
36
            'update'   => [
37
                'class'      => SmartPerformAction::class,
38
                'scenario'   => 'update',
39
                'success'    => Yii::t('hipanel:ticket', 'Comment was updated'),
40
                'POST'  => [
41
                    'save'    => true,
42
                    'success' => [
43
                        'class'       => RedirectAction::class,
44
                        'url'        => function () {
45
                            $answer = Yii::$app->request->post('Answer');
46
47
                            return ['@ticket/view', 'id' => $answer['id']];
48
                        },
49
                    ],
50
                ],
51
            ],
52
        ];
53
    }
54
55
    /**
56
     * @return array
57
     */
58 View Code Duplication
    protected function prepareRefs()
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...
59
    {
60
        return [
61
            'topic_data'    => $this->getRefs('topic,ticket', 'hipanel:ticket'),
62
            'state_data'    => $this->getClassRefs('state', 'hipanel:ticket'),
63
            'priority_data' => $this->getPriorities(),
0 ignored issues
show
Documentation Bug introduced by
The method getPriorities does not exist on object<hipanel\modules\t...llers\AnswerController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
64
        ];
65
    }
66
}
67