Cancelled
Push — master ( 706ba7...b281b4 )
by Paul
02:38
created

Globals::entries()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 21
rs 9.7666
cc 3
nc 3
nop 0
1
<?php
2
3
namespace GeminiLabs\BlackBar\Modules;
4
5
class Globals extends Module
6
{
7
    public function entries(): array
8
    {
9
        if (!empty($this->entries)) {
10
            return $this->entries;
11
        }
12
        $globals = apply_filters('blackbar/globals', [
13
            'INPUT_COOKIE' => $_COOKIE,
14
            'INPUT_ENV' => $_ENV,
15
            'INPUT_GET' => $_GET,
16
            'INPUT_POST' => $_POST,
17
            'INPUT_SERVER' => $_SERVER,
18
            'WP_Screen' => $this->wpscreen(),
19
        ]);
20
        $globals = array_filter($globals);
21
        foreach ($globals as $key => $values) {
22
            $this->entries[] = [
23
                'name' => $key,
24
                'value' => var_export($values, true),
25
            ];
26
        }
27
        return $this->entries;
28
    }
29
30
    public function hasEntries(): bool
31
    {
32
        return !empty($this->entries());
33
    }
34
35
    public function label(): string
36
    {
37
        return __('Globals', 'blackbar');
38
    }
39
40
    protected function wpscreen(): array
41
    {
42
        $values = [];
43
        if (is_admin() && $screen = get_current_screen()) {
44
            $reflection = new \ReflectionClass($screen);
45
            $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
46
            foreach ($properties as $property) {
47
                $values[$property->getName()] = $property->getValue($screen);
48
            }
49
        }
50
        return $values;
51
    }
52
}
53