1 | <?php |
||
2 | |||
3 | namespace Fwolf\Config; |
||
4 | |||
5 | /** |
||
6 | * Trait for Config aware class also accept StringOptions |
||
7 | * |
||
8 | * @copyright Copyright 2015-2017 Fwolf |
||
9 | * @license https://opensource.org/licenses/MIT MIT |
||
10 | */ |
||
11 | trait StringOptionsAwareTrait |
||
12 | { |
||
13 | use ConfigAwareTrait; |
||
14 | |||
15 | |||
16 | /** |
||
17 | * @return StringOptions |
||
18 | */ |
||
19 | View Code Duplication | protected function getConfigInstance() |
|
0 ignored issues
–
show
|
|||
20 | { |
||
21 | if (is_null($this->configInstance)) { |
||
22 | $config = new StringOptions(); |
||
23 | |||
24 | $config->setMultiple($this->getDefaultConfigs()); |
||
25 | |||
26 | $this->configInstance = $config; |
||
27 | } |
||
28 | |||
29 | return $this->configInstance; |
||
30 | } |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Set options/config with string |
||
35 | * |
||
36 | * @param string $optionString |
||
37 | * @return $this |
||
38 | */ |
||
39 | public function setStringOptions($optionString) |
||
40 | { |
||
41 | $config = $this->getConfigInstance(); |
||
42 | |||
43 | $config->setStringOptions($optionString); |
||
44 | |||
45 | return $this; |
||
46 | } |
||
47 | } |
||
48 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.