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

ConversionsController::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
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 ConversionsController extends BaseController
15
{
16
    public $controller_name = 'ConversionsController';
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
25
        $action = $this->action;
26
        if ('tree' == $action) {
27
            return $this->doTree();
28
        }
29
30
        $this->printHeader($lang['strconversions']);
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 conversions in the database.
45
     *
46
     * @param string $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
47
     *
48
     * @return string|void
49
     */
50
    public function doDefault($msg = '')
51
    {
52
        $lang = $this->lang;
53
        $data = $this->misc->getDatabaseAccessor();
54
55
        $this->printTrail('schema');
56
        $this->printTabs('schema', 'conversions');
57
        $this->printMsg($msg);
58
59
        $conversions = $data->getconversions();
60
61
        $columns = [
62
            'conversion'      => [
63
                'title' => $lang['strname'],
64
                'field' => Decorator::field('conname'),
65
            ],
66
            'source_encoding' => [
67
                'title' => $lang['strsourceencoding'],
68
                'field' => Decorator::field('conforencoding'),
69
            ],
70
            'target_encoding' => [
71
                'title' => $lang['strtargetencoding'],
72
                'field' => Decorator::field('contoencoding'),
73
            ],
74
            'default'         => [
75
                'title' => $lang['strdefault'],
76
                'field' => Decorator::field('condefault'),
77
                'type'  => 'yesno',
78
            ],
79
            'comment'         => [
80
                'title' => $lang['strcomment'],
81
                'field' => Decorator::field('concomment'),
82
            ],
83
        ];
84
85
        $actions = [];
86
87
        echo $this->printTable($conversions, $columns, $actions, 'conversions-conversions', $lang['strnoconversions']);
88
    }
89
90
    public function doTree()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
91
    {
92
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
93
        $data = $this->misc->getDatabaseAccessor();
94
95
        $constraints = $data->getConstraints($_REQUEST['table']);
96
97
        $reqvars = $this->misc->getRequestVars('schema');
0 ignored issues
show
Unused Code introduced by
The assignment to $reqvars is dead and can be removed.
Loading history...
98
99
        $getIcon = function ($f) {
100
            switch ($f['contype']) {
101
                case 'u':
102
                    return 'UniqueConstraint';
103
                case 'c':
104
                    return 'CheckConstraint';
105
                case 'f':
106
                    return 'ForeignKey';
107
                case 'p':
108
                    return 'PrimaryKey';
109
            }
110
        };
111
112
        $attrs = [
113
            'text' => Decorator::field('conname'),
114
            'icon' => Decorator::callback($getIcon),
115
        ];
116
117
        return $this->printTree($constraints, $attrs, 'constraints');
118
    }
119
}
120