Passed
Pull Request — master (#1077)
by Maxim
19:13 queued 06:20
created

DeprecationProxy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInterface() 0 12 1
A __construct() 0 12 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Config;
6
7
final class DeprecationProxy extends Proxy
8
{
9
    /**
10
     * @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...
11
     */
12 6
    public function __construct(
13
        string $interface,
14
        bool $singleton = false,
15
        private readonly string|\BackedEnum|null $scope = null,
16
        private readonly ?string $version = null,
17
        private readonly ?string $message = null,
18
    ) {
19 6
        if (($scope === null || $version === null) && $message === null) {
20 3
            throw new \InvalidArgumentException('Scope and version or custom message must be provided.');
21
        }
22
23 3
        parent::__construct($interface, $singleton);
24
    }
25
26
    /**
27
     * @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...
28
     */
29 2
    public function getInterface(): string
30
    {
31 2
        $message = $this->message ?? \sprintf(
32 2
            'Using `%s` outside of the `%s` scope is deprecated and will be impossible in version %s.',
33 2
            $this->interface,
34 2
            $this->scope,
0 ignored issues
show
Bug introduced by
It seems like $this->scope can also be of type BackedEnum; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

34
            /** @scrutinizer ignore-type */ $this->scope,
Loading history...
35 2
            $this->version
36 2
        );
37
38 2
        @trigger_error($message, \E_USER_DEPRECATED);
39
40 2
        return parent::getInterface();
41
    }
42
}
43