Completed
Push — feature/issue-99 ( def87e )
by Mikaël
02:17
created

Generator::initFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Generator;
4
5
use WsdlToPhp\PackageGenerator\Model\Schema;
6
use WsdlToPhp\PackageGenerator\Model\Wsdl;
7
use WsdlToPhp\PackageGenerator\Model\AbstractModel;
8
use WsdlToPhp\PackageGenerator\Model\EmptyModel;
9
use WsdlToPhp\PackageGenerator\Model\Struct;
10
use WsdlToPhp\PackageGenerator\Model\Service;
11
use WsdlToPhp\PackageGenerator\Model\Method;
12
use WsdlToPhp\PackageGenerator\Container\Model\Service as ServiceContainer;
13
use WsdlToPhp\PackageGenerator\Container\Model\Struct as StructContainer;
14
use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions;
15
use WsdlToPhp\PackageGenerator\WsdlHandler\Wsdl as WsdlDocument;
16
17
class Generator implements \JsonSerializable
18
{
19
    /**
20
     * Wsdl
21
     * @var Wsdl
22
     */
23
    private $wsdl;
24
    /**
25
     * @var GeneratorOptions
26
     */
27
    private $options;
28
    /**
29
     * Used parsers
30
     * @var GeneratorParsers
31
     */
32
    private $parsers;
33
    /**
34
     * Used files
35
     * @var GeneratorFiles
36
     */
37
    private $files;
38
    /**
39
     * Used containers
40
     * @var GeneratorContainers
41
     */
42
    private $containers;
43
    /**
44
     * Used SoapClient
45
     * @var GeneratorSoapClient
46
     */
47
    private $soapClient;
48
    /**
49
     * Constructor
50
     * @param GeneratorOptions $options
51
     */
52
    public function __construct(GeneratorOptions $options)
53
    {
54
        $this->setOptions($options)->initialize();
55
    }
56
    /**
57
     * @return Generator
58
     */
59
    protected function initialize()
60
    {
61
        return $this->initContainers()
62
            ->initParsers()
63
            ->initFiles()
64
            ->initSoapClient()
65
            ->initWsdl();
66
    }
67
    /**
68
     * @throws \InvalidArgumentException
69
     * @return Generator
70
     */
71
    protected function initSoapClient()
72
    {
73
        if (!isset($this->soapClient)) {
74
            $this->soapClient = new GeneratorSoapClient($this);
75
        }
76
        return $this;
77
    }
78
    /**
79
     * @return Generator
80
     */
81
    protected function initContainers()
82
    {
83
        if (!isset($this->containers)) {
84
            $this->containers = new GeneratorContainers($this);
85
        }
86
        return $this;
87
    }
88
    /**
89
     * @return Generator
90
     */
91
    protected function initParsers()
92
    {
93
        if (!isset($this->parsers)) {
94
            $this->parsers = new GeneratorParsers($this);
95
        }
96
        return $this;
97
    }
98
    /**
99
     * @return GeneratorParsers
100
     */
101
    public function getParsers()
102
    {
103
        return $this->parsers;
104
    }
105
    /**
106
     * @return Generator
107
     */
108
    protected function initFiles()
109
    {
110
        if (!isset($this->files)) {
111
            $this->files = new GeneratorFiles($this);
112
        }
113
        return $this;
114
    }
115
    /**
116
     * @return GeneratorFiles
117
     */
118
    public function getFiles()
119
    {
120
        return $this->files;
121
    }
122
    /**
123
     * @throws \InvalidArgumentException
124
     * @return Generator
125
     */
126
    protected function initDirectory()
127
    {
128
        Utils::createDirectory($this->getOptions()->getDestination());
129
        if (!is_writable($this->getOptionDestination())) {
130
            throw new \InvalidArgumentException(sprintf('Unable to use dir "%s" as dir does not exists, its creation has been impossible or it\'s not writable', $this->getOptionDestination()), __LINE__);
131
        }
132
        return $this;
133
    }
134
    /**
135
     * @return Generator
136
     */
137
    protected function initWsdl()
138
    {
139
        $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin())));
140
        return $this;
141
    }
142
    /**
143
     * @return Generator
144
     */
145
    protected function doSanityChecks()
146
    {
147
        $destination = $this->getOptionDestination();
148
        if (empty($destination)) {
149
            throw new \InvalidArgumentException('Package\'s destination must be defined', __LINE__);
150
        }
151
        $composerName = $this->getOptionComposerName();
152
        if ($this->getOptionStandalone() && empty($composerName)) {
153
            throw new \InvalidArgumentException('Package\'s composer name must be defined', __LINE__);
154
        }
155
        return $this;
156
    }
157
    /**
158
     * @return Generator
159
     */
160
    protected function doParse()
161
    {
162
        $this->parsers->doParse();
163
        return $this;
164
    }
165
    /**
166
     * @return Generator
167
     */
168
    protected function doGenerate()
169
    {
170
        $this->files->doGenerate();
171
        return $this;
172
    }
173
    /**
174
     * Generates all classes based on options
175
     * @return Generator
176
     */
177
    public function generatePackage()
178
    {
179
        return $this->doSanityChecks()->initDirectory()->doParse()->doGenerate();
180
    }
181
    /**
182
     * Gets the struct by its name
183
     * @uses Generator::getStructs()
184
     * @param string $structName the original struct name
185
     * @return Struct|null
186
     */
187
    public function getStruct($structName)
188
    {
189
        return $this->getStructs()->getStructByName($structName);
190
    }
191
    /**
192
     * Gets a service by its name
193
     * @param string $serviceName the service name
194
     * @return Service|null
195
     */
196
    public function getService($serviceName)
197
    {
198
        return $this->getServices()->getServiceByName($serviceName);
199
    }
200
    /**
201
     * Returns the method
202
     * @uses Generator::getServiceName()
203
     * @uses Generator::getService()
204
     * @uses Service::getMethod()
205
     * @param string $methodName the original function name
206
     * @return Method|null
207
     */
208
    public function getServiceMethod($methodName)
209
    {
210
        return $this->getService($this->getServiceName($methodName)) instanceof Service ? $this->getService($this->getServiceName($methodName))->getMethod($methodName) : null;
211
    }
212
    /**
213
     * @return ServiceContainer
214
     */
215
    public function getServices()
216
    {
217
        return $this->containers->getServices();
218
    }
219
    /**
220
     * @return StructContainer
221
     */
222
    public function getStructs()
223
    {
224
        return $this->containers->getStructs();
225
    }
226
    /**
227
     * Sets the optionCategory value
228
     * @return string
229
     */
230
    public function getOptionCategory()
231
    {
232
        return $this->options->getCategory();
233
    }
234
    /**
235
     * Sets the optionCategory value
236
     * @param string $category
237
     * @return Generator
238
     */
239
    public function setOptionCategory($category)
240
    {
241
        $this->options->setCategory($category);
242
        return $this;
243
    }
244
    /**
245
     * Sets the optionGatherMethods value
246
     * @return string
247
     */
248
    public function getOptionGatherMethods()
249
    {
250
        return $this->options->getGatherMethods();
251
    }
252
    /**
253
     * Sets the optionGatherMethods value
254
     * @param string $gatherMethods
255
     * @return Generator
256
     */
257
    public function setOptionGatherMethods($gatherMethods)
258
    {
259
        $this->options->setGatherMethods($gatherMethods);
260
        return $this;
261
    }
262
    /**
263
     * Gets the optionGenericConstantsNames value
264
     * @return bool
265
     */
266
    public function getOptionGenericConstantsNames()
267
    {
268
        return $this->options->getGenericConstantsName();
269
    }
270
    /**
271
     * Sets the optionGenericConstantsNames value
272
     * @param bool $genericConstantsNames
273
     * @return Generator
274
     */
275
    public function setOptionGenericConstantsNames($genericConstantsNames)
276
    {
277
        $this->options->setGenericConstantsName($genericConstantsNames);
278
        return $this;
279
    }
280
    /**
281
     * Gets the optionGenerateTutorialFile value
282
     * @return bool
283
     */
284
    public function getOptionGenerateTutorialFile()
285
    {
286
        return $this->options->getGenerateTutorialFile();
287
    }
288
    /**
289
     * Sets the optionGenerateTutorialFile value
290
     * @param bool $generateTutorialFile
291
     * @return Generator
292
     */
293
    public function setOptionGenerateTutorialFile($generateTutorialFile)
294
    {
295
        $this->options->setGenerateTutorialFile($generateTutorialFile);
296
        return $this;
297
    }
298
    /**
299
     * Gets the optionNamespacePrefix value
300
     * @return string
301
     */
302
    public function getOptionNamespacePrefix()
303
    {
304
        return $this->options->getNamespace();
305
    }
306
    /**
307
     * Sets the optionGenerateTutorialFile value
308
     * @param string $namespace
309
     * @return Generator
310
     */
311
    public function setOptionNamespacePrefix($namespace)
312
    {
313
        $this->options->setNamespace($namespace);
314
        return $this;
315
    }
316
    /**
317
     * Gets the optionAddComments value
318
     * @return array
319
     */
320
    public function getOptionAddComments()
321
    {
322
        return $this->options->getAddComments();
323
    }
324
    /**
325
     * Sets the optionAddComments value
326
     * @param array $addComments
327
     * @return Generator
328
     */
329
    public function setOptionAddComments($addComments)
330
    {
331
        $this->options->setAddComments($addComments);
332
        return $this;
333
    }
334
    /**
335
     * Gets the optionStandalone value
336
     * @return bool
337
     */
338
    public function getOptionStandalone()
339
    {
340
        return $this->options->getStandalone();
341
    }
342
    /**
343
     * Sets the optionStandalone value
344
     * @param bool $standalone
345
     * @return Generator
346
     */
347
    public function setOptionStandalone($standalone)
348
    {
349
        $this->options->setStandalone($standalone);
350
        return $this;
351
    }
352
    /**
353
     * Gets the optionValidation value
354
     * @return bool
355
     */
356
    public function getOptionValidation()
357
    {
358
        return $this->options->getValidation();
359
    }
360
    /**
361
     * Sets the optionValidation value
362
     * @param bool $validation
363
     * @return Generator
364
     */
365
    public function setOptionValidation($validation)
366
    {
367
        $this->options->setValidation($validation);
368
        return $this;
369
    }
370
    /**
371
     * Gets the optionStructClass value
372
     * @return string
373
     */
374
    public function getOptionStructClass()
375
    {
376
        return $this->options->getStructClass();
377
    }
378
    /**
379
     * Sets the optionStructClass value
380
     * @param string $structClass
381
     * @return Generator
382
     */
383
    public function setOptionStructClass($structClass)
384
    {
385
        $this->options->setStructClass($structClass);
386
        return $this;
387
    }
388
    /**
389
     * Gets the optionStructArrayClass value
390
     * @return string
391
     */
392
    public function getOptionStructArrayClass()
393
    {
394
        return $this->options->getStructArrayClass();
395
    }
396
    /**
397
     * Sets the optionStructArrayClass value
398
     * @param string $structArrayClass
399
     * @return Generator
400
     */
401
    public function setOptionStructArrayClass($structArrayClass)
402
    {
403
        $this->options->setStructArrayClass($structArrayClass);
404
        return $this;
405
    }
406
    /**
407
     * Gets the optionSoapClientClass value
408
     * @return string
409
     */
410
    public function getOptionSoapClientClass()
411
    {
412
        return $this->options->getSoapClientClass();
413
    }
414
    /**
415
     * Sets the optionSoapClientClass value
416
     * @param string $soapClientClass
417
     * @return Generator
418
     */
419
    public function setOptionSoapClientClass($soapClientClass)
420
    {
421
        $this->options->setSoapClientClass($soapClientClass);
422
        return $this;
423
    }
424
    /**
425
     * Gets the package name prefix
426
     * @param bool $ucFirst ucfirst package name prefix or not
427
     * @return string
428
     */
429
    public function getOptionPrefix($ucFirst = true)
430
    {
431
        return $ucFirst ? ucfirst($this->getOptions()->getPrefix()) : $this->getOptions()->getPrefix();
432
    }
433
    /**
434
     * Sets the package name prefix
435
     * @param string $optionPrefix
436
     * @return Generator
437
     */
438
    public function setOptionPrefix($optionPrefix)
439
    {
440
        $this->options->setPrefix($optionPrefix);
441
        return $this;
442
    }
443
    /**
444
     * Gets the package name suffix
445
     * @param bool $ucFirst ucfirst package name suffix or not
446
     * @return string
447
     */
448
    public function getOptionSuffix($ucFirst = true)
449
    {
450
        return $ucFirst ? ucfirst($this->getOptions()->getSuffix()) : $this->getOptions()->getSuffix();
451
    }
452
    /**
453
     * Sets the package name suffix
454
     * @param string $optionSuffix
455
     * @return Generator
456
     */
457
    public function setOptionSuffix($optionSuffix)
458
    {
459
        $this->options->setSuffix($optionSuffix);
460
        return $this;
461
    }
462
    /**
463
     * Gets the optionBasicLogin value
464
     * @return string
465
     */
466
    public function getOptionBasicLogin()
467
    {
468
        return $this->options->getBasicLogin();
469
    }
470
    /**
471
     * Sets the optionBasicLogin value
472
     * @param string $optionBasicLogin
473
     * @return Generator
474
     */
475
    public function setOptionBasicLogin($optionBasicLogin)
476
    {
477
        $this->options->setBasicLogin($optionBasicLogin);
478
        return $this;
479
    }
480
    /**
481
     * Gets the optionBasicPassword value
482
     * @return string
483
     */
484
    public function getOptionBasicPassword()
485
    {
486
        return $this->options->getBasicPassword();
487
    }
488
    /**
489
     * Sets the optionBasicPassword value
490
     * @param string $optionBasicPassword
491
     * @return Generator
492
     */
493
    public function setOptionBasicPassword($optionBasicPassword)
494
    {
495
        $this->options->setBasicPassword($optionBasicPassword);
496
        return $this;
497
    }
498
    /**
499
     * Gets the optionProxyHost value
500
     * @return string
501
     */
502
    public function getOptionProxyHost()
503
    {
504
        return $this->options->getProxyHost();
505
    }
506
    /**
507
     * Sets the optionProxyHost value
508
     * @param string $optionProxyHost
509
     * @return Generator
510
     */
511
    public function setOptionProxyHost($optionProxyHost)
512
    {
513
        $this->options->setProxyHost($optionProxyHost);
514
        return $this;
515
    }
516
    /**
517
     * Gets the optionProxyPort value
518
     * @return string
519
     */
520
    public function getOptionProxyPort()
521
    {
522
        return $this->options->getProxyPort();
523
    }
524
    /**
525
     * Sets the optionProxyPort value
526
     * @param string $optionProxyPort
527
     * @return Generator
528
     */
529
    public function setOptionProxyPort($optionProxyPort)
530
    {
531
        $this->options->setProxyPort($optionProxyPort);
532
        return $this;
533
    }
534
    /**
535
     * Gets the optionProxyLogin value
536
     * @return string
537
     */
538
    public function getOptionProxyLogin()
539
    {
540
        return $this->options->getProxyLogin();
541
    }
542
    /**
543
     * Sets the optionProxyLogin value
544
     * @param string $optionProxyLogin
545
     * @return Generator
546
     */
547
    public function setOptionProxyLogin($optionProxyLogin)
548
    {
549
        $this->options->setProxyLogin($optionProxyLogin);
550
        return $this;
551
    }
552
    /**
553
     * Gets the optionProxyPassword value
554
     * @return string
555
     */
556
    public function getOptionProxyPassword()
557
    {
558
        return $this->options->getProxyPassword();
559
    }
560
    /**
561
     * Sets the optionProxyPassword value
562
     * @param string $optionProxyPassword
563
     * @return Generator
564
     */
565
    public function setOptionProxyPassword($optionProxyPassword)
566
    {
567
        $this->options->setProxyPassword($optionProxyPassword);
568
        return $this;
569
    }
570
    /**
571
     * Gets the optionOrigin value
572
     * @return string
573
     */
574
    public function getOptionOrigin()
575
    {
576
        return $this->options->getOrigin();
577
    }
578
    /**
579
     * Sets the optionOrigin value
580
     * @param string $optionOrigin
581
     * @return Generator
582
     */
583
    public function setOptionOrigin($optionOrigin)
584
    {
585
        $this->options->setOrigin($optionOrigin);
586
        $this->initWsdl();
587
        return $this;
588
    }
589
    /**
590
     * Gets the optionDestination value
591
     * @return string
592
     */
593
    public function getOptionDestination()
594
    {
595
        $destination = $this->options->getDestination();
596
        if (!empty($destination)) {
597
            $destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
598
        }
599
        return $destination;
600
    }
601
    /**
602
     * Sets the optionDestination value
603
     * @param string $optionDestination
604
     * @return Generator
605
     */
606
    public function setOptionDestination($optionDestination)
607
    {
608
        if (!empty($optionDestination)) {
609
            $this->options->setDestination(rtrim($optionDestination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
610
        } else {
611
            throw new \InvalidArgumentException('Package\'s destination can\'t be empty', __LINE__);
612
        }
613
        return $this;
614
    }
615
    /**
616
     * Gets the optionSrcDiname value
617
     * @return string
618
     */
619
    public function getOptionSrcDirname()
620
    {
621
        return $this->options->getSrcDirname();
622
    }
623
    /**
624
     * Sets the optionSrcDirname value
625
     * @param string $optionSrcDirname
626
     * @return Generator
627
     */
628
    public function setOptionSrcDirname($optionSrcDirname)
629
    {
630
        $this->options->setSrcDirname($optionSrcDirname);
631
        return $this;
632
    }
633
    /**
634
     * Gets the optionSoapOptions value
635
     * @return string
636
     */
637
    public function getOptionSoapOptions()
638
    {
639
        return $this->options->getSoapOptions();
640
    }
641
    /**
642
     * Sets the optionSoapOptions value
643
     * @param array $optionSoapOptions
644
     * @return Generator
645
     */
646
    public function setOptionSoapOptions($optionSoapOptions)
647
    {
648
        $this->options->setSoapOptions($optionSoapOptions);
649
        if ($this->getSoapClient() instanceof GeneratorSoapClient) {
650
            $this->getSoapClient()->initSoapClient();
651
        }
652
        return $this;
653
    }
654
    /**
655
     * Gets the optionComposerName value
656
     * @return string
657
     */
658
    public function getOptionComposerName()
659
    {
660
        return $this->options->getComposerName();
661
    }
662
    /**
663
     * Sets the optionComposerName value
664
     * @param string $optionComposerName
665
     * @return Generator
666
     */
667
    public function setOptionComposerName($optionComposerName)
668
    {
669
        if (!empty($optionComposerName)) {
670
            $this->options->setComposerName($optionComposerName);
671
        } else {
672
            throw new \InvalidArgumentException('Package\'s composer name can\'t be empty', __LINE__);
673
        }
674
        return $this;
675
    }
676
    /**
677
     * Gets the optionComposerSettings value
678
     * @return array
679
     */
680
    public function getOptionComposerSettings()
681
    {
682
        return $this->options->getComposerSettings();
683
    }
684
    /**
685
     * Sets the optionComposerSettings value
686
     * @param array $optionComposerSettings
687
     * @return Generator
688
     */
689
    public function setOptionComposerSettings(array $optionComposerSettings = array())
690
    {
691
        $this->options->setComposerSettings($optionComposerSettings);
692
        return $this;
693
    }
694
    /**
695
     * Gets the optionStructsFolder value
696
     * @return string
697
     */
698
    public function getOptionStructsFolder()
699
    {
700
        return $this->options->getStructsFolder();
701
    }
702
    /**
703
     * Sets the optionStructsFolder value
704
     * @param string $optionStructsFolder
705
     * @return Generator
706
     */
707
    public function setOptionStructsFolder($optionStructsFolder)
708
    {
709
        $this->options->setStructsFolder($optionStructsFolder);
710
        return $this;
711
    }
712
    /**
713
     * Gets the optionArraysFolder value
714
     * @return string
715
     */
716
    public function getOptionArraysFolder()
717
    {
718
        return $this->options->getArraysFolder();
719
    }
720
    /**
721
     * Sets the optionArraysFolder value
722
     * @param string $optionArraysFolder
723
     * @return Generator
724
     */
725
    public function setOptionArraysFolder($optionArraysFolder)
726
    {
727
        $this->options->setArraysFolder($optionArraysFolder);
728
        return $this;
729
    }
730
    /**
731
     * Gets the optionEnumsFolder value
732
     * @return string
733
     */
734
    public function getOptionEnumsFolder()
735
    {
736
        return $this->options->getEnumsFolder();
737
    }
738
    /**
739
     * Sets the optionEnumsFolder value
740
     * @param string $optionEnumsFolder
741
     * @return Generator
742
     */
743
    public function setOptionEnumsFolder($optionEnumsFolder)
744
    {
745
        $this->options->setEnumsFolder($optionEnumsFolder);
746
        return $this;
747
    }
748
    /**
749
     * Gets the optionServicesFolder value
750
     * @return string
751
     */
752
    public function getOptionServicesFolder()
753
    {
754
        return $this->options->getServicesFolder();
755
    }
756
    /**
757
     * Sets the optionServicesFolder value
758
     * @param string $optionServicesFolder
759
     * @return Generator
760
     */
761
    public function setOptionServicesFolder($optionServicesFolder)
762
    {
763
        $this->options->setServicesFolder($optionServicesFolder);
764
        return $this;
765
    }
766
    /**
767
     * Gets the WSDL
768
     * @return Wsdl|null
769
     */
770
    public function getWsdl()
771
    {
772
        return $this->wsdl;
773
    }
774
    /**
775
     * Sets the WSDLs
776
     * @param Wsdl $wsdl
777
     * @return Generator
778
     */
779
    protected function setWsdl(Wsdl $wsdl)
780
    {
781
        $this->wsdl = $wsdl;
782
        return $this;
783
    }
784
    /**
785
     * Adds Wsdl location
786
     * @param Wsdl $wsdl
787
     * @param string $schemaLocation
788
     * @return Generator
789
     */
790
    public function addSchemaToWsdl(Wsdl $wsdl, $schemaLocation)
791
    {
792
        if (!empty($schemaLocation) && $wsdl->getContent() instanceof WsdlDocument && $wsdl->getContent()->getExternalSchema($schemaLocation) === null) {
793
            $wsdl->getContent()->addExternalSchema(new Schema($wsdl->getGenerator(), $schemaLocation, $this->getUrlContent($schemaLocation)));
794
        }
795
        return $this;
796
    }
797
    /**
798
     * Gets gather name class
799
     * @param AbstractModel $model the model for which we generate the folder
800
     * @return string
801
     */
802
    private function getGather(AbstractModel $model)
803
    {
804
        return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName());
805
    }
806
    /**
807
     * Returns the service name associated to the method/operation name in order to gather them in one service class
808
     * @uses Generator::getGather()
809
     * @param string $methodName original operation/method name
810
     * @return string
811
     */
812
    public function getServiceName($methodName)
813
    {
814
        return ucfirst($this->getOptionGatherMethods() === GeneratorOptions::VALUE_NONE ? Service::DEFAULT_SERVICE_CLASS_NAME : $this->getGather(new EmptyModel($this, $methodName)));
815
    }
816
    /**
817
     * @param GeneratorOptions $options
818
     * @return Generator
819
     */
820
    protected function setOptions(GeneratorOptions $options = null)
821
    {
822
        $this->options = $options;
823
        return $this;
824
    }
825
    /**
826
     * @return GeneratorOptions
827
     */
828
    public function getOptions()
829
    {
830
        return $this->options;
831
    }
832
    /**
833
     * @return GeneratorSoapClient
834
     */
835
    public function getSoapClient()
836
    {
837
        return $this->soapClient;
838
    }
839
    /**
840
     * @param string $url
841
     * @return string
842
     */
843
    public function getUrlContent($url)
844
    {
845
        if (strpos($url, '://') !== false) {
846
            return Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions());
847
        } elseif (is_file($url)) {
848
            return file_get_contents($url);
849
        }
850
        return null;
851
    }
852
    /**
853
     * @return GeneratorContainers
854
     */
855
    public function getContainers()
856
    {
857
        return $this->containers;
858
    }
859
    /**
860
     * @return array
861
     */
862
    public function jsonSerialize()
863
    {
864
        return array(
865
            'containers' => $this->containers,
866
            'options' => $this->options,
867
        );
868
    }
869
    /**
870
     * @param string $json
871
     * @throws \InvalidArgumentException
872
     * @return Generator
873
     */
874
    public static function instanceFromSerializedJson($json)
875
    {
876
        $instance = null;
0 ignored issues
show
Unused Code introduced by
$instance is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
877
        $decodedJson = json_decode($json, true);
878
        if (json_last_error() === JSON_ERROR_NONE) {
879
            // load options first
880
            $options = GeneratorOptions::instance();
881
            foreach ($decodedJson['options']as $name => $value) {
882
                $options->setOptionValue($name, $value);
883
            }
884
            // create generator instance with options
885
            $instance = new static($options);
886
            // load services
887
            foreach ($decodedJson['containers']['services'] as $service) {
888
                $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
889
            }
890
            // load sructs
891
            foreach ($decodedJson['containers']['structs'] as $struct) {
892
                $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
893
            }
894
        } else {
895
            throw new \InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
896
        }
897
        return $instance;
898
    }
899
    /**
900
     * @param Generator $generator
901
     * @param array $jsonArrayEntry
902
     * @return AbstractModel
903
     */
904
    private static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry)
905
    {
906
        return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry);
907
    }
908
}
909