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

CheckGlobalInteractionOptionsMiddleware   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 69
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setIsQuiet() 0 7 3
A __construct() 0 4 1
A inputReceived() 0 8 1
A setIsInteractive() 0 7 3
A setIsSilent() 0 7 3
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\Data\Config;
19
use Valkyrja\Cli\Interaction\Input\Contract\InputContract;
20
use Valkyrja\Cli\Interaction\Output\Contract\OutputContract;
21
use Valkyrja\Cli\Middleware\Contract\InputReceivedMiddlewareContract;
22
use Valkyrja\Cli\Middleware\Handler\Contract\InputReceivedHandlerContract;
23
use Valkyrja\Cli\Routing\Data\Option\NoInteractionOptionParameter;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Cli\Routing\Dat...eractionOptionParameter 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...
24
use Valkyrja\Cli\Routing\Data\Option\QuietOptionParameter;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Cli\Routing\Dat...on\QuietOptionParameter 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...
25
use Valkyrja\Cli\Routing\Data\Option\SilentOptionParameter;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Cli\Routing\Dat...n\SilentOptionParameter 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...
26
27
class CheckGlobalInteractionOptionsMiddleware implements InputReceivedMiddlewareContract
28
{
29
    public function __construct(
30
        protected Config $config,
31
        protected Env $env,
32
    ) {
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    #[Override]
39
    public function inputReceived(InputContract $input, InputReceivedHandlerContract $handler): InputContract|OutputContract
40
    {
41
        $this->setIsInteractive($input);
42
        $this->setIsQuiet($input);
43
        $this->setIsSilent($input);
44
45
        return $handler->inputReceived($input);
46
    }
47
48
    /**
49
     * Set the interactivity.
50
     *
51
     * @param InputContract $input The input
52
     *
53
     * @return void
54
     */
55
    protected function setIsInteractive(InputContract $input): void
56
    {
57
        if (
58
            $input->hasOption(NoInteractionOptionParameter::SHORT_NAME)
59
            || $input->hasOption(NoInteractionOptionParameter::NAME)
60
        ) {
61
            $this->config->isInteractive = false;
62
        }
63
    }
64
65
    /**
66
     * Set whether output is quiet.
67
     *
68
     * @param InputContract $input The input
69
     *
70
     * @return void
71
     */
72
    protected function setIsQuiet(InputContract $input): void
73
    {
74
        if (
75
            $input->hasOption(QuietOptionParameter::SHORT_NAME)
76
            || $input->hasOption(QuietOptionParameter::NAME)
77
        ) {
78
            $this->config->isQuiet = true;
79
        }
80
    }
81
82
    /**
83
     * Set whether the output is entirely silent.
84
     *
85
     * @param InputContract $input The input
86
     *
87
     * @return void
88
     */
89
    protected function setIsSilent(InputContract $input): void
90
    {
91
        if (
92
            $input->hasOption(SilentOptionParameter::SHORT_NAME)
93
            || $input->hasOption(SilentOptionParameter::NAME)
94
        ) {
95
            $this->config->isSilent = true;
96
        }
97
    }
98
}
99