Passed
Push — drivers ( 453ead...6c2ab9 )
by Joe
01:44
created

SWbemObject::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Support\ApiObjects;
4
5
use PhpWinTools\Support\COM\VariantWrapper;
6
use PhpWinTools\WmiScripting\Models\Classes;
7
use PhpWinTools\WmiScripting\Models\Win32Model;
8
use function PhpWinTools\WmiScripting\Support\resolve;
9
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\ObjectItem;
10
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\ObjectVariant;
11
12
/**
13
 * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemobject
14
 */
15
class SWbemObject extends AbstractWbemObject implements ObjectItem
16
{
17
    protected $win32Model;
18
19
    protected $derivations = [];
20
21
    protected $propertySet;
22
23
    protected $qualifierSet;
24
25
    protected $mergedProperties = [];
26
27
    protected $path;
28
29
    /** @var VariantWrapper|ObjectVariant */
30
    protected $object;
31
32
    public function __construct(VariantWrapper $variant, array $resolve_property_sets = [])
33
    {
34
        parent::__construct($variant);
35
36
        $this->buildDerivations();
37
38
        $this->propertySet = resolve()->propertySet($this->object->Properties_, $resolve_property_sets);
0 ignored issues
show
Bug introduced by
It seems like $this->object->Properties_ can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...Resolver::propertySet() does only seem to accept PhpWinTools\Support\COM\VariantWrapper, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $this->propertySet = resolve()->propertySet(/** @scrutinizer ignore-type */ $this->object->Properties_, $resolve_property_sets);
Loading history...
Bug Best Practice introduced by
The property Properties_ does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
        $this->qualifierSet = resolve()->qualifierSet($this->object->Qualifiers_);
0 ignored issues
show
Bug introduced by
It seems like $this->object->Qualifiers_ can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...esolver::qualifierSet() does only seem to accept PhpWinTools\Support\COM\VariantWrapper, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $this->qualifierSet = resolve()->qualifierSet(/** @scrutinizer ignore-type */ $this->object->Qualifiers_);
Loading history...
Bug Best Practice introduced by
The property Qualifiers_ does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
        $this->path = resolve()->objectPath($this->object->Path_);
0 ignored issues
show
Bug introduced by
It seems like $this->object->Path_ can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...\Resolver::objectPath() does only seem to accept PhpWinTools\Support\COM\VariantWrapper, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $this->path = resolve()->objectPath(/** @scrutinizer ignore-type */ $this->object->Path_);
Loading history...
Bug Best Practice introduced by
The property Path_ does not exist on PhpWinTools\Support\COM\VariantWrapper. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
42
        $this->mergedProperties = array_merge(
43
            $this->propertySet->toArray(),
44
            ['qualifiers' => $this->qualifierSet->toArray()['qualifiers']],
45
            ['objectPath' => $this->path->toArray()],
46
            ['derivations' => $this->derivations]
47
        );
48
49
        $this->instantiateWin32Model();
50
    }
51
52
    /**
53
     * @return Win32Model
54
     */
55
    public function getModel(): Win32Model
56
    {
57
        return $this->getAttribute('win32Model');
58
    }
59
60
    public function get()
61
    {
62
        return $this->mergedProperties;
63
    }
64
65
    public function instantiateWin32Model(Win32Model $model = null): Win32Model
66
    {
67
        $model = $model ?? Classes::getClass($this->path->getAttribute('class'));
68
69
        if (!is_null($this->win32Model) && get_class($this->win32Model) === $model) {
0 ignored issues
show
Bug introduced by
It seems like $this->win32Model can also be of type mixed; however, parameter $object of get_class() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
        if (!is_null($this->win32Model) && get_class(/** @scrutinizer ignore-type */ $this->win32Model) === $model) {
Loading history...
70
            return $this->win32Model;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->win32Model could return the type mixed which is incompatible with the type-hinted return PhpWinTools\WmiScripting\Models\Win32Model. Consider adding an additional type-check to rule them out.
Loading history...
71
        }
72
73
        return $this->win32Model = new $model($this->mergedProperties);
74
    }
75
76
    protected function buildDerivations()
77
    {
78
        $this->derivations = $this->object->propertyToArray('Derivation_');
0 ignored issues
show
Bug introduced by
The method propertyToArray() does not exist on PhpWinTools\WmiScripting...nterfaces\ObjectVariant. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        /** @scrutinizer ignore-call */ 
79
        $this->derivations = $this->object->propertyToArray('Derivation_');
Loading history...
79
    }
80
}
81