RequestUriGenerator::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\PageCacheMiddleware\IdGenerator\RequestUriGenerator;
5
6
use Ctw\Middleware\PageCacheMiddleware\Exception\RuntimeException;
7
use Ctw\Middleware\PageCacheMiddleware\IdGenerator\IdGeneratorInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class RequestUriGenerator extends AbstractIdGenerator implements IdGeneratorInterface
11
{
12
    /**
13
     * Generate an ID based on the request's path and query
14
     */
15 4
    public function generate(ServerRequestInterface $request): string
16
    {
17 4
        $uri = $request->getUri();
18
19 4
        if ('' === $uri->getPath()) {
20 2
            $message = 'Cannot auto-detect current page identity';
21 2
            throw new RuntimeException($message);
22
        }
23
24 2
        $vars = [self::SALT, $uri->getQuery()];
25
26 2
        return $this->getHash($vars);
27
    }
28
}
29