DatabaseSelectControl   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 18.92 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 9
dl 7
loc 37
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A render() 0 7 1
A createComponentSelect() 0 12 1

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\Components\DatabaseSelect;
4
5
use Nette\Application\UI\Control;
6
use Nette\Application\UI\Form;
7
use Nette\Localization\ITranslator;
8
use Tomaj\Form\Renderer\BootstrapVerticalRenderer;
9
use UniMan\Core\Driver\DriverInterface;
10
11
class DatabaseSelectControl extends Control
12
{
13
    private $driver;
14
15
    private $translator;
16
17
    private $database;
18
19 View Code Duplication
    public function __construct(DriverInterface $driver, ITranslator $translator, $database = null)
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...
20
    {
21
        parent::__construct();
22
        $this->driver = $driver;
23
        $this->translator = $translator;
24
        $this->database = $database;
25
    }
26
27
    public function render()
28
    {
29
        $this->template->driver = $this->driver;
30
        $this->template->actualDatabase = $this->database;
31
        $this->template->setFile(__DIR__ . '/default.latte');
32
        $this->template->render();
33
    }
34
35
    protected function createComponentSelect()
36
    {
37
        $databases = $this->driver->dataManager()->databaseNames();
38
        ksort($databases);
39
        $form = new Form();
40
        $form->setRenderer(new BootstrapVerticalRenderer());
41
        $form->addSelect('database', $this->translator->translate($this->driver->type() . '.database_select_control.database.label'), $databases)
42
            ->setPrompt($this->translator->translate($this->driver->type() . '.database_select_control.database.prompt'))
43
            ->setAttribute('onchange', 'window.location = \'' . $this->presenter->link('Table:default', $this->driver->type()) . '&database=\' + this.value')
44
            ->setDefaultValue($this->database);
45
        return $form;
46
    }
47
}
48