Completed
Push — master ( d6bb8e...21b718 )
by Oleg
05:17
created

ProfileController::actionIndex()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.439
cc 5
eloc 13
nc 10
nop 0
1
<?php
2
3
namespace App\Controllers;
4
5
use App\Components\Controller;
6
use App\Components\View;
7
use App\Models\User;
8
9
/**
10
 * Class ProfileController
11
 * @package App\Controllers
12
 */
13
class ProfileController extends Controller
14
{
15
    public function filters()
16
    {
17
        return [
18
            [
19
                'class' => '\Micro\Filter\AccessFilter',
20
                'actions' => ['index'],
21
                'rules' => [
22
                    [
23
                        'allow' => false,
24
                        'actions' => ['index'],
25
                        'users' => ['?'],
26
                        'message' => 'Only for authorized!'
27
                    ]
28
                ]
29
            ],
30
            [
31
                'class' => '\Micro\Filter\CsrfFilter',
32
                'actions' => ['index']
33
            ],
34
            [
35
                'class' => '\Micro\Filter\XssFilter',
36
                'actions' => ['index'],
37
                'clean' => '*'
38
            ]
39
        ];
40
    }
41
42
    public function actionIndex()
43
    {
44
        $user = User::findByPk($this->container->user->getID(), $this->container);
0 ignored issues
show
Bug introduced by
Accessing user on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
45
        if (!$user) {
46
            $this->redirect('/logout');
47
        }
48
49
        /** @var array $setup */
50
        if ($setup = $this->container->request->post('Setup')) {
0 ignored issues
show
Bug introduced by
Accessing request on the interface Micro\Base\IContainer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
51
            if (!empty($setup['pass'])) {
52
                $user->pass = md5($setup['pass']);
53
            }
54
55
            if (!empty($setup['fio'])) {
56
                $user->fio = $setup['fio'];
57
            }
58
59
            $user->save();
60
        }
61
62
        $v = new View($this->container);
63
        $v->addParameter('user', $user);
64
65
        return $v;
66
    }
67
}
68