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.
Completed
Push — integration ( a3ab80...7a98f7 )
by Brendan
06:22
created

contentAjaxParameters::__getEnvParams()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 26
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 32
rs 8.8571
1
<?php
2
    /**
3
     * @package content
4
     */
5
6
    /**
7
     * The AjaxParameters returns an JSON array of all available parameters.
8
     */
9
    class contentAjaxParameters extends JSONPage
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(
57
                'today',
58
                'current-time',
59
                'this-year',
60
                'this-month',
61
                'this-day',
62
                'timezone',
63
                'website-name',
64
                'page-title',
65
                'root',
66
                'workspace',
67
                'root-page',
68
                'current-page',
69
                'current-page-id',
70
                'current-path',
71
                'current-query-string',
72
                'current-url',
73
                'cookie-username',
74
                'cookie-pass',
75
                'page-types',
76
                'upload-limit'
77
            );
78
79
            foreach ($env as $param) {
80
                $params[] = sprintf($this->template, $param);
81
            }
82
83
            return $params;
84
        }
85
86
        private function __getPageParams()
87
        {
88
            $params = array();
89
            $pages = PageManager::fetch(true, array('params'));
90
91
            foreach ($pages as $key => $pageparams) {
0 ignored issues
show
Bug introduced by
The expression $pages of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
92
                if (empty($pageparams['params'])) {
93
                    continue;
94
                }
95
96
                $pageparams = explode('/', $pageparams['params']);
97
98
                foreach ($pageparams as $pageparam) {
99
                    $param = sprintf($this->template, $pageparam);
100
101
                    if (!in_array($param, $params)) {
102
                        $params[] = $param;
103
                    }
104
                }
105
            }
106
107
            return $params;
108
        }
109
110
        private function __getDSParams()
111
        {
112
            $params = array();
113
            $datasources = DatasourceManager::listAll();
114
115
            foreach ($datasources as $datasource) {
116
                $current = DatasourceManager::create($datasource['handle'], array(), false);
117
118
                // Get parameters
119
                if (is_array($current->dsParamPARAMOUTPUT)) {
120
                    foreach ($current->dsParamPARAMOUTPUT as $id => $param) {
0 ignored issues
show
Bug introduced by
The property dsParamPARAMOUTPUT does not seem to exist in Datasource.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
121
                        $params[] = sprintf($this->template,
122
                            'ds-' . Lang::createHandle($datasource['name']) . '.' . Lang::createHandle($param));
123
                    }
124
                }
125
            }
126
127
            return $params;
128
        }
129
    }
130