Globals.php$1 ➔ __get()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
nc 5
nop 1
dl 0
loc 17
c 1
b 0
f 0
cc 5
rs 9.5555
1
<?php
2
3
namespace VoidEngine;
4
5
register_superglobals ('APPLICATION', 'SCREEN');
0 ignored issues
show
Bug introduced by
The function register_superglobals 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

5
/** @scrutinizer ignore-call */ 
6
register_superglobals ('APPLICATION', 'SCREEN');
Loading history...
6
7
$APPLICATION = new class
8
{
9
    public NetClass $application;
10
    public string $executablePath;
11
    
12
    public function __construct ()
13
    {
14
        $this->application    = new NetClass ('System.Windows.Forms.Application');
15
        $this->executablePath = $this->application->executablePath;
16
    }
17
    
18
    public function run ($form = null): void
19
    {
20
        if ($form instanceof NetObject)
21
            $this->application->run ($form->selector);
22
        
23
        elseif (is_int ($form) && \VoidCore::objectExists ($form))
24
            $this->application->run ($form);
25
        
26
        elseif ($form === null)
27
            $this->application->run ();
28
29
        else throw new \Exception ('$form param must be instance of "VoidEngine\NetObject" ("VoidEngine\Form"), be null or object selector');
30
    }
31
    
32
    public function restart (): void
33
    {
34
        $this->application->restart ();
35
        $this->close ();
36
    }
37
    
38
    public function close (): void
39
    {
40
        $this->application->exit ();
41
    }
42
43
    public function __call (string $name, array $args)
44
    {
45
        return $this->application->$name (...$args);
46
    }
47
48
    public function __get (string $name)
49
    {
50
        return $this->application->$name;
51
    }
52
};
53
54
$SCREEN = new class
55
{
56
    public NetClass $screen;
57
    
58
    public function __construct ()
59
    {
60
        $this->screen = new NetClass ('System.Windows.Forms.Screen');
61
    }
62
    
63
    public function __get ($name)
64
    {
65
        switch (strtolower ($name))
66
        {
67
            case 'width':
68
            case 'w':
69
                return $this->screen->primaryScreen->bounds->width;
70
            break;
71
            
72
            case 'height':
73
            case 'h':
74
                return $this->screen->primaryScreen->bounds->height;
75
            break;
76
77
            default:
78
                return $this->screen->$name;
79
            break;
80
        }
81
    }
82
    
83
    public function __debugInfo (): array
84
    {
85
        return [
86
            $this->w,
0 ignored issues
show
Bug Best Practice introduced by
The property w does not exist on anonymous//engine/common/Globals.php$1. Since you implemented __get, consider adding a @property annotation.
Loading history...
87
            $this->h
0 ignored issues
show
Bug Best Practice introduced by
The property h does not exist on anonymous//engine/common/Globals.php$1. Since you implemented __get, consider adding a @property annotation.
Loading history...
88
        ];
89
    }
90
};
91