COMObjectFake::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PhpWinTools\Support\COM\Testing;
4
5
use PhpWinTools\Support\COM\VariantWrapper;
6
use PhpWinTools\WmiScripting\Testing\Support\ComResolver;
7
use PhpWinTools\WmiScripting\Testing\Support\VARIANTFake;
8
use PhpWinTools\WmiScripting\Testing\CallStacks\ComCallStack;
9
10
class COMObjectFake
11
{
12
    protected $stack;
13
14
    protected $response = [];
15
16 2
    public function __construct()
17
    {
18 2
        $this->stack = ComCallStack::instance();
19 2
    }
20
21
    /**
22
     * @param $method
23
     * @param $response
24
     *
25
     * @return COMObjectFake|VARIANTFake
26
     */
27 2
    public static function withResponse($method, $response)
28
    {
29 2
        return (new static())->addResponse($method, $response);
30
    }
31
32 2
    public function addResponse($method, $response)
33
    {
34 2
        $this->response[$method] = $response;
35
36 2
        return $this;
37
    }
38
39 2
    public function call($type, $method, $args = [])
40
    {
41 2
        $this->stack->add($type, $method, $args);
42
43 2
        $response = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
44
45 2
        if (array_key_exists($method, $this->response)) {
46 2
            return $this->response[$method];
47
        }
48
49
//        if ($type === 'getIterator') {
50
//            dd(ApiObjectCallStack::instance());
51
//            return new ArrayIterator([
52
//                new VariantWrapper(new VARIANTFake()),
53
//            ]);
54
//        }
55
56 2
        $response = ComResolver::instance($this->stack)->resolve()->{$method}($args);
57
58 2
        if ($response instanceof VARIANTFake || $response instanceof COMFake) {
59 2
            return new VariantWrapper($response);
60
        }
61
62 2
        return $response;
63
    }
64
65 2
    public function __get($property)
66
    {
67 2
        return $this->call(__FUNCTION__, $property);
68
    }
69
70
    public function __set($method, $value)
71
    {
72
        return $this->call(__FUNCTION__, $method, $value);
73
    }
74
75 2
    public function __call($method, $args)
76
    {
77 2
        return $this->call(__FUNCTION__, $method, $args);
78
    }
79
}
80