Passed
Push — master ( e26094...28949d )
by Paul
02:50
created

Globals::entries()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 34
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 24
nc 3
nop 0
dl 0
loc 34
rs 8.9137
c 1
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\BlackBar\Modules;
4
5
use GeminiLabs\BlackBar\Application;
6
7
class Globals implements Module
8
{
9
    /**
10
     * @var Application
11
     */
12
    protected $app;
13
    /**
14
     * @var array
15
     */
16
    protected $entries;
17
18
    public function __construct(Application $app)
19
    {
20
        $this->app = $app;
21
        $this->entries = [];
22
    }
23
24
    public function entries(): array
25
    {
26
        if (!empty($this->entries)) {
27
            return $this->entries;
28
        }
29
        if (is_admin() && $screen = get_current_screen()) {
1 ignored issue
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
30
            $reflection = new \ReflectionClass($screen);
1 ignored issue
show
Bug introduced by
$screen of type void is incompatible with the type object|string expected by parameter $objectOrClass of ReflectionClass::__construct(). ( Ignorable by Annotation )

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

30
            $reflection = new \ReflectionClass(/** @scrutinizer ignore-type */ $screen);
Loading history...
31
            $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
32
            $values = [];
33
            foreach ($properties as $property) {
34
                $values[$property->getName()] = $property->getValue($screen);
1 ignored issue
show
Bug introduced by
$screen of type void is incompatible with the type null|object expected by parameter $object of ReflectionProperty::getValue(). ( Ignorable by Annotation )

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

34
                $values[$property->getName()] = $property->getValue(/** @scrutinizer ignore-type */ $screen);
Loading history...
35
            }
36
            $this->entries[] = [
37
                'name' => 'WP_Screen',
38
                'value' => var_export($values, true),
39
            ];
40
        }
41
        $this->entries[] = [
42
            'name' => '$_GET',
43
            'value' => var_export($_GET, true),
44
        ];
45
        $this->entries[] = [
46
            'name' => '$_SERVER',
47
            'value' => var_export($_SERVER, true),
48
        ];
49
        $this->entries[] = [
50
            'name' => '$_COOKIE',
51
            'value' => var_export($_COOKIE, true),
52
        ];
53
        $this->entries[] = [
54
            'name' => '$_SESSION',
55
            'value' => var_export(isset($_SESSION) ? $_SESSION : [], true),
56
        ];
57
        return $this->entries;
58
    }
59
60
    public function hasEntries(): bool
61
    {
62
        return !empty($this->entries());
63
    }
64
65
    public function id(): string
66
    {
67
        return 'glbb-globals';
68
    }
69
70
    public function isVisible(): bool
71
    {
72
        return true;
73
    }
74
75
    public function label(): string
76
    {
77
        return __('Globals', 'blackbar');
78
    }
79
80
    public function render(): void
81
    {
82
        $this->app->render('panels/globals', ['globals' => $this]);
83
    }
84
}
85