Passed
Push — master ( 442876...4ec1bc )
by Felipe
15:55 queued 10:33
created

CastsController::doTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
14
class CastsController extends BaseController
15
{
16
    public $controller_name = 'CastsController';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        $lang   = $this->lang;
24
        $action = $this->action;
25
        if ('tree' == $action) {
26
            return $this->doTree();
27
        }
28
29
        $this->printHeader($lang['strcasts']);
30
        $this->printBody();
31
32
        switch ($action) {
33
            default:
34
                $this->doDefault();
35
36
                break;
37
        }
38
39
        return $this->printFooter();
40
    }
41
42
    /**
43
     * Show default list of casts in the database.
44
     *
45
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
46
     */
47
    public function doDefault($msg = '')
48
    {
49
        $lang = $this->lang;
50
        $data = $this->misc->getDatabaseAccessor();
51
52
        $renderCastContext = function ($val) use ($lang) {
53
            switch ($val) {
54
                case 'e':return $lang['strno'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
55
                case 'a':return $lang['strinassignment'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
56
                default:return $lang['stryes'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
57
            }
58
        };
59
60
        $this->printTrail('database');
61
        $this->printTabs('database', 'casts');
62
        $this->printMsg($msg);
63
64
        $casts = $data->getCasts();
65
66
        $columns = [
67
            'source_type' => [
68
                'title' => $lang['strsourcetype'],
69
                'field' => Decorator::field('castsource'),
70
            ],
71
            'target_type' => [
72
                'title' => $lang['strtargettype'],
73
                'field' => Decorator::field('casttarget'),
74
            ],
75
            'function'    => [
76
                'title'  => $lang['strfunction'],
77
                'field'  => Decorator::field('castfunc'),
78
                'params' => ['null' => $lang['strbinarycompat']],
79
            ],
80
            'implicit'    => [
81
                'title'  => $lang['strimplicit'],
82
                'field'  => Decorator::field('castcontext'),
83
                'type'   => 'callback',
84
                'params' => ['function' => $renderCastContext, 'align' => 'center'],
85
            ],
86
            'comment'     => [
87
                'title' => $lang['strcomment'],
88
                'field' => Decorator::field('castcomment'),
89
            ],
90
        ];
91
92
        $actions = [];
93
94
        echo $this->printTable($casts, $columns, $actions, 'casts-casts', $lang['strnocasts']);
95
    }
96
97
    /**
98
     * Generate XML for the browser tree.
99
     */
100
    public function doTree()
101
    {
102
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
103
        $data = $this->misc->getDatabaseAccessor();
104
105
        $casts = $data->getCasts();
106
107
        $proto = Decorator::concat(Decorator::field('castsource'), ' AS ', Decorator::field('casttarget'));
108
109
        $attrs = [
110
            'text' => $proto,
111
            'icon' => 'Cast',
112
        ];
113
114
        return $this->printTree($casts, $attrs, 'casts');
115
    }
116
}
117