These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Modules\Tag\Providers; |
||
4 | |||
5 | use Modules\Core\Providers\RoutingServiceProvider as CoreRoutingServiceProvider; |
||
6 | |||
7 | class RouteServiceProvider extends CoreRoutingServiceProvider |
||
8 | { |
||
9 | /** |
||
10 | * The root namespace to assume when generating URLs to actions. |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $namespace = 'Modules\Tag\Http\Controllers'; |
||
14 | |||
15 | /** |
||
16 | * @return string |
||
17 | */ |
||
18 | protected function getFrontendRoute() |
||
19 | { |
||
20 | return false; |
||
0 ignored issues
–
show
|
|||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @return string |
||
25 | */ |
||
26 | protected function getBackendRoute() |
||
27 | { |
||
28 | return __DIR__ . '/../Http/backendRoutes.php'; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | protected function getApiRoute() |
||
35 | { |
||
36 | return false; |
||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type declared by the abstract method Modules\Core\Providers\R...ceProvider::getApiRoute of type string .
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
Loading history...
|
|||
37 | } |
||
38 | } |
||
39 |
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.