Passed
Push — master ( 59b22d...01829a )
by Dev
03:47
created

VichUploadPropertyNamer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtension() 0 14 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
class VichUploadPropertyNamer extends \Vich\UploaderBundle\Naming\PropertyNamer //implements NamerInterface, ConfigurableInterface
9
{
10
    /**
11
     * Guess the extension of the given file.
12
     *
13
     * @param UploadedFile $file
14
     *
15
     * @return string|null
16
     */
17
    private function getExtension(UploadedFile $file): ?string
1 ignored issue
show
Unused Code introduced by
The method getExtension() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
Unused Code introduced by
The parameter $file is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

17
    private function getExtension(/** @scrutinizer ignore-unused */ UploadedFile $file): ?string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        var_dump('hello'); exit;
0 ignored issues
show
Security Debugging Code introduced by
var_dump('hello') looks like debug code. Are you sure you do not want to remove it?
Loading history...
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
20
        $originalName = $file->getClientOriginalName();
0 ignored issues
show
Unused Code introduced by
$originalName = $file->getClientOriginalName() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
21
22
        if ($extension = pathinfo($originalName, PATHINFO_EXTENSION)) {
23
            return strtolower($extension);
24
        }
25
26
        if ($extension = $file->guessExtension()) {
27
            return strtolower($extension);
28
        }
29
30
        return null;
31
    }
32
33
    public function name($object, PropertyMapping $mapping): string
34
    {
35
        return strtolower(parent::name($object, $mapping));
36
    }
37
}
38