Passed
Push — master ( f9c14b...c6fe8b )
by Laurens
02:03
created

DeviceProxy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\NestApi\Client;
6
7
use LauLamanApps\NestApi\Client\Device\Camera;
8
use LauLamanApps\NestApi\Client\Device\Protect;
9
use LauLamanApps\NestApi\Client\Device\Thermostat;
10
use LauLamanApps\NestApi\Client\Structure\CameraProxy;
11
use LauLamanApps\NestApi\Client\Structure\ProtectProxy;
12
use LauLamanApps\NestApi\Client\Structure\ThermostatProxy;
13
use LauLamanApps\NestApi\NestClientInterface;
14
15
abstract class DeviceProxy
16
{
17
    /**
18
     * @var NestClientInterface
19
     */
20
    private $__client;
21
22
    /**
23
     * @var string
24
     */
25
    private $__deviceId;
26
27
    /**
28
     * @var null|Thermostat|Protect|Camera
29
     */
30
    private $__device;
31
32
    /**
33
     * @return ThermostatProxy|ProtectProxy|CameraProxy
34
     */
35 4
    public function __construct(NestClientInterface $client, $deviceId)
36
    {
37 4
        $this->__deviceId = $deviceId;
38 4
        $this->__client = $client;
39 4
    }
40
41
    /**
42
     * @return Thermostat|Protect|Camera
43
     */
44
    abstract protected function __load(NestClientInterface $client, string $deviceId);
45
46 4
    public function __call($method, $args)
47
    {
48 4
        if (!$this->__device) {
49 4
            $this->__device = $this->__load($this->__client, $this->__deviceId);
50
        }
51
52 4
        return call_user_func_array([$this->__device, $method], $args);
53
    }
54
}
55