Completed
Push — 2.1 ( 0d6728...0539a2 )
by Rafał
09:25
created

LocalAssetUrlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateUrl() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2020 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2020 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Asset;
18
19
use SWP\Bundle\ContentBundle\Model\FileInterface;
20
21
final class LocalAssetUrlGenerator implements AssetUrlGeneratorInterface
22
{
23
    private $localDirectory;
24
25
    public function __construct(string $localDirectory = null)
26
    {
27
        $this->localDirectory = $localDirectory;
28
    }
29
30
    public function generateUrl(FileInterface $file, string $basePath): string
31
    {
32
        return ($this->localDirectory ? $this->localDirectory.DIRECTORY_SEPARATOR : null).
33
            $basePath.
34
            DIRECTORY_SEPARATOR.
35
            $file->getAssetId().
36
            '.'.
37
            $file->getFileExtension()
38
        ;
39
    }
40
}
41