CacheResolveEvent   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 95
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setPath() 0 4 1
A getPath() 0 4 1
A setFilter() 0 4 1
A getFilter() 0 4 1
A setUrl() 0 4 1
A getUrl() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Events;
13
14
use Symfony\Component\EventDispatcher\Event;
15
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
17
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
18
19
if (is_subclass_of(EventDispatcherInterface::class, ContractsEventDispatcherInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Symfony\Contracts\Event...patcherInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
20
    abstract class BCEvent extends ContractsEvent
21
    {
22
    }
23
} else {
24
    abstract class BCEvent extends Event
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Liip\ImagineBundle\Events\BCEvent has been defined more than once; this definition is ignored, only the first definition in this file (L20-22) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
25
    {
26
    }
27
}
28
29
class CacheResolveEvent extends BCEvent
30
{
31
    /**
32
     * Resource path.
33
     *
34
     * @var string
35
     */
36
    protected $path;
37
38
    /**
39
     * Filter name.
40
     *
41
     * @var string
42
     */
43
    protected $filter;
44
45
    /**
46
     * Resource url.
47
     *
48
     * @var null
49
     */
50
    protected $url;
51
52
    /**
53
     * Init default event state.
54
     *
55
     * @param string      $path
56
     * @param string      $filter
57
     * @param string|null $url
58
     */
59
    public function __construct($path, $filter, $url = null)
60
    {
61
        $this->path = $path;
62
        $this->filter = $filter;
63
        $this->url = $url;
0 ignored issues
show
Documentation Bug introduced by
It seems like $url can also be of type string. However, the property $url is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
64
    }
65
66
    /**
67
     * Sets resource path.
68
     *
69
     * @param $path
70
     */
71
    public function setPath($path)
72
    {
73
        $this->path = $path;
74
    }
75
76
    /**
77
     * Returns resource path.
78
     *
79
     * @return string
80
     */
81
    public function getPath()
82
    {
83
        return $this->path;
84
    }
85
86
    /**
87
     * Sets filter name.
88
     *
89
     * @param $filter
90
     */
91
    public function setFilter($filter)
92
    {
93
        $this->filter = $filter;
94
    }
95
96
    /**
97
     * Returns filter name.
98
     *
99
     * @return string
100
     */
101
    public function getFilter()
102
    {
103
        return $this->filter;
104
    }
105
106
    /**
107
     * Sets resource url.
108
     *
109
     * @param $url
110
     */
111
    public function setUrl($url)
112
    {
113
        $this->url = $url;
114
    }
115
116
    /**
117
     * Returns resource url.
118
     */
119
    public function getUrl()
120
    {
121
        return $this->url;
122
    }
123
}
124