TablePresenter   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 8
dl 15
loc 63
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A actionCreate() 0 9 2
A actionEdit() 10 10 2
A createComponentForm() 0 4 1
A renderDefault() 0 21 3
A handleDelete() 5 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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