RouteNameStrategy::shouldCache()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 4
cts 8
cp 0.5
rs 10
cc 3
nc 3
nop 1
crap 4.125
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