Passed
Pull Request — master (#181)
by Melech
01:19
created

Route::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 9

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
/*
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\Cli\Routing\Attribute;
15
16
use Attribute;
17
use Valkyrja\Cli\Interaction\Message\Contract\Message;
18
use Valkyrja\Cli\Middleware\Contract\CommandDispatchedMiddleware;
19
use Valkyrja\Cli\Middleware\Contract\CommandMatchedMiddleware;
20
use Valkyrja\Cli\Middleware\Contract\ExitedMiddleware;
21
use Valkyrja\Cli\Middleware\Contract\ThrowableCaughtMiddleware;
22
use Valkyrja\Cli\Routing\Data\Contract\Parameter;
23
use Valkyrja\Cli\Routing\Data\Route as Model;
24
use Valkyrja\Dispatcher\Data\Contract\MethodDispatch;
25
use Valkyrja\Dispatcher\Data\MethodDispatch as DefaultDispatch;
26
27
/**
28
 * Attribute Route.
29
 *
30
 * @author Melech Mizrachi
31
 */
32
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
33
class Route extends Model
34
{
35
    /**
36
     * @param non-empty-string                            $name                        The 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...
37
     * @param non-empty-string                            $description                 The description
38
     * @param Message                                     $helpText                    The help text
39
     * @param class-string<CommandMatchedMiddleware>[]    $commandMatchedMiddleware    The command matched middleware
40
     * @param class-string<CommandDispatchedMiddleware>[] $commandDispatchedMiddleware The command dispatched middleware
41
     * @param class-string<ThrowableCaughtMiddleware>[]   $throwableCaughtMiddleware   The throwable caught middleware
42
     * @param class-string<ExitedMiddleware>[]            $exitedMiddleware            The exited middleware
43
     * @param Parameter[]                                 $parameters                  The parameters
44
     */
45
    public function __construct(
46
        protected string $name,
47
        protected string $description,
48
        protected Message $helpText,
49
        protected MethodDispatch $dispatch = new DefaultDispatch(self::class, '__construct'),
50
        protected array $commandMatchedMiddleware = [],
51
        protected array $commandDispatchedMiddleware = [],
52
        protected array $throwableCaughtMiddleware = [],
53
        protected array $exitedMiddleware = [],
54
        array $parameters = [],
55
    ) {
56
        parent::__construct(
57
            name: $name,
58
            description: $description,
59
            helpText: $helpText,
60
            dispatch: $dispatch,
61
            commandMatchedMiddleware: $commandMatchedMiddleware,
62
            commandDispatchedMiddleware: $commandDispatchedMiddleware,
63
            throwableCaughtMiddleware: $throwableCaughtMiddleware,
64
            exitedMiddleware: $exitedMiddleware,
65
            parameters: $parameters,
66
        );
67
    }
68
}
69