Completed
Pull Request — master (#75)
by
unknown
02:42
created

Phroute::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Psr7Middlewares\Middleware;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Phroute\Phroute\Dispatcher;
8
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
9
use Phroute\Phroute\Exception\BadRouteException;
10
11
class Phroute
12
{
13
14
    /**
15
     * @var Dispatcher Phroute dispatcher
16
     */
17
    private $router;
18
19
    /**
20
     * Set the Dispatcher instance.
21
     *
22
     * @param Dispatcher|null $router
23
     */
24
    public function __construct(Dispatcher $router)
25
    {
26
        $this->router = $router;
27
    }
28
29
    /**
30
     * Execute the middleware.
31
     *
32
     * @param ServerRequestInterface $request
33
     * @param ResponseInterface      $response
34
     * @param callable               $next
35
     *
36
     * @return ResponseInterface
37
     */
38
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
39
        try {
40
            $response = $this->router->dispatch($request->getMethod(), $request->getUri()->getPath());
41
            $response = $response->withStatus(200);
42
        }
43
        catch (HttpRouteNotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class Phroute\Phroute\Exceptio...pRouteNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
44
                return $response->withStatus(404);
45
        }
46
        catch (BadRouteException $e) {
0 ignored issues
show
Bug introduced by
The class Phroute\Phroute\Exception\BadRouteException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
47
                return $response->withStatus(405);
48
        }
49
        return $next($request, $response);
50
    }
51
}
52