1 | <?php |
||
10 | class LocalEnvironment extends Environment implements CloudEnvironmentInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $creds = array(); |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $sitegroup; |
||
21 | |||
22 | /** |
||
23 | * @param string $sitegroup |
||
24 | */ |
||
25 | 18 | public function __construct($sitegroup) |
|
30 | |||
31 | /** |
||
32 | * Calculates and returns the environment. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | 18 | protected function init() |
|
40 | |||
41 | /** |
||
42 | * {@inheritDoc} |
||
43 | */ |
||
44 | 3 | public function isAcquia() |
|
48 | |||
49 | /** |
||
50 | * {@inheritDoc} |
||
51 | */ |
||
52 | 3 | public function setSiteGroup($sitegroup) |
|
57 | |||
58 | /** |
||
59 | * {@inheritDoc} |
||
60 | */ |
||
61 | 6 | public function getSiteGroup() |
|
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | 6 | public function serviceCredentials() |
|
73 | |||
74 | /** |
||
75 | * Adds credentials to a database server. |
||
76 | * |
||
77 | * @param string $acquiaDbName |
||
78 | * @param string $localDbName |
||
79 | * @param string $username |
||
80 | * @param string|null $password |
||
81 | * @param string $host |
||
82 | * @param integer $port |
||
83 | * |
||
84 | * @return \Acquia\Cloud\Environment\LocalEnvironment |
||
85 | */ |
||
86 | 3 | public function addDatabaseCredentials($acquiaDbName, $localDbName, $username, $password = null, $host = 'localhost', $port = 3306) |
|
108 | |||
109 | /** |
||
110 | * Adds credentials to a Memcached server. |
||
111 | * |
||
112 | * @param string $host |
||
113 | * @param string $port |
||
114 | * |
||
115 | * @return \Acquia\Cloud\Environment\LocalEnvironment |
||
116 | */ |
||
117 | 3 | public function addMemcacheCredentials($host, $port) |
|
122 | } |
||
123 |
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.