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

DeprecationProxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 35
ccs 4
cts 13
cp 0.3076
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A getInterface() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Config;
6
7
/**
8
 * @internal
9
 */
10
final class DeprecationProxy extends Proxy
11
{
12
    /**
13
     * @param class-string $interface
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...
14
     */
15 365
    public function __construct(
16
        string $interface,
17
        bool $singleton = false,
18
        private readonly string|\BackedEnum|null $scope = null,
19
        private readonly ?string $version = null,
20
        private readonly ?string $message = null,
21
    ) {
22 365
        if (($scope === null || $version === null) && $message === null) {
23 3
            throw new \InvalidArgumentException('Scope and version or custom message must be provided.');
24
        }
25
26 362
        parent::__construct($interface, $singleton);
27
    }
28
29
    /**
30
     * @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...
31
     * @deprecated
32
     */
33
    public function getInterface(): string
34
    {
35
        $message = $this->message ?? \sprintf(
36
            'Using `%s` outside of the `%s` scope is deprecated and will be impossible in version %s.',
37
            $this->interface,
38
            $this->scope instanceof \BackedEnum ? $this->scope->value : $this->scope,
0 ignored issues
show
Bug introduced by
Accessing value on the interface BackedEnum suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
39
            $this->version,
40
        );
41
42
        @\trigger_error($message, \E_USER_DEPRECATED);
43
44
        return parent::getInterface();
0 ignored issues
show
Deprecated Code introduced by
The function Spiral\Core\Config\Proxy::getInterface() has been deprecated: Use {@see getReturnClass()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

44
        return /** @scrutinizer ignore-deprecated */ parent::getInterface();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
45
    }
46
}
47