Facade   A
last analyzed

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
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Andrey Helldar <[email protected]>
9
 *
10
 * @copyright 2021 Andrey Helldar
11
 *
12
 * @license MIT
13
 *
14
 * @see https://github.com/andrey-helldar/support
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 678
    public static function __callStatic($method, $args)
27
    {
28 678
        if ($instance = self::getFacadeRoot()) {
29 678
            return $instance->$method(...$args);
30
        }
31
32
        throw new RuntimeException('A facade root has not been set.');
33
    }
34
35 678
    public static function getFacadeRoot(): object
36
    {
37 678
        return self::resolveInstance(static::getFacadeAccessor());
38
    }
39
40 677
    public static function clearResolvedInstances()
41
    {
42 677
        self::$resolved = [];
43 677
    }
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