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

ConversionsController::doTree()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

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