| Conditions | 6 |
| Paths | 7 |
| Total Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function edit($id) |
||
|
|
|||
| 17 | { |
||
| 18 | $model = new EditModel(); |
||
| 19 | |||
| 20 | if (!empty($_POST)) { |
||
| 21 | if (!empty($_POST['password'])) { |
||
| 22 | if (trim($_POST['password']) === $_POST['password_again'] && $model->updatePassword($id, $_POST['password'])) { |
||
| 23 | AlertsCollection::add( |
||
| 24 | new Alert( |
||
| 25 | 'success', |
||
| 26 | 'Zaktualizowano hasło' |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | } else { |
||
| 30 | AlertsCollection::add( |
||
| 31 | new Alert( |
||
| 32 | 'error', |
||
| 33 | 'Podane hasła nie są identyczne!' |
||
| 34 | ) |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($model->edit($id, $_POST)) { |
||
| 40 | AlertsCollection::add( |
||
| 41 | new Alert( |
||
| 42 | 'success', |
||
| 43 | 'Zaktualizowano profil (bez zmiany hasła)' |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | $this->redirect(DIR.'/admin/users/edit/'.$id); |
||
| 47 | } |
||
| 48 | AlertsCollection::add( |
||
| 49 | new Alert( |
||
| 50 | 'error', |
||
| 51 | 'Wystąpił nieoczekiwany błąd' |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | $view = new EditView(); |
||
| 57 | $view->display($model->getUserInfoById($id)); |
||
| 58 | $view->render(); |
||
| 59 | } |
||
| 60 | } |
||
| 61 |
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: