ConversionsController::doTree()   A
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
c 0
b 0
f 0
rs 9.4222
cc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * PHPPgAdmin 6.1.3
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 */
14
class ConversionsController extends BaseController
15
{
16
    public $controller_title = 'strconversions';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        if ('tree' === $this->action) {
24
            return $this->doTree();
25
        }
26
27
        $this->printHeader();
28
        $this->printBody();
29
30
        switch ($this->action) {
31
            default:
32
                $this->doDefault();
33
34
                break;
35
        }
36
37
        return $this->printFooter();
38
    }
39
40
    /**
41
     * Show default list of conversions in the database.
42
     *
43
     * @param string $msg
44
     */
45
    public function doDefault($msg = ''): void
46
    {
47
        $data = $this->misc->getDatabaseAccessor();
48
49
        $this->printTrail('schema');
50
        $this->printTabs('schema', 'conversions');
51
        $this->printMsg($msg);
52
53
        $conversions = $data->getconversions();
54
55
        $columns = [
56
            'conversion' => [
57
                'title' => $this->lang['strname'],
58
                'field' => Decorator::field('conname'),
59
            ],
60
            'source_encoding' => [
61
                'title' => $this->lang['strsourceencoding'],
62
                'field' => Decorator::field('conforencoding'),
63
            ],
64
            'target_encoding' => [
65
                'title' => $this->lang['strtargetencoding'],
66
                'field' => Decorator::field('contoencoding'),
67
            ],
68
            'default' => [
69
                'title' => $this->lang['strdefault'],
70
                'field' => Decorator::field('condefault'),
71
                'type' => 'yesno',
72
            ],
73
            'comment' => [
74
                'title' => $this->lang['strcomment'],
75
                'field' => Decorator::field('concomment'),
76
            ],
77
        ];
78
79
        $actions = [];
80
81
        echo $this->printTable($conversions, $columns, $actions, 'conversions-conversions', $this->lang['strnoconversions']);
0 ignored issues
show
Bug introduced by
It seems like $conversions can also be of type integer; however, parameter $tabledata of PHPPgAdmin\Controller\BaseController::printTable() does only seem to accept ADORecordSet|PHPPgAdmin\ArrayRecordSet, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        echo $this->printTable(/** @scrutinizer ignore-type */ $conversions, $columns, $actions, 'conversions-conversions', $this->lang['strnoconversions']);
Loading history...
82
    }
83
84
    public function doTree()
85
    {
86
        $data = $this->misc->getDatabaseAccessor();
87
88
        $constraints = $data->getConstraints($_REQUEST['table']);
89
90
        $getIcon = static function ($f) {
91
            switch ($f['contype']) {
92
                case 'u':
93
                    return 'UniqueConstraint';
94
                case 'c':
95
                    return 'CheckConstraint';
96
                case 'f':
97
                    return 'ForeignKey';
98
                case 'p':
99
                    return 'PrimaryKey';
100
            }
101
        };
102
103
        $attrs = [
104
            'text' => Decorator::field('conname'),
105
            'icon' => Decorator::callback($getIcon),
106
        ];
107
108
        return $this->printTree($constraints, $attrs, 'constraints');
0 ignored issues
show
Bug introduced by
It seems like $constraints can also be of type integer; however, parameter $_treedata of PHPPgAdmin\Controller\BaseController::printTree() does only seem to accept PHPPgAdmin\ADORecordSet|PHPPgAdmin\ArrayRecordSet, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        return $this->printTree(/** @scrutinizer ignore-type */ $constraints, $attrs, 'constraints');
Loading history...
109
    }
110
}
111