Passed
Pull Request — master (#7)
by Victor
02:07
created

SuppressionMiddleware::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Middleware;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
use Shoot\Shoot\MiddlewareInterface;
8
use Shoot\Shoot\SuppressedException;
9
use Shoot\Shoot\View;
10
11
/**
12
 * Suppresses exceptions thrown from within the optional tag. It's recommended to add this as the last middleware.
13
 */
14
final class SuppressionMiddleware implements MiddlewareInterface
15
{
16
    /**
17
     * Process the view within the context of the current HTTP request, either before or after calling the next
18
     * middleware. Returns the processed view.
19
     *
20
     * @param View                   $view
21
     * @param ServerRequestInterface $request
22
     * @param callable               $next
23
     *
24
     * @return View
25
     */
26 9
    public function process(View $view, ServerRequestInterface $request, callable $next): View
27
    {
28
        try {
29 9
            return $next($view);
30 5
        } catch (SuppressedException $exception) {
31 3
            return $view->withSuppressedException($exception->getPrevious());
32
        }
33
    }
34
}
35