Passed
Push — master ( cf0423...965dbc )
by Felipe
09:31 queued 04:21
created

BrowserController::jsTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-beta.33
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 *
14
 * @package PHPPgAdmin
15
 */
16
class BrowserController extends BaseController
17
{
18
    public $controller_name = 'BrowserController';
19
20
    /**
21
     * Default method to render the controller according to the action parameter.
22
     */
23
    public function render($action = null)
24
    {
25
        if ($action === null) {
26
            $action = $this->action;
27
        }
28
29
        switch ($action) {
30
            case 'tree':
31
                return $this->doTree();
32
33
                break;
1 ignored issue
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
34
            case 'jstree':
35
                return $this->jsTree();
36
                break;
37
38
            default:
39
                return $this->doDefault();
40
                break;
41
        }
42
    }
43
44
    /**
45
     * Default method to render the controller according to the action parameter.
46
     */
47
    public function doDefault()
48
    {
49
        $this->misc->setNoDBConnection(true);
50
51
        $this->setNoBottomLink(true);
52
53
        $viewVars = ['icon' => [
54
            'blank'          => $this->misc->icon('blank'),
55
            'I'              => $this->misc->icon('I'),
56
            'L'              => $this->misc->icon('L'),
57
            'Lminus'         => $this->misc->icon('Lminus'),
58
            'Loading'        => $this->misc->icon('Loading'),
59
            'Lplus'          => $this->misc->icon('Lplus'),
60
            'ObjectNotFound' => $this->misc->icon('ObjectNotFound'),
61
            'Refresh'        => $this->misc->icon('Refresh'),
62
            'Servers'        => $this->misc->icon('Servers'),
63
            'T'              => $this->misc->icon('T'),
64
            'Tminus'         => $this->misc->icon('Tminus'),
65
            'Tplus'          => $this->misc->icon('Tplus'),
66
        ]];
67
68
        return $this->view->fetch('browser.twig', $viewVars);
69
    }
70
71
    /**
72
     * Default method to render the controller according to the action parameter.
73
     */
74
    public function jsTree()
75
    {
76
        $this->misc->setNoDBConnection(true);
77
78
        $this->setNoBottomLink(true);
79
80
        $viewVars = ['icon' => [
81
            'blank'          => $this->misc->icon('blank'),
82
            'I'              => $this->misc->icon('I'),
83
            'L'              => $this->misc->icon('L'),
84
            'Lminus'         => $this->misc->icon('Lminus'),
85
            'Loading'        => $this->misc->icon('Loading'),
86
            'Lplus'          => $this->misc->icon('Lplus'),
87
            'ObjectNotFound' => $this->misc->icon('ObjectNotFound'),
88
            'Refresh'        => $this->misc->icon('Refresh'),
89
            'Servers'        => $this->misc->icon('Servers'),
90
            'T'              => $this->misc->icon('T'),
91
            'Tminus'         => $this->misc->icon('Tminus'),
92
            'Tplus'          => $this->misc->icon('Tplus'),
93
        ]];
94
95
        return $this->view->fetch('jstree.twig', $viewVars);
96
    }
97
98
    public function doTree()
99
    {
100
        $treedata = new \PHPPgAdmin\ArrayRecordSet([]);
101
        $reqvars  = [];
102
103
        $attrs = [
104
            'text'    => 'Servers',
105
            'icon'    => 'Servers',
106
            'is_root' => 'true',
107
            'action'  => Decorator::url('/src/views/servers'),
108
            'branch'  => Decorator::url('/src/views/servers', $reqvars, ['action' => 'tree']),
109
        ];
110
111
        return $this->printTree($treedata, $attrs, 'server');
112
    }
113
114
}
115