| Conditions | 5 |
| Paths | 5 |
| Total Lines | 35 |
| Lines | 9 |
| Ratio | 25.71 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | public function add() |
||
|
|
|||
| 15 | { |
||
| 16 | if (isset($_POST['add'])) { |
||
| 17 | if (empty($_POST['password']) || trim($_POST['password']) !== $_POST['password_again']) { |
||
| 18 | AlertsCollection::add( |
||
| 19 | new Alert( |
||
| 20 | 'error', |
||
| 21 | 'Podane hasła nie są identyczne!' |
||
| 22 | ) |
||
| 23 | ); |
||
| 24 | $this->redirect(DIR.'/admin/users/add'); |
||
| 25 | } |
||
| 26 | |||
| 27 | $id = (new AddModel())->add($_POST); |
||
| 28 | |||
| 29 | View Code Duplication | if ($id) { |
|
| 30 | AlertsCollection::add( |
||
| 31 | new Alert( |
||
| 32 | 'success', |
||
| 33 | 'Dodano użytkownika' |
||
| 34 | ) |
||
| 35 | ); |
||
| 36 | $this->redirect(DIR.'/admin/users/edit/'.$id); |
||
| 37 | } |
||
| 38 | AlertsCollection::add( |
||
| 39 | new Alert( |
||
| 40 | 'error', |
||
| 41 | 'Wystąpił nieoczekiwany błąd' |
||
| 42 | ) |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | $view = new AddView(); |
||
| 46 | $view->display(); |
||
| 47 | $view->render(); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: