Passed
Push — main ( da6fcc...bd4e0a )
by Dimitri
03:54
created

Facade   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 11 3
A __call() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Facades;
13
14
use InvalidArgumentException;
15
16
abstract class Facade
17
{
18
    abstract protected static function accessor(): object|string;
19
20
    public static function __callStatic(string $name, array $arguments = [])
21
    {
22
        if (is_string($accessor = static::accessor())) {
23 2
            $accessor = service($accessor);
24
        }
25
26
        if (! is_object($accessor)) {
27 2
            throw new InvalidArgumentException(sprintf('La methode `%s::accessor` doit retourner un object ou le nom d\'un service.', static::class));
28
        }
29
30 14
        return $accessor->{$name}(...$arguments);
31
    }
32
33
    public function __call(string $name, array $arguments = [])
34
    {
35 2
        return static::__callStatic($name, $arguments);
36
    }
37
}
38