InstantiatorTrait::__call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace JulianBustamante\Plaid\Traits;
4
5
/**
6
 * The Instantiator trait which has the magic methods for instantiating Resources
7
 * @package JulianBustamante\Plaid
8
 *
9
 */
10
trait InstantiatorTrait
11
{
12
13
    /**
14
     * Generic method to object getter. Since all objects are protected, this
15
     * method exposes a getter function with the same name as the protected
16
     * variable, for example
17
     * $plaid->auth can be referenced by $client->tickets()
18
     *
19
     * @param $method
20
     * @param $arguments
21
     *
22
     * @return mixed
23
     * @throws \Exception
24
     */
25
    public function __call($method, $arguments)
26
    {
27
        if (array_key_exists($method, $validResources = $this::getValidResources())) {
28
            $className = $validResources[$method];
29
            $instance = new $className($this);
30
        } else {
31
            throw new \BadMethodCallException("No method called $method available in " . __CLASS__);
32
        }
33
34
        return $instance->$method(...$arguments);
35
    }
36
}
37