DelController::del()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 24
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Galleries\One\Admin;
4
5
use Exception;
6
use Rudolf\Framework\Controller\AdminController;
7
use Rudolf\Modules\Galleries\One;
8
9 View Code Duplication
class DelController extends AdminController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @param $id
13
     *
14
     * @throws Exception
15
     */
16
    public function del($id)
17
    {
18
        // if data was send
19
        if (isset($_POST['delete'])) {
20
            $delModel = new DelModel();
21
            $form = new DelForm();
22
            $form->handle(['id' => $id]);
23
            $form->setModel($delModel);
24
25
            if ($form->isValid()) {
26
                $form->delete();
27
                $delModel->flushCache('galleries');
28
                $this->redirect(DIR . '/admin/galleries');
29
            }
30
31
            $form->displayAlerts();
32
        }
33
34
        $gallery = (new One\Model())->getGalleryInfoById($id);
35
36
        $view = new DelView();
37
        $view->delGallery($gallery);
0 ignored issues
show
Bug introduced by
It seems like $gallery defined by (new \Rudolf\Modules\Gal...getGalleryInfoById($id) on line 34 can also be of type boolean; however, Rudolf\Modules\Galleries...n\DelView::delGallery() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38
        $view->render();
39
    }
40
}
41