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

HelpController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 13 2
B doBrowse() 0 31 4
B doDefault() 0 23 4
A doChoosePage() 0 16 2
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 HelpController extends BaseController
13
{
14
    public $controller_name = 'HelpController';
15
16
    /**
17
     * Default method to render the controller according to the action parameter.
18
     */
19
    public function render()
20
    {
21
        $action = $this->action;
22
23
        switch ($action) {
24
            case 'browse':
25
                $this->doBrowse();
26
27
                break;
28
            default:
29
                $this->doDefault();
30
31
                break;
32
        }
33
    }
34
35
    public function doDefault()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
36
    {
37
        $lang = $this->lang;
38
        $data = $this->misc->getDatabaseAccessor();
39
40
        if (isset($_REQUEST['help'])) {
41
            $url = $data->getHelp($_REQUEST['help']);
42
43
            \PC::debug(['url' => $url], 'HelpController::doDefault');
44
            if (is_array($url)) {
45
                $this->doChoosePage($url);
46
47
                return;
48
            }
49
50
            if ($url) {
51
                header("Location: ${url}");
52
53
                return;
54
            }
55
        }
56
57
        $this->doBrowse($lang['strinvalidhelppage']);
58
    }
59
60
    public function doBrowse($msg = '')
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
61
    {
62
        $lang = $this->lang;
63
        $data = $this->misc->getDatabaseAccessor();
64
65
        $this->printHeader($lang['strhelppagebrowser']);
66
        $this->printBody();
67
68
        $this->printTitle($lang['strselecthelppage']);
69
70
        echo $this->printMsg($msg);
71
72
        echo "<dl>\n";
73
74
        $pages = $data->getHelpPages();
75
        foreach ($pages as $page => $dummy) {
76
            echo "<dt>{$page}</dt>\n";
77
78
            $urls = $data->getHelp($page);
79
            if (!is_array($urls)) {
80
                $urls = [$urls];
81
            }
82
83
            foreach ($urls as $url) {
84
                echo "<dd><a href=\"{$url}\">{$url}</a></dd>\n";
85
            }
86
        }
87
88
        echo "</dl>\n";
89
90
        $this->printFooter();
91
    }
92
93
    public function doChoosePage($urls)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
94
    {
95
        $lang = $this->lang;
96
97
        $this->printHeader($lang['strhelppagebrowser']);
98
        $this->printBody();
99
100
        $this->printTitle($lang['strselecthelppage']);
101
102
        echo "<ul>\n";
103
        foreach ($urls as $url) {
104
            echo "<li><a href=\"{$url}\">{$url}</a></li>\n";
105
        }
106
        echo "</ul>\n";
107
108
        $this->printFooter();
109
    }
110
}
111