VichUploadPropertyNamer::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
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