ContentImageNamer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 27
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A name() 0 11 2
1
<?php
2
3
namespace Smart\ContentBundle\Upload;
4
5
use Vich\UploaderBundle\Mapping\PropertyMapping;
6
use Vich\UploaderBundle\Naming\NamerInterface;
7
use Vich\UploaderBundle\Util\Transliterator;
8
9
/**
10
 * Nicolas Bastien <[email protected]>
11
 */
12
class ContentImageNamer implements NamerInterface
13
{
14
    /**
15
     * @var Transliterator
16
     */
17
    protected $transliterator;
18
19
    public function __construct(Transliterator $transliterator)
20
    {
21
        $this->transliterator = $transliterator;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function name($object, PropertyMapping $mapping): string
28
    {
29
        $file = $mapping->getFile($object);
30
        $name = $this->transliterator->transliterate((string) $object);
31
32
        if ($extension = $file->guessExtension()) {
33
            $name = sprintf('%s_%s.%s', $name, date('YmdHis'), $extension);
34
        }
35
36
        return $name;
37
    }
38
}
39