Completed
Pull Request — master (#424)
by Anton
04:19
created

ProxyTrait::__callStatic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 2
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Proxy;
12
13
use Bluz\Common\Singleton;
14
15
/**
16
 * ProxyTrait
17
 *
18
 * @package  Bluz\Proxy
19
 * @author   Anton Shevchuk
20
 */
21
trait ProxyTrait
22
{
23
    use Singleton;
24
25
    /**
26
     * Set or replace instance
27
     *
28
     * @param  mixed $instance
29
     *
30
     * @return void
31
     */
32 712
    public static function setInstance($instance)
33
    {
34 712
        static::$instance = $instance;
35 712
    }
36
37
    /**
38
     * Reset instance
39
     *
40
     * @return void
41
     */
42 24
    public static function resetInstance()
43
    {
44 24
        static::$instance = null;
45 24
    }
46
47
    /**
48
     * Handle dynamic, static calls to the object.
49
     *
50
     * @param  string $method
51
     * @param  array  $args
52
     *
53
     * @return mixed
54
     */
55 745
    public static function __callStatic($method, $args)
56
    {
57 745
        if ($instance = static::getInstance()) {
58 745
            return $instance->$method(...$args);
59
        }
60
        return false;
61
    }
62
}
63