SWbemLocator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
dl 0
loc 29
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connectServer() 0 15 1
A __construct() 0 5 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Support\ApiObjects;
4
5
use PhpWinTools\Support\COM\ComVariantWrapper;
6
use function PhpWinTools\WmiScripting\Support\resolve;
7
use PhpWinTools\WmiScripting\Connections\ComConnection;
8
use function PhpWinTools\WmiScripting\Support\connection;
9
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Locator;
10
use PhpWinTools\WmiScripting\Support\ApiObjects\Contracts\Services;
11
use PhpWinTools\WmiScripting\Support\ApiObjects\VariantInterfaces\LocatorVariant;
12
13
/**
14
 * @link https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemlocator
15
 */
16
class SWbemLocator extends AbstractWbemObject implements Locator
17
{
18
    const SCRIPTING = 'WbemScripting';
19
20
    /** @var ComVariantWrapper|LocatorVariant */
21
    protected $object;
22
23 2
    public function __construct(ComVariantWrapper $object = null)
24
    {
25 2
        $object = $object ?? resolve()->comWrapper(resolve()->comClass(self::SCRIPTING . '.SWbemLocator'));
26
27 2
        parent::__construct($object);
28 2
    }
29
30 2
    public function connectServer(ComConnection $connection = null): Services
31
    {
32 2
        $connection = connection($connection);
33
34 2
        return resolve()->services(
35 2
            $this->object->ConnectServer(
0 ignored issues
show
Bug introduced by
The method ConnectServer() 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

35
            $this->object->/** @scrutinizer ignore-call */ 
36
                           ConnectServer(
Loading history...
36 2
                $connection->getServer(),
37 2
                $connection->getNamespace(),
38 2
                $connection->getUser(),
39 2
                $connection->getPassword(),
40 2
                $connection->getLocale(),
41 2
                $connection->getAuthority(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $connection->getAuthority() targeting PhpWinTools\WmiScripting...nection::getAuthority() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42 2
                $connection->getSecurityFlags()
0 ignored issues
show
Bug introduced by
Are you sure the usage of $connection->getSecurityFlags() targeting PhpWinTools\WmiScripting...ion::getSecurityFlags() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
            ),
44 2
            $connection
45
        );
46
    }
47
}
48