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

Phroute   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 13 3
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