Psr7::check()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Uploader\Adapters;
4
5
use Uploader\Uploader;
6
use Psr\Http\Message\UploadedFileInterface;
7
8
/**
9
 * Adapter to save a file from Psr7's UploadedFileInterface.
10
 */
11
class Psr7 implements AdapterInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public static function check($original)
17
    {
18
        return ($original instanceof UploadedFileInterface);
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 View Code Duplication
    public static function fixDestination(Uploader $uploader, $original)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $path = Uploader::parsePath($original->getClientFilename());
27
28
        if (!$uploader->getFilename()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $uploader->getFilename() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
29
            $uploader->setFilename($path['filename']);
30
        }
31
32
        if (!$uploader->getExtension()) {
33
            $uploader->setExtension($path['extension']);
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function save($original, $destination)
41
    {
42
        $original->moveTo($destination);
43
    }
44
}
45