SWbemProperty   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 40
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A detectValue() 0 12 4
A toArray() 0 5 1
A __construct() 0 7 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Support\ApiObjects;
4
5
use PhpWinTools\Support\COM\VariantWrapper;
6
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Property;
7
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\PropertyVariant;
8
9
/**
10
 * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemproperty
11
 */
12
class SWbemProperty extends AbstractWbemObject implements Property
13
{
14
    protected $name;
15
16
    protected $value;
17
18
    protected $origin;
19
20
    /** @var VariantWrapper|PropertyVariant */
21
    protected $object;
22
23 2
    public function __construct(VariantWrapper $variant)
24
    {
25 2
        parent::__construct($variant);
26
27 2
        $this->name = (string) $this->object->Name;
0 ignored issues
show
Bug Best Practice introduced by
The property Name does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
28 2
        $this->origin = (string) $this->object->Origin;
0 ignored issues
show
Bug Best Practice introduced by
The property Origin does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
29 2
        $this->value = $this->detectValue($this->object->Value);
0 ignored issues
show
Bug Best Practice introduced by
The property Value does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
30 2
    }
31
32 2
    public function toArray(): array
33
    {
34
        return [
35 2
            'value'  => $this->value,
36 2
            'origin' => $this->origin,
37
        ];
38
    }
39
40 2
    protected function detectValue($value)
41
    {
42 2
        if ($value instanceof VariantWrapper && $value->canIterateObject()) {
43
            $items = [];
44
            foreach ($value as $item) {
45
                $items[] = $item;
46
            }
47
48
            $value = $items;
49
        }
50
51 2
        return $value;
52
    }
53
}
54