HttpCacheInterceptor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\RepositoryModule\Annotation\AbstractCacheControl;
8
use BEAR\Resource\ResourceObject;
9
use Override;
10
use Ray\Aop\MethodInterceptor;
11
use Ray\Aop\MethodInvocation;
12
13
use function assert;
14
15
final class HttpCacheInterceptor implements MethodInterceptor
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    #[Override]
21
    public function invoke(MethodInvocation $invocation)
22
    {
23
        $cacheControl = $invocation->getMethod()->getDeclaringClass()->getAnnotation(AbstractCacheControl::class);
24
        $ro = $invocation->proceed();
25
        assert($ro instanceof ResourceObject);
26
        if ($ro->code === 200 && $cacheControl instanceof AbstractCacheControl) {
27
            $ro->headers[Header::CACHE_CONTROL] = (string) $cacheControl;
28
        }
29
30
        return $ro;
31
    }
32
}
33