Complex classes like GeneratorOptions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GeneratorOptions, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class GeneratorOptions extends AbstractYamlReader implements \JsonSerializable |
||
6 | { |
||
7 | /** |
||
8 | * Common values used as option's value |
||
9 | */ |
||
10 | const VALUE_CAT = 'cat'; |
||
11 | const VALUE_END = 'end'; |
||
12 | const VALUE_FALSE = false; |
||
13 | const VALUE_NONE = 'none'; |
||
14 | const VALUE_START = 'start'; |
||
15 | const VALUE_TRUE = true; |
||
16 | /** |
||
17 | * Possible option keys |
||
18 | * @var string |
||
19 | */ |
||
20 | const ADD_COMMENTS = 'add_comments'; |
||
21 | const ARRAYS_FOLDER = 'arrays_folder'; |
||
22 | const BASIC_LOGIN = 'basic_login'; |
||
23 | const BASIC_PASSWORD = 'basic_password'; |
||
24 | const CATEGORY = 'category'; |
||
25 | const COMPOSER_NAME = 'composer_name'; |
||
26 | const COMPOSER_SETTINGS = 'composer_settings'; |
||
27 | const DESTINATION = 'destination'; |
||
28 | const ENUMS_FOLDER = 'enums_folder'; |
||
29 | const GATHER_METHODS = 'gather_methods'; |
||
30 | const GENERATE_TUTORIAL_FILE = 'generate_tutorial_file'; |
||
31 | const GENERIC_CONSTANTS_NAME = 'generic_constants_names'; |
||
32 | const NAMESPACE_PREFIX = 'namespace_prefix'; |
||
33 | const ORIGIN = 'origin'; |
||
34 | const PREFIX = 'prefix'; |
||
35 | const PROXY_HOST = 'proxy_host'; |
||
36 | const PROXY_LOGIN = 'proxy_login'; |
||
37 | const PROXY_PASSWORD = 'proxy_password'; |
||
38 | const PROXY_PORT = 'proxy_port'; |
||
39 | const SERVICES_FOLDER = 'services_folder'; |
||
40 | const SOAP_CLIENT_CLASS = 'soap_client_class'; |
||
41 | const SOAP_OPTIONS = 'soap_options'; |
||
42 | const SRC_DIRNAME = 'src_dirname'; |
||
43 | const STANDALONE = 'standalone'; |
||
44 | const STRUCT_ARRAY_CLASS = 'struct_array_class'; |
||
45 | const STRUCT_CLASS = 'struct_class'; |
||
46 | const STRUCTS_FOLDER = 'structs_folder'; |
||
47 | const SUFFIX = 'suffix'; |
||
48 | const VALIDATION = 'validation'; |
||
49 | const SCHEMAS_SAVE = 'schemas_save'; |
||
50 | const SCHEMAS_FOLDER = 'schemas_folder'; |
||
51 | /** |
||
52 | * Generator's options |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $options; |
||
56 | /** |
||
57 | 50 | * @param string $filename |
|
58 | */ |
||
59 | 50 | protected function __construct($filename) |
|
64 | /** |
||
65 | * Parse options for generator |
||
66 | * @param string $filename options's file to parse |
||
67 | 50 | * @return GeneratorOptions |
|
68 | */ |
||
69 | 50 | protected function parseOptions($filename) |
|
79 | /** |
||
80 | * Returns the option value |
||
81 | * @throws \InvalidArgumentException |
||
82 | * @param string $optionName |
||
83 | 1470 | * @return mixed |
|
84 | */ |
||
85 | 1470 | public function getOptionValue($optionName) |
|
92 | /** |
||
93 | * Allows to add an option and set its value |
||
94 | * @throws \InvalidArgumentException |
||
95 | * @param string $optionName |
||
96 | 1120 | * @param mixed $optionValue |
|
97 | * @param array $values |
||
98 | 1120 | * @return GeneratorOptions |
|
99 | 10 | */ |
|
100 | 10 | public function setOptionValue($optionName, $optionValue, array $values = []) |
|
101 | 10 | { |
|
102 | if (!isset($this->options[$optionName])) { |
||
103 | 1118 | $this->options[$optionName] = [ |
|
104 | 10 | 'value' => $optionValue, |
|
105 | 'values' => $values, |
||
106 | 1105 | ]; |
|
107 | } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) { |
||
108 | 1110 | throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__); |
|
109 | } else { |
||
110 | $this->options[$optionName]['value'] = $optionValue; |
||
111 | } |
||
112 | return $this; |
||
113 | } |
||
114 | /** |
||
115 | 1120 | * @throws \InvalidArgumentException |
|
116 | * @param string $filename options's file to parse |
||
117 | 1120 | * @return GeneratorOptions |
|
118 | */ |
||
119 | public static function instance($filename = null) |
||
120 | { |
||
121 | return parent::instance(empty($filename) ? self::getDefaultConfigurationPath() : $filename); |
||
122 | 455 | } |
|
123 | /** |
||
124 | 455 | * @return string |
|
125 | */ |
||
126 | public static function getDefaultConfigurationPath() |
||
127 | { |
||
128 | return __DIR__ . '/../resources/config/generator_options.yml'; |
||
129 | } |
||
130 | 405 | /** |
|
131 | * Get category option value |
||
132 | 405 | * @return string |
|
133 | */ |
||
134 | public function getCategory() |
||
135 | { |
||
136 | return $this->getOptionValue(self::CATEGORY); |
||
137 | } |
||
138 | /** |
||
139 | * Set current category option value |
||
140 | 45 | * @throws \InvalidArgumentException |
|
141 | * @param string $category |
||
142 | 45 | * @return GeneratorOptions |
|
143 | */ |
||
144 | public function setCategory($category) |
||
145 | { |
||
146 | return $this->setOptionValue(self::CATEGORY, $category); |
||
147 | } |
||
148 | 300 | /** |
|
149 | * Get add comments option value |
||
150 | 300 | * @return array |
|
151 | */ |
||
152 | public function getAddComments() |
||
153 | { |
||
154 | return $this->getOptionValue(self::ADD_COMMENTS); |
||
155 | } |
||
156 | /** |
||
157 | * Set current add comments option value |
||
158 | 95 | * @throws \InvalidArgumentException |
|
159 | * @param array $addComments |
||
160 | * @return GeneratorOptions |
||
161 | */ |
||
162 | public function setAddComments(array $addComments = []) |
||
163 | 95 | { |
|
164 | 95 | /** |
|
165 | 20 | * If array is type array("author:john Doe","Release:1",) |
|
166 | 5 | */ |
|
167 | 5 | $comments = []; |
|
168 | 3 | foreach ($addComments as $index => $value) { |
|
169 | 17 | if (is_numeric($index) && strpos($value, ':') > 0) { |
|
170 | list($tag, $val) = explode(':', $value); |
||
171 | 57 | $comments[$tag] = $val; |
|
172 | 95 | } else { |
|
173 | $comments[$index] = $value; |
||
174 | } |
||
175 | } |
||
176 | return $this->setOptionValue(self::ADD_COMMENTS, $comments); |
||
177 | } |
||
178 | 420 | /** |
|
179 | * Get gather methods option value |
||
180 | 420 | * @return string |
|
181 | */ |
||
182 | public function getGatherMethods() |
||
183 | { |
||
184 | return $this->getOptionValue(self::GATHER_METHODS); |
||
185 | } |
||
186 | /** |
||
187 | * Set current gather methods option value |
||
188 | 40 | * @throws \InvalidArgumentException |
|
189 | * @param string $gatherMethods |
||
190 | 40 | * @return GeneratorOptions |
|
191 | */ |
||
192 | public function setGatherMethods($gatherMethods) |
||
193 | { |
||
194 | return $this->setOptionValue(self::GATHER_METHODS, $gatherMethods); |
||
195 | } |
||
196 | 50 | /** |
|
197 | * Get generate tutorial file option value |
||
198 | 50 | * @return bool |
|
199 | */ |
||
200 | public function getGenerateTutorialFile() |
||
201 | { |
||
202 | return $this->getOptionValue(self::GENERATE_TUTORIAL_FILE); |
||
203 | } |
||
204 | /** |
||
205 | * Set current generate tutorial file option value |
||
206 | 75 | * @throws \InvalidArgumentException |
|
207 | * @param bool $generateTutorialFile |
||
208 | 75 | * @return GeneratorOptions |
|
209 | */ |
||
210 | public function setGenerateTutorialFile($generateTutorialFile) |
||
211 | { |
||
212 | return $this->setOptionValue(self::GENERATE_TUTORIAL_FILE, $generateTutorialFile); |
||
213 | } |
||
214 | 375 | /** |
|
215 | * Get namespace option value |
||
216 | 375 | * @return string |
|
217 | */ |
||
218 | public function getNamespace() |
||
219 | { |
||
220 | return $this->getOptionValue(self::NAMESPACE_PREFIX); |
||
221 | } |
||
222 | /** |
||
223 | * Set current namespace option value |
||
224 | 55 | * @throws \InvalidArgumentException |
|
225 | * @param string $namespace |
||
226 | 55 | * @return GeneratorOptions |
|
227 | */ |
||
228 | public function setNamespace($namespace) |
||
229 | { |
||
230 | return $this->setOptionValue(self::NAMESPACE_PREFIX, $namespace); |
||
231 | } |
||
232 | 90 | /** |
|
233 | * Get generic constants name option value |
||
234 | 90 | * @return bool |
|
235 | */ |
||
236 | public function getGenericConstantsName() |
||
237 | { |
||
238 | return $this->getOptionValue(self::GENERIC_CONSTANTS_NAME); |
||
239 | } |
||
240 | /** |
||
241 | * Set current generic constants name option value |
||
242 | 75 | * @throws \InvalidArgumentException |
|
243 | * @param bool $genericConstantsName |
||
244 | 75 | * @return GeneratorOptions |
|
245 | */ |
||
246 | public function setGenericConstantsName($genericConstantsName) |
||
247 | { |
||
248 | return $this->setOptionValue(self::GENERIC_CONSTANTS_NAME, $genericConstantsName); |
||
249 | } |
||
250 | 95 | /** |
|
251 | * Get standalone option value |
||
252 | 95 | * @return bool |
|
253 | */ |
||
254 | public function getStandalone() |
||
255 | { |
||
256 | return $this->getOptionValue(self::STANDALONE); |
||
257 | } |
||
258 | /** |
||
259 | * Set current standalone option value |
||
260 | 45 | * @throws \InvalidArgumentException |
|
261 | * @param bool $standalone |
||
262 | 45 | * @return GeneratorOptions |
|
263 | */ |
||
264 | public function setStandalone($standalone) |
||
265 | { |
||
266 | return $this->setOptionValue(self::STANDALONE, $standalone); |
||
267 | } |
||
268 | 175 | /** |
|
269 | * Get validation option value |
||
270 | 175 | * @return bool |
|
271 | */ |
||
272 | public function getValidation() |
||
273 | { |
||
274 | return $this->getOptionValue(self::VALIDATION); |
||
275 | } |
||
276 | /** |
||
277 | * Set current validation option value |
||
278 | 40 | * @throws \InvalidArgumentException |
|
279 | * @param bool $validation |
||
280 | 40 | * @return GeneratorOptions |
|
281 | */ |
||
282 | public function setValidation($validation) |
||
283 | { |
||
284 | return $this->setOptionValue(self::VALIDATION, $validation); |
||
285 | } |
||
286 | 150 | /** |
|
287 | * Get struct class option value |
||
288 | 150 | * @return string |
|
289 | */ |
||
290 | public function getStructClass() |
||
291 | { |
||
292 | return $this->getOptionValue(self::STRUCT_CLASS); |
||
293 | } |
||
294 | /** |
||
295 | * Set current struct class option value |
||
296 | 45 | * @throws \InvalidArgumentException |
|
297 | * @param string $structClass |
||
298 | 45 | * @return GeneratorOptions |
|
299 | */ |
||
300 | public function setStructClass($structClass) |
||
301 | { |
||
302 | return $this->setOptionValue(self::STRUCT_CLASS, $structClass); |
||
303 | } |
||
304 | 60 | /** |
|
305 | * Get struct array class option value |
||
306 | 60 | * @return string |
|
307 | */ |
||
308 | public function getStructArrayClass() |
||
309 | { |
||
310 | return $this->getOptionValue(self::STRUCT_ARRAY_CLASS); |
||
311 | } |
||
312 | /** |
||
313 | * Set current struct array class option value |
||
314 | 35 | * @throws \InvalidArgumentException |
|
315 | * @param string $structArrayClass |
||
316 | 35 | * @return GeneratorOptions |
|
317 | */ |
||
318 | public function setStructArrayClass($structArrayClass) |
||
319 | { |
||
320 | return $this->setOptionValue(self::STRUCT_ARRAY_CLASS, $structArrayClass); |
||
321 | } |
||
322 | 135 | /** |
|
323 | * Get struct array class option value |
||
324 | 135 | * @return string |
|
325 | */ |
||
326 | public function getSoapClientClass() |
||
327 | { |
||
328 | return $this->getOptionValue(self::SOAP_CLIENT_CLASS); |
||
329 | } |
||
330 | /** |
||
331 | * Set current struct array class option value |
||
332 | 35 | * @throws \InvalidArgumentException |
|
333 | * @param string $soapClientClass |
||
334 | 35 | * @return GeneratorOptions |
|
335 | */ |
||
336 | public function setSoapClientClass($soapClientClass) |
||
337 | { |
||
338 | return $this->setOptionValue(self::SOAP_CLIENT_CLASS, $soapClientClass); |
||
339 | } |
||
340 | 775 | /** |
|
341 | * Get origin option value |
||
342 | 775 | * @return string |
|
343 | */ |
||
344 | public function getOrigin() |
||
345 | { |
||
346 | return $this->getOptionValue(self::ORIGIN); |
||
347 | } |
||
348 | /** |
||
349 | * Set current origin option value |
||
350 | 410 | * @throws \InvalidArgumentException |
|
351 | * @param string $origin |
||
352 | 410 | * @return GeneratorOptions |
|
353 | */ |
||
354 | public function setOrigin($origin) |
||
355 | { |
||
356 | return $this->setOptionValue(self::ORIGIN, $origin); |
||
357 | } |
||
358 | 430 | /** |
|
359 | * Get destination option value |
||
360 | 430 | * @return string |
|
361 | */ |
||
362 | public function getDestination() |
||
363 | { |
||
364 | return $this->getOptionValue(self::DESTINATION); |
||
365 | } |
||
366 | /** |
||
367 | * Set current destination option value |
||
368 | 415 | * @throws \InvalidArgumentException |
|
369 | * @param string $destination |
||
370 | 415 | * @return GeneratorOptions |
|
371 | */ |
||
372 | public function setDestination($destination) |
||
373 | { |
||
374 | return $this->setOptionValue(self::DESTINATION, $destination); |
||
375 | } |
||
376 | 370 | /** |
|
377 | * Get src dirname option value |
||
378 | 370 | * @return string |
|
379 | */ |
||
380 | public function getSrcDirname() |
||
381 | { |
||
382 | return $this->getOptionValue(self::SRC_DIRNAME); |
||
383 | } |
||
384 | /** |
||
385 | * Set current src dirname option value |
||
386 | 25 | * @throws \InvalidArgumentException |
|
387 | * @param string $srcDirname |
||
388 | 25 | * @return GeneratorOptions |
|
389 | */ |
||
390 | public function setSrcDirname($srcDirname) |
||
391 | { |
||
392 | return $this->setOptionValue(self::SRC_DIRNAME, $srcDirname); |
||
393 | } |
||
394 | 770 | /** |
|
395 | * Get prefix option value |
||
396 | 770 | * @return string |
|
397 | */ |
||
398 | public function getPrefix() |
||
399 | { |
||
400 | return $this->getOptionValue(self::PREFIX); |
||
401 | } |
||
402 | /** |
||
403 | * Set current prefix option value |
||
404 | 135 | * @throws \InvalidArgumentException |
|
405 | * @param string $prefix |
||
406 | 135 | * @return GeneratorOptions |
|
407 | */ |
||
408 | public function setPrefix($prefix) |
||
409 | { |
||
410 | return $this->setOptionValue(self::PREFIX, $prefix); |
||
411 | } |
||
412 | 740 | /** |
|
413 | * Get suffix option value |
||
414 | 740 | * @return string |
|
415 | */ |
||
416 | public function getSuffix() |
||
417 | { |
||
418 | return $this->getOptionValue(self::SUFFIX); |
||
419 | } |
||
420 | /** |
||
421 | * Set current suffix option value |
||
422 | 65 | * @throws \InvalidArgumentException |
|
423 | * @param string $suffix |
||
424 | 65 | * @return GeneratorOptions |
|
425 | */ |
||
426 | public function setSuffix($suffix) |
||
427 | { |
||
428 | return $this->setOptionValue(self::SUFFIX, $suffix); |
||
429 | } |
||
430 | 780 | /** |
|
431 | * Get basic login option value |
||
432 | 780 | * @return string |
|
433 | */ |
||
434 | public function getBasicLogin() |
||
435 | { |
||
436 | return $this->getOptionValue(self::BASIC_LOGIN); |
||
437 | } |
||
438 | /** |
||
439 | * Set current basic login option value |
||
440 | 35 | * @throws \InvalidArgumentException |
|
441 | * @param string $basicLogin |
||
442 | 35 | * @return GeneratorOptions |
|
443 | */ |
||
444 | public function setBasicLogin($basicLogin) |
||
445 | { |
||
446 | return $this->setOptionValue(self::BASIC_LOGIN, $basicLogin); |
||
447 | } |
||
448 | 780 | /** |
|
449 | * Get basic password option value |
||
450 | 780 | * @return string |
|
451 | */ |
||
452 | public function getBasicPassword() |
||
453 | { |
||
454 | return $this->getOptionValue(self::BASIC_PASSWORD); |
||
455 | } |
||
456 | /** |
||
457 | * Set current basic password option value |
||
458 | 35 | * @throws \InvalidArgumentException |
|
459 | * @param string $basicPassword |
||
460 | 35 | * @return GeneratorOptions |
|
461 | */ |
||
462 | public function setBasicPassword($basicPassword) |
||
463 | { |
||
464 | return $this->setOptionValue(self::BASIC_PASSWORD, $basicPassword); |
||
465 | } |
||
466 | 780 | /** |
|
467 | * Get basic proxy host option value |
||
468 | 780 | * @return string |
|
469 | */ |
||
470 | public function getProxyHost() |
||
471 | { |
||
472 | return $this->getOptionValue(self::PROXY_HOST); |
||
473 | } |
||
474 | /** |
||
475 | * Set current proxy host option value |
||
476 | 35 | * @throws \InvalidArgumentException |
|
477 | * @param string $proxyHost |
||
478 | 35 | * @return GeneratorOptions |
|
479 | */ |
||
480 | public function setProxyHost($proxyHost) |
||
481 | { |
||
482 | return $this->setOptionValue(self::PROXY_HOST, $proxyHost); |
||
483 | } |
||
484 | 780 | /** |
|
485 | * Get basic proxy port option value |
||
486 | 780 | * @return string |
|
487 | */ |
||
488 | public function getProxyPort() |
||
489 | { |
||
490 | return $this->getOptionValue(self::PROXY_PORT); |
||
491 | } |
||
492 | /** |
||
493 | * Set current proxy port option value |
||
494 | 35 | * @throws \InvalidArgumentException |
|
495 | * @param string $proxyPort |
||
496 | 35 | * @return GeneratorOptions |
|
497 | */ |
||
498 | public function setProxyPort($proxyPort) |
||
499 | { |
||
500 | return $this->setOptionValue(self::PROXY_PORT, $proxyPort); |
||
501 | } |
||
502 | 780 | /** |
|
503 | * Get basic proxy login option value |
||
504 | 780 | * @return string |
|
505 | */ |
||
506 | public function getProxyLogin() |
||
507 | { |
||
508 | return $this->getOptionValue(self::PROXY_LOGIN); |
||
509 | } |
||
510 | /** |
||
511 | * Set current proxy login option value |
||
512 | 35 | * @throws \InvalidArgumentException |
|
513 | * @param string $proxyLogin |
||
514 | 35 | * @return GeneratorOptions |
|
515 | */ |
||
516 | public function setProxyLogin($proxyLogin) |
||
517 | { |
||
518 | return $this->setOptionValue(self::PROXY_LOGIN, $proxyLogin); |
||
519 | } |
||
520 | 780 | /** |
|
521 | * Get basic proxy password option value |
||
522 | 780 | * @return string |
|
523 | */ |
||
524 | public function getProxyPassword() |
||
525 | { |
||
526 | return $this->getOptionValue(self::PROXY_PASSWORD); |
||
527 | } |
||
528 | /** |
||
529 | * Set current proxy password option value |
||
530 | 35 | * @throws \InvalidArgumentException |
|
531 | * @param string $proxyPassword |
||
532 | 35 | * @return GeneratorOptions |
|
533 | */ |
||
534 | public function setProxyPassword($proxyPassword) |
||
535 | { |
||
536 | return $this->setOptionValue(self::PROXY_PASSWORD, $proxyPassword); |
||
537 | } |
||
538 | 770 | /** |
|
539 | * Get basic soap options option value |
||
540 | 770 | * @return array |
|
541 | */ |
||
542 | public function getSoapOptions() |
||
543 | { |
||
544 | return $this->getOptionValue(self::SOAP_OPTIONS); |
||
545 | } |
||
546 | /** |
||
547 | * Set current soap options option value |
||
548 | 40 | * @throws \InvalidArgumentException |
|
549 | * @param array $soapOptions |
||
550 | 40 | * @return GeneratorOptions |
|
551 | */ |
||
552 | public function setSoapOptions(array $soapOptions) |
||
553 | { |
||
554 | return $this->setOptionValue(self::SOAP_OPTIONS, $soapOptions); |
||
555 | } |
||
556 | 75 | /** |
|
557 | * Get composer name option value |
||
558 | 75 | * @return string |
|
559 | */ |
||
560 | public function getComposerName() |
||
561 | { |
||
562 | return $this->getOptionValue(self::COMPOSER_NAME); |
||
563 | } |
||
564 | /** |
||
565 | * Set current composer name option value |
||
566 | 105 | * @throws \InvalidArgumentException |
|
567 | * @param string $composerName |
||
568 | 105 | * @return GeneratorOptions |
|
569 | */ |
||
570 | public function setComposerName($composerName) |
||
571 | { |
||
572 | return $this->setOptionValue(self::COMPOSER_NAME, $composerName); |
||
573 | } |
||
574 | 60 | /** |
|
575 | * Get composer settings option value |
||
576 | 60 | * @return array |
|
577 | */ |
||
578 | public function getComposerSettings() |
||
579 | { |
||
580 | return $this->getOptionValue(self::COMPOSER_SETTINGS); |
||
581 | } |
||
582 | /** |
||
583 | * Set current composer settings option value |
||
584 | 90 | * @throws \InvalidArgumentException |
|
585 | * @param array $composerSettings |
||
586 | * @return GeneratorOptions |
||
587 | */ |
||
588 | public function setComposerSettings(array $composerSettings = []) |
||
589 | 90 | { |
|
590 | 90 | /** |
|
591 | 35 | * If array is type array("config.value:true","require:library/src",) |
|
592 | 35 | */ |
|
593 | 35 | $settings = []; |
|
594 | 35 | foreach ($composerSettings as $index => $value) { |
|
595 | 21 | if (is_numeric($index) && strpos($value, ':') > 0) { |
|
596 | 17 | $path = implode('', array_slice(explode(':', $value), 0, 1)); |
|
597 | $val = implode(':', array_slice(explode(':', $value), 1)); |
||
598 | 54 | self::dotNotationToArray($path, $val, $settings); |
|
599 | 90 | } else { |
|
600 | $settings[$index] = $value; |
||
601 | } |
||
602 | } |
||
603 | return $this->setOptionValue(self::COMPOSER_SETTINGS, $settings); |
||
604 | } |
||
605 | /** |
||
606 | * turns my.key.path to array('my' => array('key' => array('path' => $value))) |
||
607 | 35 | * @param string $string |
|
608 | * @param mixed $value |
||
609 | 35 | * @param array $array |
|
610 | 35 | */ |
|
611 | 35 | protected static function dotNotationToArray($string, $value, array &$array) |
|
612 | 21 | { |
|
613 | 35 | $keys = explode('.', $string); |
|
614 | 35 | foreach ($keys as $key) { |
|
615 | $array = &$array[$key]; |
||
616 | } |
||
617 | $array = ($value === 'true' || $value === 'false') ? $value === 'true' : $value; |
||
618 | } |
||
619 | 375 | /** |
|
620 | * Get structs folder option value |
||
621 | 375 | * @return string |
|
622 | */ |
||
623 | public function getStructsFolder() |
||
624 | { |
||
625 | return $this->getOptionValue(self::STRUCTS_FOLDER); |
||
626 | } |
||
627 | /** |
||
628 | * Set current structs folder option value |
||
629 | 35 | * @throws \InvalidArgumentException |
|
630 | * @param string $structsFolder |
||
631 | 35 | * @return GeneratorOptions |
|
632 | */ |
||
633 | public function setStructsFolder($structsFolder) |
||
634 | { |
||
635 | return $this->setOptionValue(self::STRUCTS_FOLDER, $structsFolder); |
||
636 | } |
||
637 | 80 | /** |
|
638 | * Get arrays folder option value |
||
639 | 80 | * @return string |
|
640 | */ |
||
641 | public function getArraysFolder() |
||
642 | { |
||
643 | return $this->getOptionValue(self::ARRAYS_FOLDER); |
||
644 | } |
||
645 | /** |
||
646 | * Set current arrays folder option value |
||
647 | 35 | * @throws \InvalidArgumentException |
|
648 | * @param string $arraysFolder |
||
649 | 35 | * @return GeneratorOptions |
|
650 | */ |
||
651 | public function setArraysFolder($arraysFolder) |
||
652 | { |
||
653 | return $this->setOptionValue(self::ARRAYS_FOLDER, $arraysFolder); |
||
654 | } |
||
655 | 150 | /** |
|
656 | * Get enums folder option value |
||
657 | 150 | * @return string |
|
658 | */ |
||
659 | public function getEnumsFolder() |
||
660 | { |
||
661 | return $this->getOptionValue(self::ENUMS_FOLDER); |
||
662 | } |
||
663 | /** |
||
664 | * Set current enums folder option value |
||
665 | 35 | * @throws \InvalidArgumentException |
|
666 | * @param string $enumsFolder |
||
667 | 35 | * @return GeneratorOptions |
|
668 | */ |
||
669 | public function setEnumsFolder($enumsFolder) |
||
670 | { |
||
671 | return $this->setOptionValue(self::ENUMS_FOLDER, $enumsFolder); |
||
672 | } |
||
673 | 735 | /** |
|
674 | * Get services folder option value |
||
675 | 735 | * @return string |
|
676 | */ |
||
677 | public function getServicesFolder() |
||
678 | { |
||
679 | return $this->getOptionValue(self::SERVICES_FOLDER); |
||
680 | } |
||
681 | /** |
||
682 | * Set current services folder option value |
||
683 | 35 | * @throws \InvalidArgumentException |
|
684 | * @param string $servicesFolder |
||
685 | 35 | * @return GeneratorOptions |
|
686 | */ |
||
687 | public function setServicesFolder($servicesFolder) |
||
688 | { |
||
689 | return $this->setOptionValue(self::SERVICES_FOLDER, $servicesFolder); |
||
690 | 45 | } |
|
691 | /** |
||
692 | 45 | * Get schemas save option value |
|
693 | 45 | * @return bool |
|
694 | 45 | */ |
|
695 | 27 | public function getSchemasSave() |
|
696 | 45 | { |
|
697 | return $this->getOptionValue(self::SCHEMAS_SAVE); |
||
698 | 10 | } |
|
699 | /** |
||
700 | 10 | * Set schemas save option value |
|
701 | * @throws \InvalidArgumentException |
||
702 | * @param bool $saveSchemas |
||
703 | * @return GeneratorOptions |
||
704 | */ |
||
705 | public function setSchemasSave($saveSchemas) |
||
709 | /** |
||
710 | * Get schemas folder option value |
||
711 | * @return bool |
||
712 | */ |
||
713 | public function getSchemasFolder() |
||
717 | /** |
||
718 | * Set schemas folder option value |
||
719 | * @throws \InvalidArgumentException |
||
720 | * @param string $schemasFolder |
||
721 | * @return GeneratorOptions |
||
722 | */ |
||
723 | public function setSchemasFolder($schemasFolder) |
||
724 | { |
||
725 | return $this->setOptionValue(self::SCHEMAS_FOLDER, $schemasFolder); |
||
726 | } |
||
727 | /** |
||
728 | * @return string[] |
||
729 | */ |
||
730 | public function toArray() |
||
731 | { |
||
732 | $options = []; |
||
733 | foreach (array_keys($this->options) as $name) { |
||
734 | $options[$name] = $this->getOptionValue($name); |
||
735 | } |
||
736 | return $options; |
||
737 | } |
||
738 | public function jsonSerialize() |
||
739 | { |
||
740 | return $this->toArray(); |
||
741 | } |
||
742 | } |
||
743 |