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

AcinsertController::render()   D

Complexity

Conditions 13
Paths 200

Size

Total Lines 93
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 67
nc 200
nop 0
dl 0
loc 93
rs 4.6605
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
/**
10
 * Base controller class.
11
 */
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...
12
class AcinsertController extends BaseController
13
{
14
    public $controller_name = 'AcinsertController';
15
16
    /**
17
     * Default method to render the controller according to the action parameter.
18
     */
19
    public function render()
20
    {
21
        $lang   = $this->lang;
22
        $data   = $this->misc->getDatabaseAccessor();
23
        $action = $this->action;
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
24
25
        if (isset($_POST['offset'])) {
26
            $offset = " OFFSET {$_POST['offset']}";
27
        } else {
28
            $_POST['offset'] = 0;
29
            $offset          = ' OFFSET 0';
30
        }
31
32
        $keynames = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $keynames is dead and can be removed.
Loading history...
33
        foreach ($_POST['fkeynames'] as $k => $v) {
34
            $fkeynames[$k] = html_entity_decode($v, ENT_QUOTES);
35
        }
36
37
        $keyspos = array_combine($fkeynames, $_POST['keys']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fkeynames seems to be defined by a foreach iteration on line 33. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
38
39
        $f_schema = html_entity_decode($_POST['f_schema'], ENT_QUOTES);
40
        $data->fieldClean($f_schema);
41
        $f_table = html_entity_decode($_POST['f_table'], ENT_QUOTES);
42
        $data->fieldClean($f_table);
43
        $f_attname = $fkeynames[$_POST['fattpos'][0]];
44
        $data->fieldClean($f_attname);
45
46
        $q = "SELECT *
47
		FROM \"{$f_schema}\".\"{$f_table}\"
48
		WHERE \"{$f_attname}\"::text LIKE '{$_POST['fvalue']}%'
49
		ORDER BY \"{$f_attname}\" LIMIT 12 {$offset};";
50
51
        $res = $data->selectSet($q);
52
53
        if (!$res->EOF) {
54
            echo '<table class="ac_values">';
55
            echo '<tr>';
56
            foreach (array_keys($res->fields) as $h) {
57
                echo '<th>';
58
59
                if (in_array($h, $fkeynames, true)) {
60
                    echo '<img src="' . $this->misc->icon('ForeignKey') . '" alt="[referenced key]" />';
61
                }
62
63
                echo htmlentities($h, ENT_QUOTES, 'UTF-8'), '</th>';
64
            }
65
            echo "</tr>\n";
66
            $i = 0;
67
            while ((!$res->EOF) && ($i < 11)) {
68
                $j = 0;
69
                echo '<tr class="acline">';
70
                foreach ($res->fields as $n => $v) {
71
                    $finfo = $res->fetchField($j++);
72
                    if (in_array($n, $fkeynames, true)) {
73
                        echo "<td><a href=\"javascript:void(0)\" class=\"fkval\" name=\"{$keyspos[$n]}\">",
74
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
75
                            '</a></td>';
76
                    } else {
77
                        echo '<td><a href="javascript:void(0)">',
78
                        $this->misc->printVal($v, $finfo->type, ['clip' => 'collapsed']),
79
                            '</a></td>';
80
                    }
81
                }
82
                echo "</tr>\n";
83
                ++$i;
84
                $res->moveNext();
85
            }
86
            echo "</table>\n";
87
88
            $page_tests = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $page_tests is dead and can be removed.
Loading history...
89
90
            $js = "<script type=\"text/javascript\">\n";
91
92
            if ($_POST['offset']) {
93
                echo '<a href="javascript:void(0)" id="fkprev">&lt;&lt; Prev</a>';
94
                $js .= "fkl_hasprev=true;\n";
95
            } else {
96
                $js .= "fkl_hasprev=false;\n";
97
            }
98
99
            if (12 == $res->recordCount()) {
100
                $js .= "fkl_hasnext=true;\n";
101
                echo '&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" id="fknext">Next &gt;&gt;</a>';
102
            } else {
103
                $js .= "fkl_hasnext=false;\n";
104
            }
105
106
            echo $js . '</script>';
107
        } else {
108
            printf("<p>{$lang['strnofkref']}</p>", "\"{$_POST['f_schema']}\".\"{$_POST['f_table']}\".\"{$fkeynames[$_POST['fattpos']]}\"");
109
110
            if ($_POST['offset']) {
111
                echo '<a href="javascript:void(0)" class="fkprev">Prev &lt;&lt;</a>';
112
            }
113
        }
114
    }
115
}
116