VichUploadPropertyNamer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
c 3
b 0
f 0
dl 0
loc 23
ccs 0
cts 14
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtension() 0 13 3
A name() 0 3 1
1
<?php
2
3
namespace PiedWeb\CMSBundle\Service;
4
5
use Symfony\Component\HttpFoundation\File\UploadedFile;
6
use Vich\UploaderBundle\Mapping\PropertyMapping;
7
8
//implements NamerInterface, ConfigurableInterface
9
class VichUploadPropertyNamer extends \Vich\UploaderBundle\Naming\PropertyNamer
10
{
11
    /**
12
     * Guess the extension of the given file.
13
     */
14
    private function getExtension(UploadedFile $file): ?string
15
    {
16
        $originalName = $file->getClientOriginalName();
17
18
        if ($extension = pathinfo($originalName, PATHINFO_EXTENSION)) {
19
            return strtolower($extension);
20
        }
21
22
        if ($extension = $file->guessExtension()) {
23
            return strtolower($extension);
24
        }
25
26
        return null;
27
    }
28
29
    public function name($object, PropertyMapping $mapping): string
30
    {
31
        return strtolower(parent::name($object, $mapping));
32
    }
33
}
34