Completed
Push — develop ( f96c6e...0a0831 )
by Daniel
06:36
created

ListRouteBuilder   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 193
Duplicated Lines 16.58 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 1
dl 32
loc 193
rs 9.84
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setResourceKey() 0 6 1
A setListkey() 0 6 1
A setTitle() 0 6 1
A setTabTitle() 0 6 1
A setTabOrder() 0 6 1
A setTabCondition() 0 6 1
A addListAdapters() 8 8 2
A addLocales() 8 8 2
A setDefaultLocale() 0 6 1
A addToolbarActions() 8 8 2
A setAddRoute() 0 6 1
A setEditRoute() 0 6 1
A setBackRoute() 0 6 1
A enableSearching() 0 6 1
A disableSearching() 0 6 1
A enableMoving() 0 6 1
A disableMoving() 0 6 1
A addRouterAttributesToListStore() 8 8 2
A setParent() 0 6 1
B getRoute() 0 37 8

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
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\AdminBundle\Admin\Routing;
13
14
class ListRouteBuilder implements ListRouteBuilderInterface
15
{
16
    const VIEW = 'sulu_admin.list';
17
18
    /**
19
     * @var Route
20
     */
21
    private $route;
22
23
    public function __construct(string $name, string $path)
24
    {
25
        $this->route = new Route($name, $path, static::VIEW);
26
    }
27
28
    public function setResourceKey(string $resourceKey): ListRouteBuilderInterface
29
    {
30
        $this->route->setOption('resourceKey', $resourceKey);
31
32
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...terface::setResourceKey of type self.

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...
33
    }
34
35
    public function setListkey(string $listKey): ListRouteBuilderInterface
36
    {
37
        $this->route->setOption('listKey', $listKey);
38
39
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erInterface::setListKey of type self.

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...
40
    }
41
42
    public function setTitle(string $title): ListRouteBuilderInterface
43
    {
44
        $this->route->setOption('title', $title);
45
46
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...lderInterface::setTitle of type self.

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...
47
    }
48
49
    public function setTabTitle(string $tabTitle): ListRouteBuilderInterface
50
    {
51
        $this->route->setOption('tabTitle', $tabTitle);
52
53
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...rInterface::setTabTitle of type self.

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...
54
    }
55
56
    public function setTabOrder(int $tabOrder): ListRouteBuilderInterface
57
    {
58
        $this->route->setOption('tabOrder', $tabOrder);
59
60
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...rInterface::setTabOrder of type self.

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...
61
    }
62
63
    public function setTabCondition(string $tabCondition): ListRouteBuilderInterface
64
    {
65
        $this->route->setOption('tabCondition', $tabCondition);
66
67
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erface::setTabCondition of type self.

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...
68
    }
69
70 View Code Duplication
    public function addListAdapters(array $listAdapters): ListRouteBuilderInterface
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...
71
    {
72
        $oldListAdapters = $this->route->getOption('adapters');
73
        $newListAdapters = $oldListAdapters ? array_merge($oldListAdapters, $listAdapters) : $listAdapters;
74
        $this->route->setOption('adapters', $newListAdapters);
75
76
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erface::addListAdapters of type self.

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...
77
    }
78
79 View Code Duplication
    public function addLocales(array $locales): ListRouteBuilderInterface
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...
80
    {
81
        $oldLocales = $this->route->getOption('locales');
82
        $newLocales = $oldLocales ? array_merge($oldLocales, $locales) : $locales;
83
        $this->route->setOption('locales', $newLocales);
84
85
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erInterface::addLocales of type self.

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...
86
    }
87
88
    public function setDefaultLocale(string $locale): ListRouteBuilderInterface
89
    {
90
        $this->route->setAttributeDefault('locale', $locale);
91
92
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...rface::setDefaultLocale of type self.

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...
93
    }
94
95 View Code Duplication
    public function addToolbarActions(array $toolbarActions): ListRouteBuilderInterface
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...
96
    {
97
        $oldToolbarActions = $this->route->getOption('toolbarActions');
98
        $newToolbarActions = $oldToolbarActions ? array_merge($oldToolbarActions, $toolbarActions) : $toolbarActions;
99
        $this->route->setOption('toolbarActions', $newToolbarActions);
100
101
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...face::addToolbarActions of type self.

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...
102
    }
103
104
    public function setAddRoute(string $addRoute): ListRouteBuilderInterface
105
    {
106
        $this->route->setOption('addRoute', $addRoute);
107
108
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...rInterface::setAddRoute of type self.

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...
109
    }
110
111
    public function setEditRoute(string $editRoute): ListRouteBuilderInterface
112
    {
113
        $this->route->setOption('editRoute', $editRoute);
114
115
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...Interface::setEditRoute of type self.

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...
116
    }
117
118
    public function setBackRoute(string $backRoute): ListRouteBuilderInterface
119
    {
120
        $this->route->setOption('backRoute', $backRoute);
121
122
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...Interface::setBackRoute of type self.

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...
123
    }
124
125
    public function enableSearching(): ListRouteBuilderInterface
126
    {
127
        $this->route->setOption('searchable', true);
128
129
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erface::enableSearching of type self.

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...
130
    }
131
132
    public function disableSearching(): ListRouteBuilderInterface
133
    {
134
        $this->route->setOption('searchable', false);
135
136
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...rface::disableSearching of type self.

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...
137
    }
138
139
    public function enableMoving(): ListRouteBuilderInterface
140
    {
141
        $this->route->setOption('movable', true);
142
143
        return $this;
144
    }
145
146
    public function disableMoving(): ListRouteBuilderInterface
147
    {
148
        $this->route->setOption('movable', false);
149
150
        return $this;
151
    }
152
153 View Code Duplication
    public function addRouterAttributesToListStore(array $routerAttributesToListStore): ListRouteBuilderInterface
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...
154
    {
155
        $oldRouterAttributesToListStore = $this->route->getOption('routerAttributesToListStore');
156
        $newRouterAttributesToListStore = $oldRouterAttributesToListStore ? array_merge($oldRouterAttributesToListStore, $routerAttributesToListStore) : $routerAttributesToListStore;
157
        $this->route->setOption('routerAttributesToListStore', $newRouterAttributesToListStore);
158
159
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...erAttributesToListStore of type self.

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...
160
    }
161
162
    public function setParent(string $parent): ListRouteBuilderInterface
163
    {
164
        $this->route->setParent($parent);
165
166
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Sulu\Bundle\AdminBundle\...outing\ListRouteBuilder) is incompatible with the return type declared by the interface Sulu\Bundle\AdminBundle\...derInterface::setParent of type self.

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...
167
    }
168
169
    public function getRoute(): Route
170
    {
171
        if (!$this->route->getOption('resourceKey')) {
172
            throw new \DomainException(
173
                'A route for a list view needs a "resourceKey" option.'
174
                . ' You have likely forgotten to call the "setResourceKey" method.'
175
            );
176
        }
177
178
        if (!$this->route->getOption('listKey')) {
179
            throw new \DomainException(
180
                'A route for a list view needs a "listKey" option.'
181
                . ' You have likely forgotten to call the "setListKey" method.'
182
            );
183
        }
184
185
        if (!$this->route->getOption('adapters')) {
186
            throw new \DomainException(
187
                'A route for a list needs a "adapters" option.'
188
                . ' You have likely forgotten to call the "addListAdapters" method.'
189
            );
190
        }
191
192
        if ($this->route->getOption('locales') && false === strpos($this->route->getPath(), ':locale')) {
193
            throw new \DomainException(
194
                'A route for a list needs a ":locale" placeholder in its URL if some "locales" have been set.'
195
            );
196
        }
197
198
        if (!$this->route->getOption('locales') && false !== strpos($this->route->getPath(), ':locale')) {
199
            throw new \DomainException(
200
                'A route for a list cannot have a ":locale" placeholder in its URL if no "locales" have been set.'
201
            );
202
        }
203
204
        return clone $this->route;
205
    }
206
}
207