Completed
Push — master ( b27204...a2c64d )
by Nate
05:15 queued 02:48
created

controllers/settings/view/UserTypesController.php (1 issue)

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
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\cp\controllers\settings\view;
10
11
use Craft;
12
use craft\helpers\UrlHelper as UrlHelper;
13
use flipbox\organizations\records\UserType;
14
use yii\web\Response;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class UserTypesController extends AbstractSettingsController
21
{
22
    /**
23
     * The index view template path
24
     */
25
    const TEMPLATE_INDEX = AbstractSettingsController::TEMPLATE_BASE . '/userTypes';
26
27
    /**
28
     * The insert/update view template path
29
     */
30
    const TEMPLATE_UPSERT = self::TEMPLATE_INDEX . '/upsert';
31
32
    /**
33
     * @return Response
34
     */
35
    public function actionIndex()
36
    {
37
        $variables = [];
38
        $this->baseVariables($variables);
39
40
        $variables['types'] = UserType::findAll([]);
41
42
        return $this->renderTemplate(static::TEMPLATE_INDEX, $variables);
43
    }
44
45
    /**
46
     * @param null $identifier
47
     * @param UserType|null $userType
48
     * @return Response
49
     * @throws \flipbox\craft\ember\exceptions\RecordNotFoundException
50
     */
51
    public function actionUpsert($identifier = null, UserType $userType = null)
52
    {
53
        if (null === $userType) {
54
            if (null === $identifier) {
55
                $userType = new UserType();
56
            } else {
57
                $userType = UserType::getOne($identifier);
58
            }
59
        }
60
61
        $variables = [];
62
        if ($userType->getIsNewRecord()) {
63
            $this->insertVariables($variables);
64
        } else {
65
            $this->updateVariables($variables, $userType);
0 ignored issues
show
$userType is of type object<yii\db\ActiveRecordInterface>|array, but the function expects a object<flipbox\organizations\records\UserType>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        }
67
68
        $variables['type'] = $userType;
69
        $variables['fullPageForm'] = true;
70
71
        return $this->renderTemplate(static::TEMPLATE_UPSERT, $variables);
72
    }
73
74
    /*******************************************
75
     * BASE PATHS
76
     *******************************************/
77
78
    /**
79
     * @return string
80
     */
81
    protected function getBaseActionPath(): string
82
    {
83
        return parent::getBaseActionPath() . '/user-types';
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    protected function getBaseCpPath(): string
90
    {
91
        return parent::getBaseCpPath() . '/user-types';
92
    }
93
94
    /*******************************************
95
     * INSERT VARIABLES
96
     *******************************************/
97
98
    /**
99
     * @param array $variables
100
     */
101
    protected function insertVariables(array &$variables)
102
    {
103
        parent::insertVariables($variables);
104
        $variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}');
105
    }
106
107
    /*******************************************
108
     * UPDATE VARIABLES
109
     *******************************************/
110
111
    /**
112
     * @param array $variables
113
     * @param UserType $userType
114
     */
115
    protected function updateVariables(array &$variables, UserType $userType)
116
    {
117
        $this->baseVariables($variables);
118
        $variables['title'] .= ' - ' . Craft::t('organizations', 'Edit') . ' ' . $userType->name;
119
        $variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/' . $userType->getId());
120
        $variables['saveShortcutRedirect'] = $variables['continueEditingUrl'];
121
        $variables['crumbs'][] = [
122
            'label' => Craft::t('organizations', $userType->name),
123
            'url' => UrlHelper::url($variables['continueEditingUrl'])
124
        ];
125
    }
126
127
    /*******************************************
128
     * VARIABLES
129
     *******************************************/
130
131
    /**
132
     * @inheritdoc
133
     */
134
    protected function baseVariables(array &$variables = [])
135
    {
136
        $title = Craft::t('organizations', 'User Types');
137
138
        parent::baseVariables($variables);
139
        $variables['title'] .= ': ' . $title;
140
        $variables['crumbs'][] = [
141
            'label' => $title,
142
            'url' => UrlHelper::url($variables['baseCpPath'])
143
        ];
144
    }
145
}
146