• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valkyrjaio / valkyrja / 20687263522

04 Jan 2026 03:56AM UTC coverage: 74.209%. Remained the same
20687263522

push

github

web-flow
[CI] Add dead code rector rules (#337)

# Description

Add dead code rector rules.

## Types of changes

- [ ] Bug fix _(non-breaking change which fixes an issue)_
    <!-- Target the lowest major affected branch -->
- [X] New feature _(non-breaking change which adds functionality)_
    <!-- Target master -->
- [ ] Deprecation _(breaking change which removes functionality)_
    <!-- Target master -->
- [ ] Breaking change _(fix or feature that would cause existing
functionality
  to change)_
<!-- Target master, unless this is a bug fix in which case let's chat
-->
- [ ] Documentation improvement
    <!-- Target appropriate branch -->

8419 of 11345 relevant lines covered (74.21%)

8.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.9
/src/Valkyrja/Cli/Server/Handler/InputHandler.php
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 <melechmizrachi@gmail.com>
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\Server\Handler;
15

16
use Override;
17
use Throwable;
18
use Valkyrja\Cli\Interaction\Data\Config as InteractionConfig;
19
use Valkyrja\Cli\Interaction\Enum\ExitCode;
20
use Valkyrja\Cli\Interaction\Factory\Contract\OutputFactoryContract;
21
use Valkyrja\Cli\Interaction\Factory\OutputFactory;
22
use Valkyrja\Cli\Interaction\Input\Contract\InputContract;
23
use Valkyrja\Cli\Interaction\Message\Banner;
24
use Valkyrja\Cli\Interaction\Message\ErrorMessage;
25
use Valkyrja\Cli\Interaction\Message\Message;
26
use Valkyrja\Cli\Interaction\Message\NewLine;
27
use Valkyrja\Cli\Interaction\Output\Contract\OutputContract;
28
use Valkyrja\Cli\Middleware\Handler\Contract\ExitedHandlerContract;
29
use Valkyrja\Cli\Middleware\Handler\Contract\InputReceivedHandlerContract;
30
use Valkyrja\Cli\Middleware\Handler\Contract\ThrowableCaughtHandlerContract;
31
use Valkyrja\Cli\Middleware\Handler\ExitedHandler;
32
use Valkyrja\Cli\Middleware\Handler\InputReceivedHandler;
33
use Valkyrja\Cli\Middleware\Handler\ThrowableCaughtHandler;
34
use Valkyrja\Cli\Routing\Dispatcher\Contract\RouterContract;
35
use Valkyrja\Cli\Routing\Dispatcher\Router;
36
use Valkyrja\Cli\Server\Handler\Contract\InputHandlerContract as Contract;
37
use Valkyrja\Cli\Server\Support\Exiter;
38
use Valkyrja\Container\Manager\Container;
39
use Valkyrja\Container\Manager\Contract\ContainerContract;
40

41
class InputHandler implements Contract
42
{
43
    public function __construct(
2✔
44
        protected ContainerContract $container = new Container(),
45
        protected RouterContract $router = new Router(),
46
        protected InputReceivedHandlerContract $inputReceivedHandler = new InputReceivedHandler(),
47
        protected ThrowableCaughtHandlerContract $throwableCaughtHandler = new ThrowableCaughtHandler(),
48
        protected ExitedHandlerContract $exitedHandler = new ExitedHandler(),
49
        protected InteractionConfig $interactionConfig = new InteractionConfig(),
50
        protected OutputFactoryContract $outputFactory = new OutputFactory(),
51
    ) {
52
    }
2✔
53

54
    /**
55
     * Handle the input.
56
     *
57
     * @param InputContract $input The input
58
     */
59
    #[Override]
1✔
60
    public function handle(InputContract $input): OutputContract
61
    {
62
        try {
63
            $output = $this->dispatchRouter($input);
1✔
64
        } catch (Throwable $throwable) {
×
65
            $output = $this->getOutputFromThrowable($input, $throwable);
×
66
            $output = $this->throwableCaughtHandler->throwableCaught($input, $output, $throwable);
×
67
        }
68

69
        // Set the returned output in the container
70
        $this->container->setSingleton(OutputContract::class, $output);
1✔
71

72
        return $output;
1✔
73
    }
74

75
    /**
76
     * Handle exiting the handler.
77
     *
78
     * @param InputContract  $input  The input
79
     * @param OutputContract $output The output
80
     */
81
    #[Override]
1✔
82
    public function exit(InputContract $input, OutputContract $output): void
83
    {
84
        // Dispatch the exited middleware
85
        $this->exitedHandler->exited($input, $output);
1✔
86
    }
87

88
    /**
89
     * Run the handler.
90
     */
91
    #[Override]
1✔
92
    public function run(InputContract $input): void
93
    {
94
        $output = $this->handle($input);
1✔
95

96
        $output->writeMessages();
1✔
97

98
        $this->exit($input, $output);
1✔
99

100
        $exitCode = $output->getExitCode();
1✔
101

102
        if ($exitCode instanceof ExitCode) {
1✔
103
            $exitCode = $exitCode->value;
1✔
104
        }
105

106
        Exiter::exit($exitCode);
1✔
107
    }
108

109
    /**
110
     * Dispatch the input via the router.
111
     *
112
     * @param InputContract $input The input
113
     */
114
    protected function dispatchRouter(InputContract $input): OutputContract
1✔
115
    {
116
        // Set the request object in the container
117
        $this->container->setSingleton(InputContract::class, $input);
1✔
118

119
        // Dispatch the before input received middleware
120
        $inputAfterMiddleware = $this->inputReceivedHandler->inputReceived($input);
1✔
121

122
        // If the return value after middleware is a response return it
123
        if ($inputAfterMiddleware instanceof OutputContract) {
1✔
124
            return $inputAfterMiddleware;
×
125
        }
126

127
        // Set the returned request in the container
128
        $this->container->setSingleton(InputContract::class, $inputAfterMiddleware);
1✔
129

130
        return $this->router->dispatch($inputAfterMiddleware);
1✔
131
    }
132

133
    /**
134
     * Get an output from a throwable.
135
     *
136
     * @param InputContract $input     The input
137
     * @param Throwable     $throwable The throwable
138
     */
139
    protected function getOutputFromThrowable(InputContract $input, Throwable $throwable): OutputContract
×
140
    {
141
        $commandName = $input->getCommandName();
×
142

143
        return $this->outputFactory
×
144
            ->createOutput(exitCode: ExitCode::ERROR)
×
145
            ->withMessages(
×
146
                new Banner(new ErrorMessage('Cli Server Error:')),
×
147
                new NewLine(),
×
148
                new ErrorMessage('Command:'),
×
149
                new Message(" $commandName"),
×
150
                new NewLine(),
×
151
                new NewLine(),
×
152
                new ErrorMessage('Message:'),
×
153
                new Message(' ' . $throwable->getMessage()),
×
154
                new NewLine(),
×
155
                new NewLine(),
×
156
                new ErrorMessage('Line:'),
×
157
                new Message(' ' . ((string) $throwable->getLine())),
×
158
                new NewLine(),
×
159
                new NewLine(),
×
160
                new ErrorMessage('Trace:'),
×
161
                new NewLine(),
×
162
                new Message($throwable->getTraceAsString() . "\n"),
×
163
            );
×
164
    }
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc