Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Admin/User/ActionRoleUpdate.php (1 issue)

Checks if the types of the passed arguments in a function/method call are compatible.

Bug Minor
1
<?php
2
3
namespace Apps\Controller\Admin\User;
4
5
use Apps\ActiveRecord\Role;
6
use Apps\Model\Admin\User\FormUserGroupUpdate;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\SyntaxException;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionRoleUpdate
15
 * @package Apps\Controller\Admin\User
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionRoleUpdate
21
{
22
23
    /**
24
     * Update and add user role groups
25
     * @param int $id
26
     * @return null|string
27
     * @throws SyntaxException
28
     */
29
    public function roleUpdate($id = 0): ?string
30
    {
31
        // find role or create new object
32
        $role = Role::findOrNew($id);
33
34
        $model = new FormUserGroupUpdate($role);
0 ignored issues
show
It seems like $role can also be of type null; however, parameter $role of Apps\Model\Admin\User\Fo...upUpdate::__construct() does only seem to accept Apps\ActiveRecord\Role, 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

34
        $model = new FormUserGroupUpdate(/** @scrutinizer ignore-type */ $role);
Loading history...
35
        if ($model->send()) { // work with post request
36
            if ($model->validate()) {
37
                $model->save();
38
                App::$Session->getFlashBag()->add('success', __('Data was successful updated'));
39
            } else {
40
                App::$Session->getFlashBag()->add('error', __('Form validation is failed'));
41
            }
42
        }
43
44
        // render view
45
        return $this->view->render('user/role_update', [
46
            'model' => $model
47
        ]);
48
    }
49
}
50