Passed
Push — master ( 41e710...91ffae )
by Aleksei
06:19 queued 21s
created

Proxy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
eloc 8
c 2
b 1
f 0
dl 0
loc 42
ccs 11
cts 13
cp 0.8462
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 4
A __toString() 0 3 1
A getInterface() 0 3 1
A getReturnClass() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Config;
6
7
use Psr\Container\ContainerInterface;
8
9
class Proxy extends Binding
10
{
11
    /**
12
     * @template T
13
     * @param class-string<T> $interface
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
14
     * @param null|\Closure(ContainerInterface, \Stringable|string|null): T $fallbackFactory Factory that will be used
15
     *        to create an instance if the value is resolved from a proxy.
16
     */
17 398
    public function __construct(
18
        protected readonly string $interface,
19
        public readonly bool $singleton = false,
20
        public readonly ?\Closure $fallbackFactory = null,
21
    ) {
22 398
        \interface_exists($interface) or throw new \InvalidArgumentException(
23 398
            "Interface `{$interface}` does not exist.",
24 398
        );
25 397
        $this->singleton and $this->fallbackFactory !== null and throw new \InvalidArgumentException(
26 397
            'Singleton proxies must not have a fallback factory.',
27 397
        );
28
    }
29
30
    /**
31
     * @return class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
32
     * @deprecated Use {@see getReturnClass()} instead.
33
     */
34
    public function getInterface(): string
35
    {
36
        return $this->interface;
37
    }
38
39
    /**
40
     * @return class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
41
     * @internal
42
     */
43 393
    public function getReturnClass(): string
44
    {
45 393
        return $this->interface;
46
    }
47
48 1
    public function __toString(): string
49
    {
50 1
        return \sprintf('Proxy to `%s`', $this->interface);
51
    }
52
}
53