| 1 | <?php |
||
| 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) { |
||
| 80 | |||
| 81 | /** |
||
| 82 | * {@inheritdoc} |
||
| 83 | */ |
||
| 84 | public function getAnimated() { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function getContent() { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function getMax() { |
||
| 101 | |||
| 102 | /** |
||
| 103 | * {@inheritdoc} |
||
| 104 | */ |
||
| 105 | public function getMin() { |
||
| 108 | |||
| 109 | /** |
||
| 110 | * {@inheritdoc} |
||
| 111 | */ |
||
| 112 | public function getStriped() { |
||
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritdoc} |
||
| 118 | */ |
||
| 119 | public function getType() { |
||
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | public function getValue() { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * {@inheritdoc} |
||
| 132 | */ |
||
| 133 | public function setAnimated($animated) { |
||
| 137 | |||
| 138 | /** |
||
| 139 | * {@inheritdoc} |
||
| 140 | */ |
||
| 141 | public function setContent($content) { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * {@inheritdoc} |
||
| 148 | */ |
||
| 149 | public function setMax($max) { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * {@inheritdoc} |
||
| 156 | */ |
||
| 157 | public function setMin($min) { |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function setStriped($striped) { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function setType($type) { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * {@inheritdoc} |
||
| 180 | */ |
||
| 181 | public function setValue($value) { |
||
| 185 | } |
||
| 186 |
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_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.