SignedUrlBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Media\Glide;
6
7
use Damax\Media\Domain\Image\UrlBuilder;
8
use Damax\Media\Domain\Model\MediaId;
9
use League\Glide\Signatures\SignatureInterface;
10
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
11
12
final class SignedUrlBuilder implements UrlBuilder
13
{
14
    private $urlGenerator;
15
    private $signature;
16
    private $routeName;
17
18
    public function __construct(UrlGeneratorInterface $urlGenerator, SignatureInterface $signature, string $routeName = 'media_image')
19
    {
20
        $this->urlGenerator = $urlGenerator;
21
        $this->signature = $signature;
22
        $this->routeName = $routeName;
23
    }
24
25
    public function build(MediaId $mediaId, array $params): string
26
    {
27
        $id = ['id' => (string) $mediaId];
28
29
        $url = $this->urlGenerator->generate($this->routeName, $id);
30
31
        $params = $this->signature->addSignature($url, $params);
32
33
        return $this->urlGenerator->generate($this->routeName, $params + $id);
34
    }
35
}
36