Passed
Push — main ( a2d04f...938ee5 )
by Andrey
24:43 queued 22:52
created

Facade   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
ccs 10
cts 11
cp 0.9091
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A clearResolvedInstances() 0 3 1
A getFacadeAccessor() 0 3 1
A __callStatic() 0 7 2
A getFacadeRoot() 0 3 1
1
<?php
2
/******************************************************************************
3
 * This file is part of the "andrey-helldar/support" project.                 *
4
 *                                                                            *
5
 * @author Andrey Helldar <[email protected]>                                *
6
 *                                                                            *
7
 * @copyright 2021 Andrey Helldar                                             *
8
 *                                                                            *
9
 * @license MIT                                                               *
10
 *                                                                            *
11
 * @see https://github.com/andrey-helldar/support                             *
12
 *                                                                            *
13
 * For the full copyright and license information, please view the LICENSE    *
14
 * file that was distributed with this source code.                           *
15
 ******************************************************************************/
16
17
namespace Helldar\Support\Facades;
18
19
use Helldar\Support\Concerns\Resolvable;
20
use RuntimeException;
21
22
abstract class Facade
23
{
24
    use Resolvable;
25
26 668
    public static function __callStatic($method, $args)
27
    {
28 668
        if ($instance = self::getFacadeRoot()) {
29 668
            return $instance->$method(...$args);
30
        }
31
32
        throw new RuntimeException('A facade root has not been set.');
33
    }
34
35 668
    public static function getFacadeRoot(): object
36
    {
37 668
        return self::resolveInstance(static::getFacadeAccessor());
38
    }
39
40 667
    public static function clearResolvedInstances()
41
    {
42 667
        self::$resolved = [];
43 667
    }
44
45
    /**
46
     * @return object|string
47
     */
48 1
    protected static function getFacadeAccessor()
49
    {
50 1
        throw new RuntimeException('Facade does not implement getFacadeAccessor method.');
51
    }
52
}
53