AbstractProxy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\eCurring\Resource\Proxy;
6
7
use LauLamanApps\eCurring\eCurringClientInterface;
8
use LauLamanApps\eCurring\Resource\Subscription;
9
10
abstract class AbstractProxy
11
{
12
    /**
13
     * @var eCurringClientInterface
14
     */
15
    private $__client;
16
17
    /**
18
     * @var string
19
     */
20
    private $__id;
21
22
    /**
23
     * @var null|Subscription
24
     */
25
    private $__object;
26
27
    /**
28
     * @return SubscriptionProxy
29
     */
30 3
    public function __construct(eCurringClientInterface $client, $deviceId)
31
    {
32 3
        $this->__id = $deviceId;
33 3
        $this->__client = $client;
34 3
    }
35
36
    /**
37
     * @return Subscription
38
     */
39
    abstract protected function __load(eCurringClientInterface $client, string $id);
40
41 3
    public function getId()
42
    {
43 3
        return $this->__id;
44
    }
45
46
    public function __call($method, $args)
47
    {
48
        if (!$this->__object) {
49
            $this->__object = $this->__load($this->__client, $this->__id);
50
        }
51
52
        return call_user_func_array([$this->__object, $method], $args);
53
    }
54
}
55