ProfileController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 7
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B filters() 0 26 1
B actionIndex() 0 27 5
1
<?php
2
3
namespace App\Controllers;
4
5
use App\Components\Controller;
6
use App\Components\View;
7
use App\Models\User;
8
use Micro\Web\RequestInjector;
9
use Micro\Web\UserInjector;
10
11
/**
12
 * Class ProfileController
13
 * @package App\Controllers
14
 */
15
class ProfileController extends Controller
16
{
17
    public function filters()
18
    {
19
        return [
20
            [
21
                'class' => '\Micro\Filter\AccessFilter',
22
                'actions' => ['index'],
23
                'rules' => [
24
                    [
25
                        'allow' => false,
26
                        'actions' => ['index'],
27
                        'users' => ['?'],
28
                        'message' => 'Only for authorized!'
29
                    ]
30
                ]
31
            ],
32
            [
33
                'class' => '\Micro\Filter\CsrfFilter',
34
                'actions' => ['index']
35
            ],
36
            [
37
                'class' => '\Micro\Filter\XssFilter',
38
                'actions' => ['index'],
39
                'clean' => '*'
40
            ]
41
        ];
42
    }
43
44
    public function actionIndex()
45
    {
46
        $user = User::findByPk((new UserInjector)->build()->getID());
0 ignored issues
show
Bug introduced by
It seems like (new \Micro\Web\UserInjector())->build()->getID() targeting Micro\Web\IUser::getID() can also be of type boolean; however, Micro\Mvc\Models\Model::findByPk() does only seem to accept integer|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
47
        if (!$user) {
48
            return $this->redirect('/logout');
49
        }
50
51
        $body = (new RequestInjector)->build()->getParsedBody();
52
53
        /** @var array $setup */
54
        if ($setup = $body['Setup']) {
55
            if (!empty($setup['pass'])) {
56
                $user->pass = md5($setup['pass']);
57
            }
58
59
            if (!empty($setup['fio'])) {
60
                $user->fio = $setup['fio'];
61
            }
62
63
            $user->save();
64
        }
65
66
        $v = new View();
67
        $v->addParameter('user', $user);
68
69
        return $v;
70
    }
71
}
72