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.

Toolbar   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 68
dl 0
loc 180
rs 10
c 0
b 0
f 0
wmc 20

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A getOutput() 0 39 3
A getLogs() 0 9 2
A getDatabase() 0 15 4
A getVars() 0 27 5
A getFiles() 0 17 4
A roundTo() 0 5 1
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Gear;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class Toolbar
20
 *
21
 * @package O2System\Gear
22
 */
23
class Toolbar
24
{
25
    /**
26
     * Toolbar::__toString
27
     *
28
     * @return string
29
     */
30
    public function __toString()
31
    {
32
        return $this->getOutput();
33
    }
34
35
    // ------------------------------------------------------------------------
36
37
    /**
38
     * Toolbar::getOutput
39
     *
40
     * @return string
41
     */
42
    public function getOutput()
43
    {
44
        $totalExecution = profiler()->getTotalExecution();
0 ignored issues
show
Bug introduced by
The function profiler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

44
        $totalExecution = /** @scrutinizer ignore-call */ profiler()->getTotalExecution();
Loading history...
45
        $metrics = profiler()->getMetrics();
46
47
        $totalTime = 0;
48
        $totalMemory = 0;
49
50
        foreach ($metrics as $metric) {
51
            $totalTime += ($metric->endTime - $metric->startTime);
52
            $totalMemory += ($metric->endMemory - $metric->startMemory);
53
        }
54
55
        $segmentDuration = $this->roundTo($totalTime * 1000, 5);
56
        $segmentCount = (int)ceil($totalTime / $segmentDuration);
57
58
        $displayTime = $segmentCount * $segmentDuration;
59
60
        foreach ($metrics as $metric) {
61
            $metric->offset = (($metric->startTime - $totalExecution->startTime) * 1000 / $displayTime) * 100;
62
            $metric->length = (($metric->endTime - $metric->startTime) * 1000 / $displayTime) * 100;
63
        }
64
65
        $totalTime = $totalExecution->getFormattedTime($totalTime, 2);
66
        $totalMemory = $totalExecution->getFormattedMemorySize($totalMemory);
67
        $allocatedMemory = $totalExecution->getFormattedMemorySize(memory_get_usage(true));
68
        $peakMemory = $totalExecution->getFormattedMemorySize(memory_get_peak_usage(true));
69
70
        $files = $this->getFiles();
71
        $logs = $this->getLogs();
72
        $vars = $this->getVars();
73
        $database = $this->getDatabase();
74
75
        ob_start();
76
        include __DIR__ . '/Views/Toolbar.php';
77
        $output = ob_get_contents();
78
        ob_end_clean();
79
80
        return $output;
81
    }
82
83
    // ------------------------------------------------------------------------
84
85
    /**
86
     * Toolbar::roundTo
87
     *
88
     * Rounds a number to the nearest incremental value.
89
     *
90
     * @param float $number
91
     * @param int   $increments
92
     *
93
     * @return float
94
     */
95
    protected function roundTo($number, $increments = 5)
96
    {
97
        $increments = 1 / $increments;
98
99
        return (ceil($number * $increments) / $increments);
100
    }
101
    //--------------------------------------------------------------------
102
103
    /**
104
     * Toolbar::getFiles
105
     *
106
     * @return array
107
     */
108
    public function getFiles()
109
    {
110
        $files = get_included_files();
111
112
        if (class_exists('\O2System\Framework', false)) {
113
            foreach ($files as $key => $file) {
114
115
                if (strpos($file, 'autoload.php') !== false) {
116
                    unset($files[ $key ]);
117
                    continue;
118
                }
119
120
                $files[ $key ] = str_replace(PATH_ROOT, DIRECTORY_SEPARATOR, $file);
0 ignored issues
show
Bug introduced by
The constant O2System\Gear\PATH_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
121
            }
122
        }
123
124
        return $files;
125
    }
126
127
    // ------------------------------------------------------------------------
128
129
    /**
130
     * Toolbar::getLogs
131
     *
132
     * @return array
133
     */
134
    public function getLogs()
135
    {
136
        $logs = [];
137
138
        if (function_exists('logger')) {
139
            $logs = logger()->getLines();
140
        }
141
142
        return $logs;
143
    }
144
145
    // ------------------------------------------------------------------------
146
147
    /**
148
     * Toolbar::getVars
149
     *
150
     * @return \ArrayObject
151
     */
152
    public function getVars()
153
    {
154
        $vars = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
155
156
        $vars->env = $_ENV;
0 ignored issues
show
Bug introduced by
The property env does not seem to exist on ArrayObject.
Loading history...
157
        $vars->server = $_SERVER;
0 ignored issues
show
Bug introduced by
The property server does not seem to exist on ArrayObject.
Loading history...
158
        $vars->session = $_SESSION;
0 ignored issues
show
Bug introduced by
The property session does not seem to exist on ArrayObject.
Loading history...
159
        $vars->cookies = $_COOKIE;
0 ignored issues
show
Bug introduced by
The property cookies does not seem to exist on ArrayObject.
Loading history...
160
        $vars->get = $_GET;
0 ignored issues
show
Bug introduced by
The property get does not seem to exist on ArrayObject.
Loading history...
161
        $vars->post = $_POST;
0 ignored issues
show
Bug introduced by
The property post does not seem to exist on ArrayObject.
Loading history...
162
        $vars->files = $_FILES;
0 ignored issues
show
Bug introduced by
The property files does not seem to exist on ArrayObject.
Loading history...
163
164
        if (function_exists('apache_request_headers')) {
165
            $vars->headers = apache_request_headers();
0 ignored issues
show
Bug introduced by
The property headers does not seem to exist on ArrayObject.
Loading history...
166
        } elseif (function_exists('getallheaders')) {
167
            $vars->headers = getallheaders();
168
        } else {
169
            $vars->headers = [];
170
            foreach ($_SERVER as $name => $value) {
171
                if (substr($name, 0, 5) == 'HTTP_') {
172
                    $vars->headers[ str_replace(' ', '-',
173
                        ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))) ] = $value;
174
                }
175
            }
176
        }
177
178
        return $vars;
179
    }
180
181
    // ------------------------------------------------------------------------
182
183
    /**
184
     * Toolbar::getDatabase
185
     *
186
     * @return array
187
     */
188
    public function getDatabase()
189
    {
190
        $database = [];
191
192
        if (class_exists('O2System\Framework', false)) {
193
            if (services()->has('database')) {
0 ignored issues
show
Bug introduced by
The function services was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

193
            if (/** @scrutinizer ignore-call */ services()->has('database')) {
Loading history...
194
                $connections = database()->getIterator();
0 ignored issues
show
Bug introduced by
The function database was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

194
                $connections = /** @scrutinizer ignore-call */ database()->getIterator();
Loading history...
195
196
                foreach ($connections as $offset => $connection) {
197
                    $database[ $offset ] = $connection->getQueries();
198
                }
199
            }
200
        }
201
202
        return $database;
203
    }
204
}