|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hidev |
|
7
|
|
|
* @package hidev |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\controllers; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Controller for VCS ignore files generation. |
|
16
|
|
|
*/ |
|
17
|
|
|
class VcsignoreController extends FileController |
|
18
|
|
|
{ |
|
19
|
|
|
protected $_items = [ |
|
20
|
|
|
'.hidev/composer.json' => 'hidev internals', |
|
21
|
|
|
'.hidev/composer.lock' => 'hidev internals', |
|
22
|
|
|
'.hidev/vendor' => 'hidev internals', |
|
23
|
|
|
'.*.swp' => 'IDE & OS files', |
|
24
|
|
|
'.idea' => 'IDE & OS files', |
|
25
|
|
|
'nbproject' => 'IDE & OS files', |
|
26
|
|
|
'.buildpath' => 'IDE & OS files', |
|
27
|
|
|
'.project' => 'IDE & OS files', |
|
28
|
|
|
'.settings' => 'IDE & OS files', |
|
29
|
|
|
'Thumbs.db' => 'IDE & OS files', |
|
30
|
|
|
'.DS_Store' => 'IDE & OS files', |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
public function actionLoad() |
|
34
|
|
|
{ |
|
35
|
|
|
$items = $this->getFile()->load() ?: []; |
|
36
|
|
|
if ($items) { |
|
37
|
|
|
$this->takeVcs()->setIgnore($items); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function actionSave() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->getFile()->save($this->takeVcs()->getIgnore()); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
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.