Completed
Pull Request — master (#397)
by Anton
05:51
created

ProxyTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setInstance() 0 4 1
A __callStatic() 0 8 2
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
     * @return void
30
     */
31 636
    public static function setInstance($instance)
32
    {
33 636
        static::$instance = $instance;
34 636
    }
35
36
    /**
37
     * Handle dynamic, static calls to the object.
38
     *
39
     * @param  string $method
40
     * @param  array $args
41
     * @return mixed
42
     */
43 659
    public static function __callStatic($method, $args)
44
    {
45 659
        if ($instance = static::getInstance()) {
46 659
            return $instance->$method(...$args);
47
        } else {
48
            return false;
49
        }
50
    }
51
}
52