Passed
Push — master ( 72934f...dfb406 )
by Aleksei
05:59 queued 26s
created

DeprecationProxy::getInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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 6
    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 6
        if (($scope === null || $version === null) && $message === null) {
23 3
            throw new \InvalidArgumentException('Scope and version or custom message must be provided.');
24
        }
25
26 3
        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
     */
32 2
    public function getInterface(): string
33
    {
34 2
        $message = $this->message ?? \sprintf(
35 2
            'Using `%s` outside of the `%s` scope is deprecated and will be impossible in version %s.',
36 2
            $this->interface,
37 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

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