SWbemProperty::detectValue()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6.9849

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 1
crap 6.9849
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