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

DeviceProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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