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

Controller/Admin/Profile/ActionFieldUpdate.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Admin\Profile;
4
5
use Apps\ActiveRecord\ProfileField;
6
use Apps\Model\Admin\Profile\FormFieldUpdate;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Network\Request;
10
use Ffcms\Core\Network\Response;
11
12
/**
13
 * Trait ActionFieldUpdate
14
 * @package Apps\Controller\Admin\Profile
15
 * @property Request $request
16
 * @property Response $response
17
 * @property View $view
18
 */
19
trait ActionFieldUpdate
20
{
21
22
    /**
23
     * Add new or edit exist additional fields for user profiles
24
     * @param string|null $id
25
     * @return string
26
     * @throws \Ffcms\Core\Exception\SyntaxException
27
     */
28
    public function profileFieldUpdate($id = null)
29
    {
30
        // get current record or new and init form DI
31
        $record = ProfileField::findOrNew($id);
32
        $model = new FormFieldUpdate($record);
0 ignored issues
show
It seems like $record can also be of type null; however, parameter $record of Apps\Model\Admin\Profile...ldUpdate::__construct() does only seem to accept Apps\ActiveRecord\ProfileField, 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

32
        $model = new FormFieldUpdate(/** @scrutinizer ignore-type */ $record);
Loading history...
33
34
        // check if form is submitted
35
        if ($model->send() && $model->validate()) {
36
            $model->save();
37
            if ($record->id) {
38
                $this->response->redirect('profile/fieldlist');
39
            }
40
            App::$Session->getFlashBag()->add('success', __('Profile field was successful updated'));
41
        }
42
43
        return $this->view->render('profile/field_update', [
44
            'model' => $model
45
        ]);
46
    }
47
}
48