InstantiatorTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 10 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