RemoveHandler::remove()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
3
namespace yiicod\fileupload\components;
4
5
use Exception;
6
use yiicod\fileupload\components\base\AccessRemoveInterface;
7
use yiicod\fileupload\components\base\UploaderInterface;
8
9
/**
10
 * Class UploadHandler
11
 *
12
 * @package yiicod\fileupload\libs
13
 */
14
class RemoveHandler
15
{
16
    /**
17
     * Remove file
18
     *
19
     * @param string $uploader
20
     * @param array $userData
21
     *
22
     * @return array
23
     *
24
     * @throws Exception
25
     */
26
    public function remove(string $uploader, array $userData)
27
    {
28
        /** @var UploaderInterface $uploader */
29
        $uploader = new $uploader();
30
        if (false === is_a($uploader, UploaderInterface::class)) {
31
            throw new Exception('Uploader class must be instanceof UploaderInterface', 500);
32
        }
33
        if (is_a($uploader, AccessRemoveInterface::class)) {
34
            /** @var UploaderInterface|AccessRemoveInterface $uploader */
35
            if ($uploader->canRemove($userData)) {
0 ignored issues
show
Bug introduced by
The method canRemove does only exist in yiicod\fileupload\compon...e\AccessRemoveInterface, but not in yiicod\fileupload\compon...\base\UploaderInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
                return $uploader->remove($userData);
0 ignored issues
show
Bug introduced by
The method remove does only exist in yiicod\fileupload\compon...\base\UploaderInterface, but not in yiicod\fileupload\compon...e\AccessRemoveInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
37
            } else {
38
                return $uploader->deniedRemove($userData);
0 ignored issues
show
Bug introduced by
The method deniedRemove does only exist in yiicod\fileupload\compon...e\AccessRemoveInterface, but not in yiicod\fileupload\compon...\base\UploaderInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
39
            }
40
        } else {
41
            return $uploader->remove($userData);
42
        }
43
    }
44
}
45