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

CastsController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

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