| Conditions | 3 |
| Paths | 3 |
| Total Lines | 32 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function add() |
||
|
|
|||
| 16 | { |
||
| 17 | if (isset($_POST['add'])) { |
||
| 18 | $model = new AddModel(); |
||
| 19 | $id = $model->add($_POST); |
||
| 20 | if ($id) { |
||
| 21 | AlertsCollection::add(new Alert( |
||
| 22 | 'success', |
||
| 23 | 'Poprawnie dodano!' |
||
| 24 | )); |
||
| 25 | $this->redirectTo(DIR.'/admin/appearance/menu/edit/'.$id); |
||
| 26 | return; |
||
| 27 | } |
||
| 28 | AlertsCollection::add(new Alert( |
||
| 29 | 'error', |
||
| 30 | 'Coś się zepsuło!' |
||
| 31 | )); |
||
| 32 | } |
||
| 33 | |||
| 34 | $view = new AddView(); |
||
| 35 | $view->display(new MenuItem([ |
||
| 36 | 'id' => -1, |
||
| 37 | 'parent_id' => 0, |
||
| 38 | 'title' => '', |
||
| 39 | 'slug' => '', |
||
| 40 | 'caption' => '', |
||
| 41 | 'menu_type' => 'main', |
||
| 42 | 'item_type' => '', |
||
| 43 | 'position' => 0, |
||
| 44 | ]), (new Model())->getTypes(), (new FrontModel())->getMenuItems()); |
||
| 45 | $view->render('admin'); |
||
| 46 | } |
||
| 47 | } |
||
| 48 |
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: