ContentImageDirectoryNamer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A directoryName() 0 7 1
1
<?php
2
3
namespace Smart\ContentBundle\Upload;
4
5
use Vich\UploaderBundle\Mapping\PropertyMapping;
6
use Vich\UploaderBundle\Naming\DirectoryNamerInterface;
7
use Vich\UploaderBundle\Util\Transliterator;
8
9
/**
10
 * https://www.prestaconcept.net/blog/symfony/vichuploaderbundle-dry-configuration
11
 */
12
class ContentImageDirectoryNamer implements DirectoryNamerInterface
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
     * Get short class name of given object :
26
     *  - AppBundle\Entity\Product : product
27
     *  - AppBundle\Entity\User : user
28
     *
29
     * @param object $object
30
     * @param PropertyMapping $mapping
31
     * @return string
32
     */
33
    public function directoryName($object, PropertyMapping $mapping): string
34
    {
35
        $fqcn = get_class($object);
36
        $classParts = explode('\\', $fqcn);
37
38
        return $this->transliterator->transliterate(array_pop($classParts));
39
    }
40
}
41