LanguageDetectionMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A process() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Middleware;
6
7
use Lochmueller\LanguageDetection\Handler\Exception\AbstractHandlerException;
8
use Lochmueller\LanguageDetection\Handler\LanguageDetectionHandler;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Server\MiddlewareInterface;
12
use Psr\Http\Server\RequestHandlerInterface;
13
14
class LanguageDetectionMiddleware implements MiddlewareInterface
15
{
16
    public function __construct(protected LanguageDetectionHandler $languageDetectionHandler) {}
17
18
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
19
    {
20
        try {
21
            return $this->languageDetectionHandler->handle($request);
22
        } catch (AbstractHandlerException $exception) {
23
            return $handler->handle($request);
24
        }
25
    }
26
}
27