SWbemObject   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 50
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A instantiateWin32Model() 0 9 3
A buildDerivations() 0 3 1
A getModel() 0 3 1
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 $path;
26
27
    /** @var VariantWrapper|ObjectVariant */
28
    protected $object;
29
30 2
    public function __construct(VariantWrapper $variant, array $resolve_property_sets = [])
31
    {
32 2
        parent::__construct($variant);
33
34 2
        $this->buildDerivations();
35
36 2
        $this->propertySet = resolve()->propertySet($this->object->Properties_, $resolve_property_sets);
0 ignored issues
show
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...
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

36
        $this->propertySet = resolve()->propertySet(/** @scrutinizer ignore-type */ $this->object->Properties_, $resolve_property_sets);
Loading history...
37 2
        $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

37
        $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...
38 2
        $this->path = resolve()->objectPath($this->object->Path_);
0 ignored issues
show
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...
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

38
        $this->path = resolve()->objectPath(/** @scrutinizer ignore-type */ $this->object->Path_);
Loading history...
39
40 2
        $this->instantiateWin32Model();
41 2
    }
42
43
    /**
44
     * @return Win32Model
45
     */
46 2
    public function getModel(): Win32Model
47
    {
48 2
        return $this->getAttribute('win32Model');
49
    }
50
51 2
    public function instantiateWin32Model(Win32Model $model = null): Win32Model
52
    {
53 2
        $model = $model ?? Classes::getClass($this->path->getAttribute('class'));
54
55 2
        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

55
        if (!is_null($this->win32Model) && get_class(/** @scrutinizer ignore-type */ $this->win32Model) === $model) {
Loading history...
56
            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...
57
        }
58
59 2
        return $this->win32Model = new $model($this->propertySet->toArray(), $this->path);
60
    }
61
62 2
    protected function buildDerivations()
63
    {
64 2
        $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

64
        /** @scrutinizer ignore-call */ 
65
        $this->derivations = $this->object->propertyToArray('Derivation_');
Loading history...
65 2
    }
66
}
67