1 | <?php |
||
2 | |||
3 | namespace PhpWinTools\WmiScripting\Connections; |
||
4 | |||
5 | use function PhpWinTools\WmiScripting\Support\resolve; |
||
6 | use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Services; |
||
7 | |||
8 | class ComConnection |
||
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 | |||
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 | $authority = null, |
||
46 | $security_flags = null |
||
47 | ) { |
||
48 | $this->server = $server; |
||
49 | $this->namespace = $namespace; |
||
50 | $this->user = $user; |
||
51 | $this->password = $password; |
||
52 | $this->locale = $locale; |
||
53 | $this->authority = $authority; |
||
54 | $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 | * @param mixed|null $authority |
||
63 | * @param mixed|null $security_flags |
||
64 | * |
||
65 | * @return ComConnection |
||
66 | */ |
||
67 | public static function defaultNamespace( |
||
68 | string $server, |
||
69 | string $user = null, |
||
70 | string $password = null, |
||
71 | $locale = null, |
||
72 | $authority = null, |
||
73 | $security_flags = null |
||
74 | ): self { |
||
75 | return new self($server, self::DEFAULT_NAMESPACE, $user, $password, $locale, $authority, $security_flags); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param string $server |
||
80 | * @param string $user |
||
81 | * @param string $password |
||
82 | * |
||
83 | * @return ComConnection |
||
84 | */ |
||
85 | public static function simple(string $server, string $user, string $password): self |
||
86 | { |
||
87 | return static::defaultNamespace($server, $user, $password); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return Services |
||
92 | */ |
||
93 | public function connect(): Services |
||
94 | { |
||
95 | if (is_null($this->services)) { |
||
96 | $start = microtime(true); |
||
97 | $this->services = resolve()->locator()->connectServer($this); |
||
98 | $this->time_to_connect = microtime(true) - $start; |
||
99 | } |
||
100 | |||
101 | return $this->services; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @return float |
||
106 | */ |
||
107 | public function getTimeToConnect() |
||
108 | { |
||
109 | return $this->time_to_connect; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getServer(): string |
||
116 | { |
||
117 | return $this->server; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function getNamespace(): string |
||
124 | { |
||
125 | return $this->namespace; |
||
126 | } |
||
127 | |||
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
|
|||
185 | |||
186 | return $this; |
||
187 | } |
||
188 | } |
||
189 |
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..