SWbemServices   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 18
dl 0
loc 74
ccs 15
cts 21
cp 0.7143
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A instancesOf() 0 8 1
A __construct() 0 10 1
A resolvePropertySets() 0 5 1
A get() 0 3 1
A execQuery() 0 9 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Support\ApiObjects;
4
5
use PhpWinTools\WmiScripting\Flags\WbemFlags;
6
use PhpWinTools\Support\COM\ComVariantWrapper;
7
use function PhpWinTools\WmiScripting\Support\resolve;
8
use PhpWinTools\WmiScripting\Connections\ComConnection;
9
use function PhpWinTools\WmiScripting\Support\connection;
10
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Services;
11
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\ObjectSet;
12
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\ObjectItem;
13
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\ServicesVariant;
14
15
/**
16
 * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices
17
 */
18
class SWbemServices extends AbstractWbemObject implements Services
19
{
20
    const WMI_MONIKER = 'WINMGMTS:';
21
22
    protected $resolve_property_sets = [];
23
24
    /** @var ComVariantWrapper|ServicesVariant */
25
    protected $object;
26
27 2
    public function __construct(ComVariantWrapper $object = null, ComConnection $connection = null)
28
    {
29 2
        $connection = connection($connection);
30 2
        $object = $object ?? resolve()->comWrapper(
31 2
            resolve()->comClass(static::WMI_MONIKER . "\\\\{$connection->getServer()}\\{$connection->getNamespace()}")
32
        );
33 2
        parent::__construct($object);
34
35 2
        $this->resolve_property_sets['services'] = $this;
36 2
        $this->resolve_property_sets['property_names'] = [];
37 2
    }
38
39
    /**
40
     * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices-instancesof
41
     *
42
     * @param string $class
43
     * @param int    $flags
44
     * @param null   $wbemNamedValueSet
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $wbemNamedValueSet is correct as it would always require null to be passed?
Loading history...
45
     *
46
     * @return SWbemObjectSet
47
     */
48
    public function instancesOf(
49
        string $class,
50
        $flags = WbemFlags::RETURN_IMMEDIATELY,
51
        $wbemNamedValueSet = null
52
    ): ObjectSet {
53
        return resolve()->objectSet(
54
            $this->object->InstancesOf($class, $flags, $wbemNamedValueSet),
0 ignored issues
show
Bug introduced by
It seems like $this->object->Instances...gs, $wbemNamedValueSet) can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...n\Resolver::objectSet() 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

54
            /** @scrutinizer ignore-type */ $this->object->InstancesOf($class, $flags, $wbemNamedValueSet),
Loading history...
Bug introduced by
The method InstancesOf() does not exist on PhpWinTools\Support\COM\ComVariantWrapper. 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

54
            $this->object->/** @scrutinizer ignore-call */ 
55
                           InstancesOf($class, $flags, $wbemNamedValueSet),
Loading history...
55
            $this->resolve_property_sets
56
        );
57
    }
58
59
    /**
60
     * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/wql-sql-for-wmi
61
     * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices-execquery
62
     *
63
     * @param string $query
64
     * @param null   $query_language
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $query_language is correct as it would always require null to be passed?
Loading history...
65
     * @param int    $flags
66
     * @param null   $wbemNamedValueSet
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $wbemNamedValueSet is correct as it would always require null to be passed?
Loading history...
67
     *
68
     * @return ObjectSet
69
     */
70 2
    public function execQuery(
71
        string $query,
72
        $query_language = null,
73
        $flags = WbemFlags::RETURN_IMMEDIATELY,
74
        $wbemNamedValueSet = null
75
    ): ObjectSet {
76 2
        return resolve()->objectSet(
77 2
            $this->object->ExecQuery($query, $query_language, $flags, $wbemNamedValueSet),
0 ignored issues
show
Bug introduced by
The method ExecQuery() does not exist on PhpWinTools\Support\COM\ComVariantWrapper. 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

77
            $this->object->/** @scrutinizer ignore-call */ 
78
                           ExecQuery($query, $query_language, $flags, $wbemNamedValueSet),
Loading history...
Bug introduced by
It seems like $this->object->ExecQuery...gs, $wbemNamedValueSet) can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...n\Resolver::objectSet() 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

77
            /** @scrutinizer ignore-type */ $this->object->ExecQuery($query, $query_language, $flags, $wbemNamedValueSet),
Loading history...
78 2
            $this->resolve_property_sets
79
        );
80
    }
81
82
    public function get(string $object_path, $flags = null, $wbemNamedValueSet = null): ObjectItem
83
    {
84
        return resolve()->objectItem($this->object->Get($object_path, $flags, $wbemNamedValueSet));
0 ignored issues
show
Bug introduced by
It seems like $this->object->Get($obje...gs, $wbemNamedValueSet) can also be of type PhpWinTools\Support\COM\ComWrapper; however, parameter $variant of PhpWinTools\WmiScripting...\Resolver::objectItem() 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

84
        return resolve()->objectItem(/** @scrutinizer ignore-type */ $this->object->Get($object_path, $flags, $wbemNamedValueSet));
Loading history...
Bug introduced by
The method Get() does not exist on PhpWinTools\Support\COM\ComVariantWrapper. 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

84
        return resolve()->objectItem($this->object->/** @scrutinizer ignore-call */ Get($object_path, $flags, $wbemNamedValueSet));
Loading history...
85
    }
86
87 2
    public function resolvePropertySets(array $property_set_names): Services
88
    {
89 2
        $this->resolve_property_sets['property_names'] = $property_set_names;
90
91 2
        return $this;
92
    }
93
}
94