Completed
Push — master ( 0d5af4...840ef4 )
by Joe
01:47
created

Connection::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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 float */
15
    private $time_to_connect = 0.0;
16
17
    /** @var string */
18
    private $server;
19
20
    /** @var string */
21
    private $namespace;
22
23
    /** @var string|null */
24
    private $user;
25
26
    /** @var string|null */
27
    private $password;
28
29
    private $locale;
30
31
    /** @var null */
32
    private $authority;
33
34
    /** @var null */
35
    private $security_flags;
36 33
37
    private $services;
38
39
    public function __construct(
40
        string $server = self::DEFAULT_SERVER,
41
        string $namespace = self::DEFAULT_NAMESPACE,
42
        string $user = null,
43
        string $password = null,
44
        $locale = null,
45 33
        $authority = null,
46 33
        $security_flags = null
47 33
    ) {
48 33
        $this->server = $server;
49 33
        $this->namespace = $namespace;
50 33
        $this->user = $user;
51 33
        $this->password = $password;
52 33
        $this->locale = $locale;
53
        $this->authority = $authority;
54 7
        $this->security_flags = $security_flags;
55
    }
56
57
    /**
58
     * @param string      $server
59
     * @param string|null $user
60
     * @param string|null $password
61
     * @param mixed|null  $locale
62 7
     * @param mixed|null  $authority
63
     * @param mixed|null  $security_flags
64
     *
65
     * @return Connection
66
     */
67
    public static function defaultNamespace(
68 2
        string $server,
69
        string $user = null,
70 2
        string $password = null,
71 2
        $locale = null,
72
        $authority = null,
73
        $security_flags = null
74 2
    ): self {
75
        return new self($server, self::DEFAULT_NAMESPACE, $user, $password, $locale, $authority, $security_flags);
76
    }
77
78
    /**
79
     * @param string $server
80 5
     * @param string $user
81
     * @param string $password
82 5
     *
83
     * @return Connection
84
     */
85
    public static function simple(string $server, string $user, string $password): self
86
    {
87
        return static::defaultNamespace($server, $user, $password);
88 4
    }
89
90 4
    /**
91
     * @return Services
92
     */
93
    public function connect(): Services
94
    {
95
        if (is_null($this->services)) {
96 3
            $start = microtime(true);
97
            $this->services = resolve()->locator()->connectServer($this);
98 3
            $this->time_to_connect = microtime(true) - $start;
99
        }
100
101
        return $this->services;
102
    }
103
104 3
    /**
105
     * @return float
106 3
     */
107
    public function getTimeToConnect()
108
    {
109 3
        return $this->time_to_connect;
110
    }
111 3
112
    /**
113
     * @return string
114
     */
115
    public function getServer(): string
116
    {
117 3
        return $this->server;
118
    }
119 3
120
    /**
121
     * @return string
122
     */
123
    public function getNamespace(): string
124
    {
125 3
        return $this->namespace;
126
    }
127 3
128
    /**
129
     * @return string|null
130
     */
131
    public function getUser(): ?string
132
    {
133
        return $this->user;
134
    }
135
136
    /**
137
     * @return string|null
138
     */
139
    public function getPassword(): ?string
140
    {
141
        return $this->password;
142
    }
143
144
    public function getLocale()
145
    {
146
        return $this->locale;
147
    }
148
149
    /**
150
     * @return null
151
     */
152
    public function getAuthority()
153
    {
154
        return $this->authority;
155
    }
156
157
    /**
158
     * @param $authority
159
     *
160
     * @return self
161
     */
162
    public function setAuthority($authority)
163
    {
164
        $this->authority = $authority;
165
166
        return $this;
167
    }
168
169
    /**
170
     * @return null
171
     */
172
    public function getSecurityFlags()
173
    {
174
        return $this->security_flags;
175
    }
176
177
    /**
178
     * @param int $flags
179
     *
180
     * @return self
181
     */
182
    public function setSecurityFlags(int $flags)
183
    {
184
        $this->security_flags = $flags;
0 ignored issues
show
Documentation Bug introduced by
It seems like $flags of type integer is incompatible with the declared type null of property $security_flags.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
185
186
        return $this;
187
    }
188
}
189