Passed
Pull Request — develop (#92)
by Felipe
04:25
created

CastsController::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 0
dl 0
loc 20
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
        $data = $this->misc->getDatabaseAccessor();
1 ignored issue
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
29
30
        $this->printHeader($lang['strcasts']);
31
        $this->printBody();
32
33
        switch ($action) {
34
            default:
35
                $this->doDefault();
36
37
                break;
38
        }
39
40
        return $this->printFooter();
41
    }
42
43
    /**
44
     * Show default list of casts in the database.
45
     *
46
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
47
     */
48
    public function doDefault($msg = '')
49
    {
50
        $lang = $this->lang;
51
        $data = $this->misc->getDatabaseAccessor();
52
53
        $renderCastContext = function ($val) use ($lang) {
54
            switch ($val) {
55
                case 'e':return $lang['strno'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
56
                case 'a':return $lang['strinassignment'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
57
                default:return $lang['stryes'];
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
58
            }
59
        };
60
61
        $this->printTrail('database');
62
        $this->printTabs('database', 'casts');
63
        $this->printMsg($msg);
64
65
        $casts = $data->getCasts();
66
67
        $columns = [
68
            'source_type' => [
69
                'title' => $lang['strsourcetype'],
70
                'field' => Decorator::field('castsource'),
71
            ],
72
            'target_type' => [
73
                'title' => $lang['strtargettype'],
74
                'field' => Decorator::field('casttarget'),
75
            ],
76
            'function'    => [
77
                'title'  => $lang['strfunction'],
78
                'field'  => Decorator::field('castfunc'),
79
                'params' => ['null' => $lang['strbinarycompat']],
80
            ],
81
            'implicit'    => [
82
                'title'  => $lang['strimplicit'],
83
                'field'  => Decorator::field('castcontext'),
84
                'type'   => 'callback',
85
                'params' => ['function' => $renderCastContext, 'align' => 'center'],
86
            ],
87
            'comment'     => [
88
                'title' => $lang['strcomment'],
89
                'field' => Decorator::field('castcomment'),
90
            ],
91
        ];
92
93
        $actions = [];
94
95
        echo $this->printTable($casts, $columns, $actions, 'casts-casts', $lang['strnocasts']);
96
    }
97
98
    /**
99
     * Generate XML for the browser tree.
100
     */
101
    public function doTree()
102
    {
103
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
104
        $data = $this->misc->getDatabaseAccessor();
105
106
        $casts = $data->getCasts();
107
108
        $proto = Decorator::concat(Decorator::field('castsource'), ' AS ', Decorator::field('casttarget'));
109
110
        $attrs = [
111
            'text' => $proto,
112
            'icon' => 'Cast',
113
        ];
114
115
        return $this->printTree($casts, $attrs, 'casts');
116
    }
117
}
118