Passed
Pull Request — 1.x (#99)
by Akihito
10:41
created

FastlyCacheControlHeaderSetter::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository\Cdn;
6
7
use BEAR\QueryRepository\CdnCacheControlHeaderSetterInterface;
8
use BEAR\Resource\ResourceObject;
9
10
use function sprintf;
11
12
final class FastlyCacheControlHeaderSetter implements CdnCacheControlHeaderSetterInterface
13
{
14
    public const CDN_CACHE_CONTROL_HEADER = 'Surrogate-Control';
15
16
    public function __invoke(ResourceObject $ro, ?int $sMaxAge): void
17
    {
18
        $sMaxAge = $sMaxAge ?? 31536000;
19
        if (! isset($ro->headers[self::CDN_CACHE_CONTROL_HEADER])) {
20
            $ro->headers[self::CDN_CACHE_CONTROL_HEADER] = sprintf('max-age=%s', (string) $sMaxAge);
21
        }
22
    }
23
}
24