These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace App\Controllers; |
||
4 | |||
5 | use App\Components\Controller; |
||
6 | use App\Components\View; |
||
7 | use App\Models\LoginFormModel; |
||
8 | use Micro\Form\FormBuilder; |
||
9 | use Micro\Web\Html\Html; |
||
10 | |||
11 | /** |
||
12 | * Class DefaultController |
||
13 | * @package App\Controllers |
||
14 | */ |
||
15 | class DefaultController extends Controller |
||
16 | { |
||
17 | public function filters() |
||
18 | { |
||
19 | return [ |
||
20 | [ |
||
21 | 'class' => '\Micro\Filter\AccessFilter', |
||
22 | 'actions' => ['login', 'logout', 'index'], |
||
23 | 'rules' => [ |
||
24 | [ |
||
25 | 'allow' => false, |
||
26 | 'actions' => ['index'], |
||
27 | 'users' => ['@'], |
||
28 | 'message' => 'Only for not authorized!' |
||
29 | ], |
||
30 | [ |
||
31 | 'allow' => false, |
||
32 | 'actions' => ['login'], |
||
33 | 'users' => ['@'], |
||
34 | 'message' => 'Not authorized only' |
||
35 | ], |
||
36 | [ |
||
37 | 'allow' => false, |
||
38 | 'actions' => ['logout'], |
||
39 | 'users' => ['?'], |
||
40 | 'message' => 'Authorized only' |
||
41 | ] |
||
42 | ] |
||
43 | ], |
||
44 | [ |
||
45 | 'class' => '\Micro\Filter\CsrfFilter', |
||
46 | 'actions' => ['login'] |
||
47 | ], |
||
48 | [ |
||
49 | 'class' => '\Micro\Filter\XssFilter', |
||
50 | 'actions' => ['index', 'login', 'logout'], |
||
51 | 'clean' => '*' |
||
52 | ] |
||
53 | ]; |
||
54 | } |
||
55 | |||
56 | public function actionIndex() |
||
57 | { |
||
58 | return new View($this->container); |
||
59 | } |
||
60 | |||
61 | public function actionLogin() |
||
62 | { |
||
63 | /** @noinspection PhpIncludeInspection */ |
||
64 | $form = new FormBuilder( |
||
65 | include $this->container->kernel->getAppDir() . '/views/default/loginform.php', |
||
66 | new LoginFormModel($this->container), |
||
67 | 'POST' |
||
68 | ); |
||
69 | |||
70 | if ($post = $this->container->request->post('LoginFormModel')) { |
||
0 ignored issues
–
show
|
|||
71 | $form->setModelData($post); |
||
72 | /** @noinspection PhpUndefinedMethodInspection */ |
||
73 | if ($form->validateModel() && $form->getModel()->logined()) { |
||
0 ignored issues
–
show
The method
logined() does not seem to exist on object<Micro\Mvc\Models\Model> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
74 | $this->redirect('/profile'); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | $v = new View($this->container); |
||
79 | $v->addParameter('form', $form); |
||
80 | |||
81 | return $v; |
||
82 | } |
||
83 | |||
84 | public function actionError() |
||
85 | { |
||
86 | $result = null; |
||
87 | /** @var \Micro\Base\Exception $error */ |
||
88 | if ($error = $this->container->request->post('error')) { |
||
0 ignored issues
–
show
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
Loading history...
|
|||
89 | $result .= Html::heading(3, $error->getMessage(), ['class' => 'text-danger bg-danger']); |
||
90 | } |
||
91 | $v = new View($this->container); |
||
92 | $v->data = $result ?: 'undefined error'; |
||
93 | |||
94 | return $v; |
||
95 | } |
||
96 | |||
97 | public function actionLogout() |
||
98 | { |
||
99 | $this->container->session->destroy(); |
||
0 ignored issues
–
show
Accessing
session 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
Loading history...
|
|||
100 | $this->redirect('/'); |
||
101 | } |
||
102 | } |
||
103 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: