BasePresenter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 6
dl 0
loc 39
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createComponentDatabaseSelect() 0 4 1
B startup() 0 31 8
1
<?php
2
3
namespace UniMan\Presenters;
4
5
use UniMan\Components\DatabaseSelect\DatabaseSelectControl;
6
use UniMan\Core\Exception\ConnectException;
7
use Nette\Application\BadRequestException;
8
9
abstract class BasePresenter extends AbstractBasePresenter
10
{
11
    protected function startup()
12
    {
13
        parent::startup();
14
        $drivers = $this->driverStorage->getDrivers();
15
        $actualDriver = isset($this->params['driver']) ? $this->params['driver'] : current(array_keys($drivers));
16
17
        $this->template->driver = $actualDriver;
18
        $this->driver = $this->driverStorage->getDriver($actualDriver);
19
        if (!$this->driver) {
20
            throw new BadRequestException('Driver "' . $actualDriver . '" not found');
21
        }
22
23
        $credentials = $this->credentialsStorage->getCredentials($actualDriver);
24
        if (!$credentials) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $credentials of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
25
            $this->redirect('Default:default', $actualDriver);
26
        }
27
28
        foreach ($this->driver->defaultCredentials() as $key => $defaultCredential) {
29
            $credentials[$key] = $credentials[$key] ?: $defaultCredential;
30
        }
31
        try {
32
            $this->driver->connect($credentials);
33
            if (isset($this->params['database'])) {
34
                $this->driver->dataManager()->selectDatabase($this->params['database']);
35
            }
36
        } catch (ConnectException $e) {
37
            $this->flashMessage($e->getMessage(), 'danger');
38
            $this->redirect('Default:default', $actualDriver);
39
        }
40
        $this->template->actualDriver = $this->driver;
41
    }
42
43
    protected function createComponentDatabaseSelect()
44
    {
45
        return new DatabaseSelectControl($this->driver, $this->translator, $this->database);
46
    }
47
}
48