Passed
Push — master ( 8f9974...195c48 )
by Divine Niiquaye
13:24
created

Application   A

Complexity

Total Complexity 42

Size/Duplication

Total Lines 295
Duplicated Lines 0 %

Test Coverage

Coverage 36.45%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 90
c 5
b 0
f 0
dl 0
loc 295
ccs 39
cts 107
cp 0.3645
rs 9.0399
wmc 42

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 24 3
A match() 0 3 1
A pipe() 0 3 1
A getDispatcher() 0 3 1
A delete() 0 3 1
A handleRouterException() 0 17 4
A generateUri() 0 3 1
A handleThrowable() 0 25 5
A post() 0 3 1
A resolveMiddlewares() 0 15 6
A put() 0 3 1
A pipes() 0 3 1
A handle() 0 25 6
A group() 0 3 1
A createWelcomeResponse() 0 11 1
A strictAutowiring() 0 3 1
A run() 0 23 5
A options() 0 3 1
A patch() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like Application often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Application, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade;
19
20
use Biurad\Http\{Interfaces\Psr17Interface, Request, Response, Response\HtmlResponse};
21
use Biurad\Http\Factory\Psr17Factory;
22
use Flight\Routing\{Exceptions\RouteNotFoundException, Route, RouteCollection, Router};
23
use Fig\Http\Message\RequestMethodInterface;
24
use Flight\Routing\Generator\GeneratedUri;
25
use Flight\Routing\Interfaces\RouteMatcherInterface;
26
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
27
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};
28
use Laminas\Stratigility\Middleware\{CallableMiddlewareDecorator, RequestHandlerMiddleware};
29
use Laminas\{HttpHandlerRunner\Emitter\SapiStreamEmitter, Stratigility\Utils};
0 ignored issues
show
Coding Style introduced by
Compound namespaces cannot have a depth more than 2
Loading history...
Bug introduced by
The type Laminas\HttpHandlerRunne...itter\SapiStreamEmitter 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...
30
use Psr\EventDispatcher\EventDispatcherInterface;
31
use Rade\DI\Definitions\{Reference, Statement};
32
use Symfony\Component\Console\Application as ConsoleApplication;
33
use Symfony\Component\HttpFoundation\RequestStack;
34
35
/**
36
 * The Rade framework core class.
37
 *
38
 * @author Divine Niiquaye Ibok <[email protected]>
39
 */
40
class Application extends DI\Container implements RouterInterface, KernelInterface
41
{
42
    use Traits\HelperTrait;
43
44
    public const VERSION = '2.0.0-DEV';
45
46
    /**
47
     * Instantiate a new Application.
48
     */
49 14
    public function __construct(Psr17Interface $psr17Factory = null, EventDispatcherInterface $dispatcher = null, bool $debug = false)
50
    {
51 14
        parent::__construct();
52
53 14
        if (empty($this->methodsMap)) {
54 14
            $this->definitions['http.router'] = Router::withCollection();
55 14
            $this->definitions['request_stack'] = new RequestStack();
56 14
            $this->definitions['psr17.factory'] = $psr17Factory = ($psr17Factory ?? new Psr17Factory());
57 14
            $this->definitions['events.dispatcher'] = $dispatcher = ($dispatcher ?? new Handler\EventHandler());
58
59 14
            $this->types(
60
                [
61 14
                    'http.router' => [Router::class, RouteMatcherInterface::class],
62
                    'request_stack' => [RequestStack::class],
63 14
                    'psr17.factory' => DI\Resolver::autowireService($psr17Factory),
64 14
                    'events.dispatcher' => DI\Resolver::autowireService($dispatcher),
65
                ]
66
            );
67
68 14
            unset($psr17Factory, $dispatcher);
69
        }
70
71 14
        if (!isset($this->parameters['debug'])) {
72 14
            $this->parameters['debug'] = $debug;
73
        }
74 14
    }
75
76
    /**
77
     * If true, exception will be thrown on resolvable services with are not typed.
78
     */
79
    public function strictAutowiring(bool $boolean = true): void
80
    {
81
        $this->resolver->setStrictAutowiring($boolean);
82
    }
83
84 4
    public function getDispatcher(): EventDispatcherInterface
85
    {
86 4
        return $this->services['events.dispatcher'] ?? $this->get('events.dispatcher');
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     *
92
     * @param MiddlewareInterface|RequestHandlerInterface|Reference|Statement|callable ...$middlewares
93
     */
94
    public function pipe(object ...$middlewares): void
95
    {
96
        $this->get('http.router')->pipe(...$this->resolveMiddlewares($middlewares));
0 ignored issues
show
Bug introduced by
The method pipe() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        $this->get('http.router')->/** @scrutinizer ignore-call */ pipe(...$this->resolveMiddlewares($middlewares));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
introduced by
The method pipe() does not exist on Rade\DI\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        $this->get('http.router')->/** @scrutinizer ignore-call */ pipe(...$this->resolveMiddlewares($middlewares));
Loading history...
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     *
102
     * @param MiddlewareInterface|RequestHandlerInterface|Reference|Statement|callable ...$middlewares
103
     */
104
    public function pipes(string $named, object ...$middlewares): void
105
    {
106
        $this->get('http.router')->pipes($named, ...$this->resolveMiddlewares($middlewares));
0 ignored issues
show
Bug introduced by
The method pipes() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        $this->get('http.router')->/** @scrutinizer ignore-call */ pipes($named, ...$this->resolveMiddlewares($middlewares));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
introduced by
The method pipes() does not exist on Rade\DI\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        $this->get('http.router')->/** @scrutinizer ignore-call */ pipes($named, ...$this->resolveMiddlewares($middlewares));
Loading history...
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function generateUri(string $routeName, array $parameters = []): GeneratedUri
113
    {
114
        return $this->get('http.router')->generateUri($routeName, $parameters);
0 ignored issues
show
introduced by
The method generateUri() does not exist on Rade\DI\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

114
        return $this->get('http.router')->/** @scrutinizer ignore-call */ generateUri($routeName, $parameters);
Loading history...
Bug introduced by
The method generateUri() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

114
        return $this->get('http.router')->/** @scrutinizer ignore-call */ generateUri($routeName, $parameters);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The expression return $this->get('http....routeName, $parameters) returns the type Flight\Routing\Generator\GeneratedUri which is incompatible with the return type mandated by Rade\RouterInterface::generateUri() of Rade\GeneratedUri.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120 7
    public function match(string $pattern, array $methods = Route::DEFAULT_METHODS, $to = null): Route
121
    {
122 7
        return ($this->services['http.router'] ?? $this->get('http.router'))->getCollection()->addRoute($pattern, $methods, $to)->getRoute();
0 ignored issues
show
Bug introduced by
The method getCollection() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
        return ($this->services['http.router'] ?? $this->get('http.router'))->/** @scrutinizer ignore-call */ getCollection()->addRoute($pattern, $methods, $to)->getRoute();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getCollection() does not exist on Rade\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
        return ($this->services['http.router'] ?? $this->get('http.router'))->/** @scrutinizer ignore-call */ getCollection()->addRoute($pattern, $methods, $to)->getRoute();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getCollection() does not exist on Rade\DI\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
        return ($this->services['http.router'] ?? $this->get('http.router'))->/** @scrutinizer ignore-call */ getCollection()->addRoute($pattern, $methods, $to)->getRoute();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128 1
    public function post(string $pattern, $to = null): Route
129
    {
130 1
        return $this->match($pattern, [RequestMethodInterface::METHOD_POST], $to);
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136 1
    public function put(string $pattern, $to = null): Route
137
    {
138 1
        return $this->match($pattern, [RequestMethodInterface::METHOD_PUT], $to);
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144 1
    public function delete(string $pattern, $to = null): Route
145
    {
146 1
        return $this->match($pattern, [RequestMethodInterface::METHOD_DELETE], $to);
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function options(string $pattern, $to = null): Route
153
    {
154
        return $this->match($pattern, [RequestMethodInterface::METHOD_OPTIONS], $to);
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160 1
    public function patch(string $pattern, $to = null): Route
161
    {
162 1
        return $this->match($pattern, [RequestMethodInterface::METHOD_PATCH], $to);
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168 1
    public function group(string $prefix, $collection = null): RouteCollection
169
    {
170 1
        return $this->get('http.router')->getCollection()->group($prefix, $collection);
171
    }
172
173
    /**
174
     * Handles the request and delivers the response.
175
     *
176
     * @param ServerRequestInterface|null $request Request to process
177
     *
178
     * @throws \Throwable
179
     *
180
     * @return int|bool
181
     */
182
    public function run(ServerRequestInterface $request = null, bool $catch = true)
183
    {
184
        if ($this->isRunningInConsole()) {
185
            $this->get(ConsoleApplication::class)->run();
0 ignored issues
show
Bug introduced by
The method run() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

185
            $this->get(ConsoleApplication::class)->/** @scrutinizer ignore-call */ run();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
introduced by
The method run() does not exist on Rade\DI\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

185
            $this->get(ConsoleApplication::class)->/** @scrutinizer ignore-call */ run();
Loading history...
186
        }
187
188
        if (null === $request) {
189
            $request = $this->get('psr17.factory')->fromGlobalRequest();
0 ignored issues
show
Bug introduced by
The method fromGlobalRequest() does not exist on Rade\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

189
            $request = $this->get('psr17.factory')->/** @scrutinizer ignore-call */ fromGlobalRequest();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method fromGlobalRequest() does not exist on Rade\DI\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

189
            $request = $this->get('psr17.factory')->/** @scrutinizer ignore-call */ fromGlobalRequest();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method fromGlobalRequest() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

189
            $request = $this->get('psr17.factory')->/** @scrutinizer ignore-call */ fromGlobalRequest();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
190
        }
191
192
        $response = $this->handle($request, $catch);
193
194
        if ($response instanceof Response) {
195
            $response->getResponse()->send();
196
197
            return true;
198
        }
199
200
        if (class_exists(SapiStreamEmitter::class)) {
201
            return (new SapiStreamEmitter())->emit($response);
202
        }
203
204
        throw new \RuntimeException(\sprintf('Unable to emit response onto the browser. Try running "composer require laminas/laminas-httphandlerrunner".'));
205
    }
206
207
    /**
208
     * Handles a request to convert it to a response.
209
     *
210
     * Exceptions are not caught.
211
     *
212
     * @param bool $catch Whether to catch exceptions or not
213
     */
214 4
    public function handle(ServerRequestInterface $request, bool $catch = true): ResponseInterface
215
    {
216 4
        if (!$this->has(RequestHandlerInterface::class)) {
217 4
            $this->definitions[RequestHandlerInterface::class] = new Handler\RouteHandler($this);
218
        }
219
220
        try {
221 4
            $response = $this->get('http.router')->process($request, $this->get(RequestHandlerInterface::class));
0 ignored issues
show
Bug introduced by
The method process() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

221
            $response = $this->get('http.router')->/** @scrutinizer ignore-call */ process($request, $this->get(RequestHandlerInterface::class));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method process() does not exist on Rade\DI\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

221
            $response = $this->get('http.router')->/** @scrutinizer ignore-call */ process($request, $this->get(RequestHandlerInterface::class));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method process() does not exist on Rade\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

221
            $response = $this->get('http.router')->/** @scrutinizer ignore-call */ process($request, $this->get(RequestHandlerInterface::class));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
222
223 4
            if ($request instanceof Request) {
224 4
                $request = $request->withRequest($this->get('request_stack')->getMainRequest());
0 ignored issues
show
Bug introduced by
The method getMainRequest() does not exist on Rade\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

224
                $request = $request->withRequest($this->get('request_stack')->/** @scrutinizer ignore-call */ getMainRequest());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getMainRequest() does not exist on PhpParser\Builder\Method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

224
                $request = $request->withRequest($this->get('request_stack')->/** @scrutinizer ignore-call */ getMainRequest());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getMainRequest() does not exist on Rade\DI\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

224
                $request = $request->withRequest($this->get('request_stack')->/** @scrutinizer ignore-call */ getMainRequest());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
225
            }
226
227 4
            $this->getDispatcher()->dispatch($event = new Event\ResponseEvent($this, $request, $response));
0 ignored issues
show
Bug introduced by
It seems like $request can also be of type Biurad\Http\Request; however, parameter $request of Rade\Event\ResponseEvent::__construct() does only seem to accept Psr\Http\Message\ServerRequestInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

227
            $this->getDispatcher()->dispatch($event = new Event\ResponseEvent($this, /** @scrutinizer ignore-type */ $request, $response));
Loading history...
228
        } catch (\Throwable $e) {
229
            if (!$catch || $this->isRunningInConsole()) {
230
                throw $e;
231
            }
232
233
            return $this->handleThrowable($e, $request);
0 ignored issues
show
Bug introduced by
It seems like $request can also be of type Biurad\Http\Request; however, parameter $request of Rade\Application::handleThrowable() does only seem to accept Psr\Http\Message\ServerRequestInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

233
            return $this->handleThrowable($e, /** @scrutinizer ignore-type */ $request);
Loading history...
234 4
        } finally {
235 4
            $this->getDispatcher()->dispatch(new Event\TerminateEvent($this, $request));
0 ignored issues
show
Bug introduced by
It seems like $request can also be of type Biurad\Http\Request; however, parameter $request of Rade\Event\TerminateEvent::__construct() does only seem to accept Psr\Http\Message\ServerRequestInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

235
            $this->getDispatcher()->dispatch(new Event\TerminateEvent($this, /** @scrutinizer ignore-type */ $request));
Loading history...
236
        }
237
238 4
        return $event->getResponse();
239
    }
240
241
    /**
242
     * Handle RouteNotFoundException for Flight Routing.
243
     *
244
     * @return RouteNotFoundException|ResponseInterface
245
     */
246
    protected function handleRouterException(RouteNotFoundException $e, ServerRequestInterface $request)
247
    {
248
        if (empty($pathInfo = $request->getServerParams()['PATH_INFO'] ?? '')) {
249
            $pathInfo = $request->getUri()->getPath();
250
        }
251
252
        if ('/' === $pathInfo) {
253
            return $this->createWelcomeResponse();
254
        }
255
256
        $message = $e->getMessage();
257
258
        if ('' !== $referer = $request->getHeaderLine('referer')) {
259
            $message .= \sprintf(' (from "%s")', $referer);
260
        }
261
262
        return new RouteNotFoundException($message, 404);
263
    }
264
265
    /**
266
     * Handles a throwable by trying to convert it to a Response.
267
     *
268
     * @throws \Throwable
269
     */
270
    protected function handleThrowable(\Throwable $e, ServerRequestInterface $request): ResponseInterface
271
    {
272
        $this->getDispatcher()->dispatch($event = new Event\ExceptionEvent($this, $request, $e));
273
274
        // a listener might have replaced the exception
275
        $e = $event->getThrowable();
276
277
        if (null === $response = $event->getResponse()) {
278
            if ($e instanceof RouteNotFoundException) {
279
                $e = $this->handleRouterException($e, $request);
280
281
                if ($e instanceof ResponseInterface) {
282
                    return $e;
283
                }
284
            }
285
286
            throw $e;
287
        }
288
289
        // ensure that we actually have an error response and keep the HTTP status code and headers
290
        if (!$event->isAllowingCustomResponseCode()) {
291
            $response = $response->withStatus(Utils::getStatusCode($e, $response));
292
        }
293
294
        return $response;
295
    }
296
297
    /**
298
     * The default welcome page for application.
299
     */
300
    protected function createWelcomeResponse(): ResponseInterface
301
    {
302
        $debug = $this->parameters['debug'];
303
        $version = self::VERSION;
304
        $docVersion = $version[0] . '.x.x';
305
306
        \ob_start();
307
308
        include __DIR__ . '/Resources/welcome.phtml';
309
310
        return new HtmlResponse((string) \ob_get_clean(), 404);
311
    }
312
313
    /**
314
     * Resolve Middlewares.
315
     *
316
     * @param array<int,MiddlewareInterface|RequestHandlerInterface|Reference|Statement|callable> $middlewares
317
     *
318
     * @return array<int,MiddlewareInterface>
319
     */
320
    protected function resolveMiddlewares(array $middlewares): array
321
    {
322
        foreach ($middlewares as $offset => $middleware) {
323
            if ($middleware instanceof RequestHandlerInterface) {
324
                $middlewares[$offset] = new RequestHandlerMiddleware($middleware);
325
            } elseif ($middleware instanceof Statement) {
326
                $middlewares[$offset] = $this->resolver->resolve($middleware->getValue(), $middleware->getArguments());
327
            } elseif ($middleware instanceof Reference) {
328
                $middlewares[$offset] = $this->get((string) $middleware);
329
            } elseif (\is_callable($middleware)) {
330
                $middlewares[$offset] = new CallableMiddlewareDecorator($middleware);
0 ignored issues
show
Bug introduced by
It seems like $middleware can also be of type Psr\Http\Server\MiddlewareInterface; however, parameter $middleware of Laminas\Stratigility\Mid...ecorator::__construct() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

330
                $middlewares[$offset] = new CallableMiddlewareDecorator(/** @scrutinizer ignore-type */ $middleware);
Loading history...
331
            }
332
        }
333
334
        return $middlewares;
335
    }
336
}
337