Completed
Push — master ( 7062ee...c98379 )
by Peter
06:27
created

Betfair::__callStatic()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
c 7
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 5
eloc 8
nc 4
nop 2
1
<?php
2
3
namespace PeterColes\Betfair;
4
5
use PeterColes\Betfair\Api\Auth;
6
7
class Betfair
8
{
9
    /**
10
     * Distribute requests to appropriate subsystems
11
     *
12
     * @param  $method string   the requested method (usually an API call)
13
     * @param  $params array    any parameters needed by, or to refine, the call
14
     * @return mixed
15
     */
16
    public static function __callStatic($method, $params)
17
    {
18
        // alias for Auth's init and persist methods
19
        if ($method == 'init' || $method == 'persist') {
20
            return call_user_func_array([ new Auth, $method ], $params);
21
        }
22
23
        // standard Auth
24
        if ($method == 'auth') {
25
            return new Auth;
26
        }
27
28
        // all other subsystems, currently Betting and Account
29
        $class = 'PeterColes\\Betfair\\Api\\'.ucfirst($method);
30
        if (class_exists($class)) {
31
            return call_user_func([ new $class, 'execute' ], $params);
32
        }
33
    }
34
}
35