GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RedirectRoute   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 166
c 0
b 0
f 0
ccs 0
cts 62
cp 0
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getContent() 0 4 1
A getRouteKey() 0 4 1
A setName() 0 6 1
A getName() 0 4 1
A setUri() 0 6 1
A getUri() 0 4 1
A setRouteTarget() 0 6 1
A getRouteTarget() 0 4 1
A setRouteName() 0 6 1
A getRouteName() 0 4 1
A getParameters() 0 4 1
A setParameters() 0 6 1
A setPermanent() 0 6 1
A isPermanent() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tadcka\Component\Routing\Model;
13
14
/**
15
 * @author Tadas Gliaubicas <[email protected]>
16
 *
17
 * @since 7/1/14 10:54 PM
18
 */
19
abstract class RedirectRoute implements RedirectRouteInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $name;
25
26
    /**
27
     * Absolute uri to redirect to.
28
     *
29
     * @var string
30
     */
31
    protected $uri;
32
33
    /**
34
     * The name of a target route (for use with standard symfony routes).
35
     *
36
     * @var string
37
     */
38
    protected $routeName;
39
40
    /**
41
     * Target route to redirect to different dynamic route.
42
     *
43
     * @var RouteInterface
44
     */
45
    protected $routeTarget;
46
47
    /**
48
     * Route parameters.
49
     *
50
     * @var array
51
     */
52
    protected $parameters = array();
53
54
    /**
55
     * Whether this is a permanent redirect. Defaults to true.
56
     *
57
     * @var bool
58
     */
59
    protected $permanent = true;
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getContent()
65
    {
66
        return $this;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getRouteKey()
73
    {
74
        return $this->getId();
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function setName($name)
81
    {
82
        $this->name = $name;
83
84
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Tadcka\Component\Routing\Model\RedirectRoute) is incompatible with the return type declared by the interface Tadcka\Component\Routing...RouteInterface::setName of type Tadcka\Component\Routing\Model\RouteInterface.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getName()
91
    {
92
        return $this->name;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function setUri($uri)
99
    {
100
        $this->uri = $uri;
101
102
        return $this;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getUri()
109
    {
110
        return $this->uri;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function setRouteTarget(RouteInterface $routeTarget = null)
117
    {
118
        $this->routeTarget = $routeTarget;
119
120
        return $this;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function getRouteTarget()
127
    {
128
        return $this->routeTarget;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function setRouteName($routeName)
135
    {
136
        $this->routeName = $routeName;
137
138
        return $this;
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function getRouteName()
145
    {
146
        return $this->routeName;
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function getParameters()
153
    {
154
        return $this->parameters;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function setParameters(array $parameters)
161
    {
162
        $this->parameters = $parameters;
163
164
        return $this;
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function setPermanent($permanent)
171
    {
172
        $this->permanent = $permanent;
173
174
        return $this;
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function isPermanent()
181
    {
182
        return $this->permanent;
183
    }
184
}
185