TablePresenter::handleDelete()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 5
Ratio 41.67 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 5
loc 12
ccs 0
cts 8
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 4
crap 12
1
<?php
2
3
namespace UniMan\Presenters;
4
5
use UniMan\Core\Exception\NoTablesJustItemsException;
6
use UniMan\Core\Forms\TableForm;
7
use Nette\Application\ForbiddenRequestException;
8
9
class TablePresenter extends BasePresenter
10
{
11
    public function renderDefault($driver, $database = null, array $sorting = [])
12
    {
13
        if ($database === null) {
14
            $this->redirect('Database:default', $driver);
15
        }
16
        $this->database = $database;
17
18
        try {
19
            $tables = $this->driver->dataManager()->tables($sorting);
20
        } catch (NoTablesJustItemsException $e) {
21
            $this->redirect('Item:default', $driver, $database, $e->getType(), $e->getTable());
22
        }
23
24
        $this->template->driver = $driver;
25
        $this->template->database = $database;
26
        $this->template->databaseName = $this->driver->dataManager()->databaseName($database);
27
        $this->template->tables = $tables;
28
        $this->template->tablesHeaders = $this->driver->headerManager()->tablesHeaders();
29
        $this->template->sorting = $sorting;
30
        $this->template->tablesCounts = $this->driver->dataManager()->tablesCount();
31
    }
32
33
    public function actionCreate($driver, $database, $type)
34
    {
35
        if (!$this->driver->permissions()->canCreateTable($database, $type)) {
36
            throw new ForbiddenRequestException('Create table is not allowed');
37
        }
38
        $this->template->driver = $driver;
39
        $this->database = $database;
40
        $this->template->type = $this->type = $type;
41
    }
42
43 View Code Duplication
    public function actionEdit($driver, $database, $type, $table)
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        if (!$this->driver->permissions()->canEditTable($database, $type, $table)) {
46
            throw new ForbiddenRequestException('Edit table is not allowed');
47
        }
48
        $this->template->driver = $driver;
49
        $this->database = $database;
50
        $this->template->type = $this->type = $type;
51
        $this->table = $table;
52
    }
53
54
    public function handleDelete($driver, $database, $type, $table)
55
    {
56
        if (!$this->driver->permissions()->canDeleteTable($database, $type, $table)) {
57
            throw new ForbiddenRequestException('Delete table is not allowed');
58
        }
59 View Code Duplication
        if ($this->driver->dataManager()->deleteTable($type, $table)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
60
            $this->flashMessage('Table was successfully deleted', 'success');
61
        } else {
62
            $this->flashMessage('Table was not deleted', 'danger');
63
        }
64
        $this->redirect('this', $driver, $database);
65
    }
66
67
    protected function createComponentForm()
68
    {
69
        return new TableForm($this->translator, $this->driver, $this->database, $this->type, $this->table);
70
    }
71
}
72