Completed
Push — master ( 4a684c...c59301 )
by Joe
01:47
created

Connection::defaultNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 9
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 6
crap 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting;
4
5
use function PhpWinTools\WmiScripting\Support\resolve;
6
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Services;
7
8
class Connection
9
{
10
    const DEFAULT_SERVER = '.';
11
12
    const DEFAULT_NAMESPACE = 'Root\CIMv2';
13
14
    /** @var string */
15
    private $server;
16
17
    /** @var string */
18
    private $namespace;
19
20
    /** @var string|null */
21
    private $user;
22
23
    /** @var string|null */
24
    private $password;
25
26
    private $locale;
27
28
    /** @var null */
29
    private $authority;
30
31
    /** @var null */
32
    private $security_flags;
33
34
    private $services;
35
36 33
    public function __construct(
37
        string $server = self::DEFAULT_SERVER,
38
        string $namespace = self::DEFAULT_NAMESPACE,
39
        string $user = null,
40
        string $password = null,
41
        $locale = null,
42
        $authority = null,
43
        $security_flags = null
44
    ) {
45 33
        $this->server = $server;
46 33
        $this->namespace = $namespace;
47 33
        $this->user = $user;
48 33
        $this->password = $password;
49 33
        $this->locale = $locale;
50 33
        $this->authority = $authority;
51 33
        $this->security_flags = $security_flags;
52 33
    }
53
54 7
    /**
55
     * @param string      $server
56
     * @param string|null $user
57
     * @param string|null $password
58
     * @param mixed|null  $locale
59
     * @param mixed|null  $authority
60
     * @param mixed|null  $security_flags
61
     *
62 7
     * @return Connection
63
     */
64
    public static function defaultNamespace(
65
        string $server,
66
        string $user = null,
67
        string $password = null,
68 2
        $locale = null,
69
        $authority = null,
70 2
        $security_flags = null
71 2
    ): self {
72
        return new self($server, self::DEFAULT_NAMESPACE, $user, $password, $locale, $authority, $security_flags);
73
    }
74 2
75
    /**
76
     * @param string $server
77
     * @param string $user
78
     * @param string $password
79
     *
80 5
     * @return Connection
81
     */
82 5
    public static function simple(string $server, string $user, string $password): self
83
    {
84
        return static::defaultNamespace($server, $user, $password);
85
    }
86
87
    /**
88 4
     * @return Services
89
     */
90 4
    public function connect(): Services
91
    {
92
        if (is_null($this->services)) {
93
            $this->services = resolve()->locator()->connectServer($this);
94
        }
95
96 3
        return $this->services;
97
    }
98 3
99
    /**
100
     * @return string
101
     */
102
    public function getServer(): string
103
    {
104 3
        return $this->server;
105
    }
106 3
107
    /**
108
     * @return string
109 3
     */
110
    public function getNamespace(): string
111 3
    {
112
        return $this->namespace;
113
    }
114
115
    /**
116
     * @return string|null
117 3
     */
118
    public function getUser(): ?string
119 3
    {
120
        return $this->user;
121
    }
122
123
    /**
124
     * @return string|null
125 3
     */
126
    public function getPassword(): ?string
127 3
    {
128
        return $this->password;
129
    }
130
131
    public function getLocale()
132
    {
133
        return $this->locale;
134
    }
135
136
    /**
137
     * @return null
138
     */
139
    public function getAuthority()
140
    {
141
        return $this->authority;
142
    }
143
144
    /**
145
     * @return null
146
     */
147
    public function getSecurityFlags()
148
    {
149
        return $this->security_flags;
150
    }
151
}
152