Passed
Pull Request — master (#196)
by Rustam
13:36
created

Route::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 19
ccs 10
cts 10
cp 1
crap 1
rs 9.9666

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
declare(strict_types=1);
4
5
namespace Yiisoft\Router\Attribute;
6
7
use Attribute;
8
use Stringable;
9
use Yiisoft\Router\Route as RouteObject;
10
11
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
12
final class Route implements RouteAttributeInterface
13
{
14
    private RouteObject $route;
15
16
    /**
17
     * @param array<string,scalar|Stringable|null> $defaults Parameter default values indexed by parameter names.
18
     * @param bool $override Marks route as override. When added it will replace existing route with the same name.
19
     * @param array $disabledMiddlewares Excludes middleware from being invoked when action is handled.
20
     * It is useful to avoid invoking one of the parent group middleware for
21
     * a certain route.
22
     */
23 2
    public function __construct(
24
        array $methods,
25
        string $pattern,
26
        ?string $name = null,
27
        array $middlewares = [],
28
        array $defaults = [],
29
        array $hosts = [],
30
        bool $override = false,
31
        array $disabledMiddlewares = []
32
    ) {
33 2
        $this->route = new RouteObject(
34 2
            methods: $methods,
35 2
            pattern: $pattern,
36 2
            name: $name,
37 2
            middlewareDefinitions: $middlewares,
38 2
            defaults: $defaults,
39 2
            hosts: $hosts,
40 2
            override: $override,
41 2
            disabledMiddlewareDefinitions: $disabledMiddlewares
42 2
        );
43
    }
44
45 2
    public function getRoute(): RouteObject
46
    {
47 2
        return $this->route;
48
    }
49
}
50