Completed
Push — master ( ee875b...07ff5e )
by Colin
01:17
created

Xero::bootPrivateApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MacsiDigital\Xero;
4
5
use Exception;
6
use Illuminate\Support\Str;
7
use MacsiDigital\Xero\Interfaces\PrivateApplication;
8
9
class Xero
10
{
11
    protected $client;
12
13
    public function __construct($type = 'Private')
14
    {
15
        $function = 'boot'.ucfirst($type).'Application';
16
        if (method_exists($this, $function)) {
17
            $this->$function();
18
        } else {
19
            throw new Exception('Application Interface type not known');
20
        }
21
    }
22
23
    public function bootPrivateApplication()
24
    {
25
        $this->client = (new PrivateApplication());
26
    }
27
28
    public function getClient() 
29
    {
30
        return $this->client;
31
    }
32
33
    public function __get($key)
34
    {
35
        return $this->getNode($key);
36
    }
37
38
    public function getNode($key)
39
    {
40
        $class = 'MacsiDigital\Xero\\'.Str::studly($key);
41
        if (class_exists($class)) {
42
            return new $class();
43
        }
44
        throw new Exception('Wrong method');
45
    }
46
}
47