RouteNameStrategy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 17
ccs 4
cts 8
cp 0.5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldCache() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\PageCacheMiddleware\Strategy\RouteNameStrategy;
5
6
use Ctw\Middleware\PageCacheMiddleware\Strategy\StrategyInterface;
7
use Mezzio\Router\Route;
8
use Mezzio\Router\RouteResult;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
class RouteNameStrategy extends AbstractStrategy implements StrategyInterface
12
{
13 2
    public function shouldCache(ServerRequestInterface $request): bool
14
    {
15 2
        $routeResult = $request->getAttribute(RouteResult::class);
16
17 2
        if (!$routeResult instanceof RouteResult) {
18 2
            return false;
19
        }
20
21
        $matchedRoute = $routeResult->getMatchedRoute();
22
23
        if (!$matchedRoute instanceof Route) {
24
            return false;
25
        }
26
27
        return in_array($matchedRoute->getName(), $this->getNames(), true);
28
    }
29
}
30