Psr7   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 35.29 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 34
wmc 5
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 4 1
A save() 0 4 1
A fixDestination() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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