1 | <?php |
||
41 | class Configuration implements ConfigurationInterface |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * The operation name to use. |
||
46 | * |
||
47 | * @var string |
||
48 | * @Type("string") |
||
49 | * @SerializedName("operation-name") |
||
50 | */ |
||
51 | protected $operationName; |
||
52 | |||
53 | /** |
||
54 | * The Magento edition, EE or CE. |
||
55 | * |
||
56 | * @var string |
||
57 | * @Type("string") |
||
58 | * @SerializedName("magento-edition") |
||
59 | */ |
||
60 | protected $magentoEdition = 'CE'; |
||
61 | |||
62 | /** |
||
63 | * The Magento version, e. g. 2.1.0. |
||
64 | * |
||
65 | * @var string |
||
66 | * @Type("string") |
||
67 | * @SerializedName("magento-version") |
||
68 | */ |
||
69 | protected $magentoVersion = '2.1.2'; |
||
70 | |||
71 | /** |
||
72 | * The Magento installation directory. |
||
73 | * |
||
74 | * @var string |
||
75 | * @Type("string") |
||
76 | * @SerializedName("installation-dir") |
||
77 | */ |
||
78 | protected $installationDir; |
||
79 | |||
80 | /** |
||
81 | * The database configuration. |
||
82 | * |
||
83 | * @var TechDivision\Import\Configuration\Database |
||
84 | * @Type("TechDivision\Import\Cli\Configuration\Database") |
||
85 | */ |
||
86 | protected $database; |
||
87 | |||
88 | /** |
||
89 | * ArrayCollection with the information of the configured operations. |
||
90 | * |
||
91 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
92 | * @Type("ArrayCollection<TechDivision\Import\Cli\Configuration\Operation>") |
||
93 | */ |
||
94 | protected $operations; |
||
95 | |||
96 | /** |
||
97 | * The subject's utility class with the SQL statements to use. |
||
98 | * |
||
99 | * @var string |
||
100 | * @Type("string") |
||
101 | * @SerializedName("utility-class-name") |
||
102 | */ |
||
103 | protected $utilityClassName; |
||
104 | |||
105 | /** |
||
106 | * Factory implementation to create a new initialized configuration instance. |
||
107 | * |
||
108 | * If command line options are specified, they will always override the |
||
109 | * values found in the configuration file. |
||
110 | * |
||
111 | * @param \Symfony\Component\Console\Input\InputInterface $input The Symfony console input instance |
||
112 | * |
||
113 | * @return \TechDivision\Import\Cli\Configuration The configuration instance |
||
114 | * @throws \Exception Is thrown, if the specified configuration file doesn't exist |
||
115 | */ |
||
116 | public static function factory(InputInterface $input) |
||
193 | |||
194 | /** |
||
195 | * Return's the database configuration. |
||
196 | * |
||
197 | * @return \TechDivision\Import\Cli\Configuration\Database The database configuration |
||
198 | */ |
||
199 | public function getDatabase() |
||
203 | |||
204 | /** |
||
205 | * Return's the ArrayCollection with the configured operations. |
||
206 | * |
||
207 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations |
||
208 | */ |
||
209 | public function getOperations() |
||
213 | |||
214 | /** |
||
215 | * Return's the array with the subjects of the operation to use. |
||
216 | * |
||
217 | * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the subjects |
||
218 | * @throws \Exception Is thrown, if no subjects are available for the actual operation |
||
219 | */ |
||
220 | public function getSubjects() |
||
234 | |||
235 | /** |
||
236 | * Return's the operation, initialize from the actual operation name. |
||
237 | * |
||
238 | * @return \TechDivision\Import\Configuration\OperationInterface The operation instance |
||
239 | */ |
||
240 | protected function getOperation() |
||
244 | |||
245 | /** |
||
246 | * Return's the operation name that has to be used. |
||
247 | * |
||
248 | * @param string $operationName The operation name that has to be used |
||
249 | * |
||
250 | * @return void |
||
251 | */ |
||
252 | public function setOperationName($operationName) |
||
256 | |||
257 | /** |
||
258 | * Return's the operation name that has to be used. |
||
259 | * |
||
260 | * @return string The operation name that has to be used |
||
261 | */ |
||
262 | public function getOperationName() |
||
266 | |||
267 | /** |
||
268 | * Set's the Magento installation directory. |
||
269 | * |
||
270 | * @param string $installationDir The Magento installation directory |
||
271 | * |
||
272 | * @return void |
||
273 | */ |
||
274 | public function setInstallationDir($installationDir) |
||
278 | |||
279 | /** |
||
280 | * Return's the Magento installation directory. |
||
281 | * |
||
282 | * @return string The Magento installation directory |
||
283 | */ |
||
284 | public function getInstallationDir() |
||
288 | |||
289 | /** |
||
290 | * Return's the utility class with the SQL statements to use. |
||
291 | * |
||
292 | * @param string $utilityClassName The utility class name |
||
293 | * |
||
294 | * @return void |
||
295 | */ |
||
296 | public function setUtilityClassName($utilityClassName) |
||
300 | |||
301 | /** |
||
302 | * Return's the utility class with the SQL statements to use. |
||
303 | * |
||
304 | * @return string The utility class name |
||
305 | */ |
||
306 | public function getUtilityClassName() |
||
310 | |||
311 | /** |
||
312 | * Set's the Magento edition, EE or CE. |
||
313 | * |
||
314 | * @param string $magentoEdition The Magento edition |
||
315 | * |
||
316 | * @return void |
||
317 | */ |
||
318 | public function setMagentoEdition($magentoEdition) |
||
322 | |||
323 | /** |
||
324 | * Return's the Magento edition, EE or CE. |
||
325 | * |
||
326 | * @return string The Magento edition |
||
327 | */ |
||
328 | public function getMagentoEdition() |
||
332 | |||
333 | /** |
||
334 | * Return's the Magento version, e. g. 2.1.0. |
||
335 | * |
||
336 | * @param string $magentoVersion The Magento version |
||
337 | * |
||
338 | * @return void |
||
339 | */ |
||
340 | public function setMagentoVersion($magentoVersion) |
||
344 | |||
345 | /** |
||
346 | * Return's the Magento version, e. g. 2.1.0. |
||
347 | * |
||
348 | * @return string The Magento version |
||
349 | */ |
||
350 | public function getMagentoVersion() |
||
354 | } |
||
355 |
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.