FullUriIdGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
c 0
b 0
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\PageCacheMiddleware\IdGenerator\FullUriIdGenerator;
5
6
use Ctw\Middleware\PageCacheMiddleware\Exception\RuntimeException;
7
use Ctw\Middleware\PageCacheMiddleware\IdGenerator\IdGeneratorInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class FullUriIdGenerator extends AbstractIdGenerator implements IdGeneratorInterface
11
{
12
    /**
13
     * Generate an ID based on the request's host, port, 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->getPath(), $uri->getPort(), $uri->getHost(), $uri->getQuery()];
25
26 2
        return $this->getHash($vars);
27
    }
28
}
29