GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

contentAjaxParameters::__getPageParams()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
c 0
b 0
f 0
nc 5
nop 0
dl 0
loc 22
rs 9.6111
1
<?php
2
/**
3
 * @package content
4
 */
5
/**
6
 * The AjaxParameters returns an JSON array of all available parameters.
7
 */
8
9
class contentAjaxParameters extends JSONPage
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
10
{
11
    private $template = '$%s';
12
13
    public function view()
14
    {
15
        $params = array();
16
        $filter = $_GET['query'];
17
18
        if ($_GET['template']) {
19
            $this->template = General::sanitize($_GET['template']);
20
        }
21
22
        // Environment parameters
23
        if ($filter == 'env') {
24
            $params = array_merge($params, $this->__getEnvParams());
25
26
            // Page parameters
27
        } elseif ($filter == 'page') {
28
            $params = array_merge($params, $this->__getPageParams());
29
30
            // Data source parameters
31
        } elseif ($filter == 'ds') {
32
            $params = array_merge($params, $this->__getDSParams());
33
34
            // All parameters
35
        } else {
36
            $params = array_merge($params, $this->__getEnvParams());
37
            $params = array_merge($params, $this->__getPageParams());
38
            $params = array_merge($params, $this->__getDSParams());
39
        }
40
41
        foreach ($params as $param) {
42
            if (empty($filter) || strripos($param, $filter) !== false) {
43
                $this->_Result[] = $param;
44
            }
45
        }
46
47
        sort($this->_Result);
48
    }
49
50
    /**
51
     * Utilities
52
     */
53
    private function __getEnvParams()
54
    {
55
        $params = array();
56
        $env = array('today', 'current-time', 'this-year', 'this-month', 'this-day', 'timezone', 'website-name', 'page-title', 'root', 'workspace', 'root-page', 'current-page', 'current-page-id', 'current-path', 'current-query-string', 'current-url', 'cookie-username', 'cookie-pass', 'page-types', 'upload-limit');
57
58
        foreach ($env as $param) {
59
            $params[] = sprintf($this->template, $param);
60
        }
61
62
        return $params;
63
    }
64
65
    private function __getPageParams()
66
    {
67
        $params = array();
68
        $pages = PageManager::fetch(true, array('params'));
69
70
        foreach ($pages as $key => $pageparams) {
71
            if (empty($pageparams['params'])) {
72
                continue;
73
            }
74
75
            $pageparams = explode('/', $pageparams['params']);
76
77
            foreach ($pageparams as $pageparam) {
78
                $param = sprintf($this->template, $pageparam);
79
80
                if (!in_array($param, $params)) {
81
                    $params[] = $param;
82
                }
83
            }
84
        }
85
86
        return $params;
87
    }
88
89
    private function __getDSParams()
90
    {
91
        $params = array();
92
        $datasources = DatasourceManager::listAll();
93
94
        foreach ($datasources as $datasource) {
95
            $current = DatasourceManager::create($datasource['handle'], array(), false);
96
97
            // Get parameters
98
            if (is_array($current->dsParamPARAMOUTPUT)) {
99
                foreach ($current->dsParamPARAMOUTPUT as $id => $param) {
100
                    $params[] = sprintf($this->template, 'ds-' . Lang::createHandle($datasource['name']) . '.' . Lang::createHandle($param));
101
                }
102
            }
103
        }
104
105
        return $params;
106
    }
107
}
108