Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
17 | final class AddPathPlugin implements Plugin |
||
18 | { |
||
19 | /** |
||
20 | * The URI. |
||
21 | * |
||
22 | * @var \Psr\Http\Message\UriInterface |
||
23 | */ |
||
24 | private $uri; |
||
25 | |||
26 | /** |
||
27 | * AddPathPlugin constructor. |
||
28 | * |
||
29 | * @param \Psr\Http\Message\UriInterface $uri |
||
30 | * The URI. |
||
31 | */ |
||
32 | public function __construct(UriInterface $uri) |
||
33 | { |
||
34 | if ('' === $uri->getPath()) { |
||
35 | throw new \InvalidArgumentException('URI path cannot be empty'); |
||
36 | } |
||
37 | if ('/' === substr($uri->getPath(), -1)) { |
||
38 | $uri = $uri->withPath(rtrim($uri->getPath(), '/')); |
||
39 | } |
||
40 | $this->uri = $uri; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise |
||
55 | } |
||
56 | } |
||
57 |