1 | <?php |
||
24 | class MakiMarker extends Plugin |
||
25 | { |
||
26 | /** |
||
27 | * @var string the maki icon name |
||
28 | * @see https://www.mapbox.com/maki/ |
||
29 | */ |
||
30 | public $icon; |
||
31 | |||
32 | /** |
||
33 | * Generates the code to generate a maki marker. Helper method made for speed purposes. |
||
34 | * |
||
35 | * @param string $icon the icon name |
||
36 | * @param array $options the maki marker icon |
||
37 | * |
||
38 | * @return string the resulting js code |
||
39 | */ |
||
40 | 3 | public function make($icon, $options = []) |
|
46 | |||
47 | /** |
||
48 | * Returns the plugin name |
||
49 | * @return string |
||
50 | */ |
||
51 | 3 | public function getPluginName() |
|
55 | |||
56 | /** |
||
57 | * Registers plugin asset bundle |
||
58 | * |
||
59 | * @param \yii\web\View $view |
||
60 | * |
||
61 | * @return mixed |
||
62 | * @codeCoverageIgnore |
||
63 | */ |
||
64 | public function registerAssetBundle($view) |
||
69 | |||
70 | /** |
||
71 | * Returns the javascript ready code for the object to render |
||
72 | * @return \yii\web\JsExpression |
||
73 | */ |
||
74 | 3 | public function encode() |
|
93 | |||
94 | } |
||
95 |
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.