Route::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 4
b 0
f 0
nc 1
nop 14
dl 0
loc 23
ccs 1
cts 1
cp 1
crap 1
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\Annotation;
15
16
use Attribute;
17
use Fig\Http\Message\RequestMethodInterface;
18
use Sunrise\Coder\MediaTypeInterface;
19
20
/**
21
 * @link https://dev.sunrise-studio.io/docs/reference/routing-annotations?id=route
22
 * @since 2.0.0
23
 */
24
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)]
25
class Route implements RequestMethodInterface
26
{
27
    public mixed $holder = null;
28
29
    /** @var array<array-key, string> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, string> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, string>.
Loading history...
30
    public array $namePrefixes = [];
31
32
    /** @var array<array-key, string> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, string> at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, string>.
Loading history...
33
    public array $pathPrefixes = [];
34
35
    /** @var non-empty-string|null */
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
36
    public ?string $pattern = null;
37
38 50
    public function __construct(
39
        public string $name,
40
        public string $path = '',
41
        /** @var array<string, string> */
42
        public array $patterns = [],
43
        /** @var array<array-key, string> */
44
        public array $methods = [],
45
        /** @var array<string, mixed> */
46
        public array $attributes = [],
47
        /** @var array<array-key, mixed> */
48
        public array $middlewares = [],
49
        /** @var array<array-key, MediaTypeInterface> */
50
        public array $consumes = [],
51
        /** @var array<array-key, MediaTypeInterface> */
52
        public array $produces = [],
53
        /** @var array<array-key, string> */
54
        public array $tags = [],
55
        public string $summary = '',
56
        public string $description = '',
57
        public bool $isDeprecated = false,
58
        public bool $isApiRoute = false,
59
        public int $priority = 0,
60
    ) {
61 50
    }
62
}
63