Protean   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 48
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 4 1
A factory() 0 9 2
1
<?php
2
3
namespace Gregoriohc\Protean;
4
5
use Gregoriohc\Protean\Common\GatewayFactory;
6
use Gregoriohc\Protean\Common\GatewayInterface;
7
8
/**
9
 * @method static GatewayInterface create($name, $parameters = [])
10
 * @mehtod
11
 *
12
 * @see GatewayFactory
13
 */
14
class Protean
15
{
16
    /**
17
     * Internal factory storage
18
     *
19
     * @var GatewayFactory
20
     */
21
    private static $factory;
22
23
    /**
24
     * Get the gateway factory
25
     *
26
     * Creates a new empty GatewayFactory if none has been set previously.
27
     *
28
     * @return GatewayFactory A GatewayFactory instance
29
     */
30 42
    public static function factory()
31
    {
32 42
        if (is_null(self::$factory)) {
33 3
            $namespace = substr(static::class, 0, -(strlen(class_basename(static::class)) + 1));
34 3
            self::$factory = new GatewayFactory($namespace);
35
        }
36
37 42
        return self::$factory;
38
    }
39
40
    /**
41
     * Static function call router.
42
     *
43
     * All other function calls to the Protean class are routed to the factory.
44
     *
45
     * Example:
46
     *
47
     * <code>
48
     *   // Create a gateway
49
     *   $gateway = Protean::create('Something');
50
     * </code>
51
     *
52
     * @param string $method     The factory method to invoke.
53
     * @param array  $parameters Parameters passed to the factory method.
54
     *
55
     * @return mixed
56
     */
57 42
    public static function __callStatic($method, $parameters)
58
    {
59 42
        return call_user_func_array([self::factory(), $method], $parameters);
60
    }
61
}
62