Passed
Push — master ( f2a84f...718fb6 )
by Melech
03:59
created

ConstantDispatch   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
dl 0
loc 64
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A withClass() 0 8 1
A __construct() 0 4 1
A __toString() 0 5 2
A withConstant() 0 8 1
A getConstant() 0 4 1
A getClass() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Dispatcher\Data;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Valkyrja\Dispatcher\Data\Contract\ConstantDispatch as Contract;
18
19
/**
20
 * Class ConstantDispatch.
21
 *
22
 * @author Melech Mizrachi
23
 */
24
class ConstantDispatch extends Dispatch implements Contract
25
{
26
    /**
27
     * @param non-empty-string  $constant The constant name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
28
     * @param class-string|null $class    The class name
29
     */
30
    public function __construct(
31
        protected string $constant,
32
        protected string|null $class = null,
33
    ) {
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    #[Override]
40
    public function getConstant(): string
41
    {
42
        return $this->constant;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    #[Override]
49
    public function withConstant(string $constant): static
50
    {
51
        $new = clone $this;
52
53
        $new->constant = $constant;
54
55
        return $new;
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    #[Override]
62
    public function getClass(): string|null
63
    {
64
        return $this->class;
65
    }
66
67
    /**
68
     * @inheritDoc
69
     */
70
    #[Override]
71
    public function withClass(string|null $class = null): static
72
    {
73
        $new = clone $this;
74
75
        $new->class = $class;
76
77
        return $new;
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    #[Override]
84
    public function __toString(): string
85
    {
86
        return ($this->class !== null ? $this->class . '::' : '')
87
            . $this->constant;
88
    }
89
}
90