Passed
Push — master ( 0000a3...2b10f1 )
by Melech
01:30
created

CheckForHelpOptionsMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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\Middleware\InputReceived;
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\Application\Env\Env;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Application\Env\Env 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...
18
use Valkyrja\Cli\Interaction\Input\Contract\InputContract;
19
use Valkyrja\Cli\Interaction\Option\Option;
20
use Valkyrja\Cli\Interaction\Output\Contract\OutputContract;
21
use Valkyrja\Cli\Middleware\Contract\InputReceivedMiddlewareContract;
22
use Valkyrja\Cli\Middleware\Handler\Contract\InputReceivedHandlerContract;
23
24
class CheckForHelpOptionsMiddleware implements InputReceivedMiddlewareContract
25
{
26
    public function __construct(
27
        protected Env $env,
28
    ) {
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    #[Override]
35
    public function inputReceived(InputContract $input, InputReceivedHandlerContract $handler): InputContract|OutputContract
36
    {
37
        $env = $this->env;
38
        /** @var non-empty-string $name */
39
        $name = $env::CLI_HELP_OPTION_NAME;
40
        /** @var non-empty-string $shortName */
41
        $shortName = $env::CLI_HELP_OPTION_SHORT_NAME;
42
43
        // Check if the options are set for help
44
        if (
45
            $input->hasOption($shortName)
46
            || $input->hasOption($name)
47
        ) {
48
            /** @var non-empty-string $commandName */
49
            $commandName = $env::CLI_HELP_COMMAND_NAME;
50
51
            $input = $input
52
                ->withCommandName($commandName)
53
                ->withOptions(
54
                    new Option('command', $input->getCommandName()),
55
                );
56
        }
57
58
        return $handler->inputReceived($input);
59
    }
60
}
61