Completed
Push — master ( b13563...fa826f )
by WEBEWEB
02:11
created

AbstractProgressBar::getAnimated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
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 WBW\Bundle\BootstrapBundle\ProgressBar;
13
14
/**
15
 * Abstract progress bar.
16
 *
17
 * @author webeweb <https://github.com/webeweb/>
18
 * @package WBW\Bundle\BootstrapBundle\ProgressBar
19
 * @abstract
20
 */
21
abstract class AbstractProgressBar implements ProgressBarInterface {
22
23
    /**
24
     * Animated.
25
     *
26
     * @var bool
27
     */
28
    private $animated;
29
30
    /**
31
     * Content.
32
     *
33
     * @var string
34
     */
35
    private $content;
36
37
    /**
38
     * Max.
39
     *
40
     * @var int
41
     */
42
    private $max;
43
44
    /**
45
     * Min.
46
     *
47
     * @var int
48
     */
49
    private $min;
50
51
    /**
52
     * Striped.
53
     *
54
     * @var bool
55
     */
56
    private $striped;
57
58
    /**
59
     * Type.
60
     *
61
     * @var string
62
     */
63
    private $type;
64
65
    /**
66
     * Value.
67
     *
68
     * @var int
69
     */
70
    private $value;
71
72
    /**
73
     * Constructor.
74
     *
75
     * @param string $type The type.
76
     */
77
    public function __construct($type) {
78
        $this->setType($type);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function getAnimated() {
85
        return $this->animated;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function getContent() {
92
        return $this->content;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function getMax() {
99
        return $this->max;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getMin() {
106
        return $this->min;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function getStriped() {
113
        return $this->striped;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function getType() {
120
        return $this->type;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function getValue() {
127
        return $this->value;
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function setAnimated($animated) {
134
        $this->animated = $animated;
135
        return $this;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function setContent($content) {
142
        $this->content = $content;
143
        return $this;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function setMax($max) {
150
        $this->max = $max;
151
        return $this;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function setMin($min) {
158
        $this->min = $min;
159
        return $this;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function setStriped($striped) {
166
        $this->striped = $striped;
167
        return $this;
168
    }
169
170
    /**
171
     * {@inheritdoc}
172
     */
173
    public function setType($type) {
174
        $this->type = $type;
175
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (WBW\Bundle\BootstrapBund...Bar\AbstractProgressBar) is incompatible with the return type declared by the interface WBW\Bundle\BootstrapBund...ssBarInterface::setType of type WBW\Bundle\BootstrapBund...ressBar\ButtonInterface.

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...
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     */
181
    public function setValue($value) {
182
        $this->value = $value;
183
        return $this;
184
    }
185
}
186