AddController::add()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 0
dl 0
loc 37
rs 9.0168
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Users\One\Admin\Profile;
4
5
use Exception;
6
use Rudolf\Component\Alerts\Alert;
7
use Rudolf\Component\Alerts\AlertsCollection;
8
use Rudolf\Framework\Controller\AdminController;
9
10
class AddController extends AdminController
11
{
12
    /**
13
     * @throws Exception
14
     */
15
    public function add()
16
    {
17
        if (isset($_POST['add'])) {
18
            if (empty($_POST['password']) || trim($_POST['password']) !== $_POST['password_again']) {
19
                AlertsCollection::add(
20
                    new Alert(
21
                        'error',
22
                        'Podane hasła nie są identyczne!'
23
                    )
24
                );
25
                $this->redirect(DIR . '/admin/users/add');
26
            }
27
28
            $addModel = new AddModel();
29
            $id = ($addModel)->add($_POST);
30
31
            if ($id) {
32
                AlertsCollection::add(
33
                    new Alert(
34
                        'success',
35
                        'Dodano użytkownika'
36
                    )
37
                );
38
                $addModel->flushCache('users');
39
                $this->redirect(DIR . '/admin/users/edit/' . $id);
40
            }
41
            AlertsCollection::add(
42
                new Alert(
43
                    'error',
44
                    'Wystąpił nieoczekiwany błąd'
45
                )
46
            );
47
        }
48
        $view = new AddView();
49
        $view->display();
50
        $view->render();
51
    }
52
}
53