HasSubInvoker   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
getResponseType() 0 1 ?
setResponseType() 0 1 ?
A __get() 0 20 5
1
<?php
2
3
namespace CloudyCity\UCMarketingSDK\Kernel\Traits;
4
5
use CloudyCity\UCMarketingSDK\Kernel\Exceptions\Exception;
6
7
/**
8
 * Trait HasSubInvoker.
9
 *
10
 * @property array $providers
11
 */
12
trait HasSubInvoker
13
{
14
    use HasSdkBaseInfo;
15
16
    protected $instances = [];
17
18
    abstract public function getResponseType();
19
20
    abstract public function setResponseType($responseType);
21
22
    /**
23
     * @param $name
24
     *
25
     * @throws Exception
26
     *
27
     * @return mixed
28
     */
29
    public function __get($name)
30
    {
31
        if (!property_exists($this, $name)) {
32
            if (array_key_exists($name, $this->instances)) {
33
                return $this->instances[$name];
34
            }
35
            if (property_exists($this, 'providers') && array_key_exists($name, $this->providers)) {
36
                $username = $this->getUsername();
37
                $password = $this->getPassword();
38
                $token = $this->getToken();
39
                $responseType = $this->getResponseType();
40
41
                return new $this->providers[$name]($username, $password, $token, $responseType);
42
            }
43
44
            throw new Exception("Undefined property $name", 500);
45
        }
46
47
        return $this->$name;
48
    }
49
}
50