Passed
Push — feature/issue-264 ( 16c0d2 )
by Mikaël
31:40 queued 28:41
created

Generator::getFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

927
            $wsdl->addSchema(new Schema($wsdl->getGenerator(), $schemaLocation, /** @scrutinizer ignore-type */ $this->getUrlContent($schemaLocation)));
Loading history...
928
        }
929
930 66
        return $this;
931
    }
932
933 156
    public function getServiceName(string $methodName): string
934
    {
935 156
        return ucfirst($this->getGather(new EmptyModel($this, $methodName)));
936
    }
937
938 416
    public function getOptions(): ?GeneratorOptions
939
    {
940 416
        return $this->options;
941
    }
942
943 132
    public function getSoapClient(): GeneratorSoapClient
944
    {
945 132
        return $this->soapClient;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->soapClient could return the type null which is incompatible with the type-hinted return WsdlToPhp\PackageGenerat...tor\GeneratorSoapClient. Consider adding an additional type-check to rule them out.
Loading history...
946
    }
947
948 450
    public function getUrlContent(string $url): ?string
949
    {
950 450
        if (false !== mb_strpos($url, '://')) {
951 4
            $content = Utils::getContentFromUrl($url, $this->getOptionBasicLogin(), $this->getOptionBasicPassword(), $this->getOptionProxyHost(), $this->getOptionProxyPort(), $this->getOptionProxyLogin(), $this->getOptionProxyPassword(), $this->getSoapClient()->getSoapClientStreamContextOptions());
952 4
            if ($this->getOptionSchemasSave()) {
953 2
                Utils::saveSchemas($this->getOptionDestination(), $this->getOptionSchemasFolder(), $url, $content);
954
            }
955
956 4
            return $content;
957
        }
958 446
        if (is_file($url)) {
959 444
            return file_get_contents($url);
960
        }
961
962 2
        return null;
963
    }
964
965 202
    public function getContainers(): GeneratorContainers
966
    {
967 202
        return $this->containers;
968
    }
969
970 2
    public function jsonSerialize(): array
971
    {
972
        return [
973 2
            'containers' => $this->containers,
974 2
            'options' => $this->options,
975
        ];
976
    }
977
978 204
    public static function instanceFromSerializedJson(string $json): Generator
979
    {
980 204
        $decodedJson = json_decode($json, true);
981 204
        if (JSON_ERROR_NONE === json_last_error()) {
982
            // load options first
983 202
            $options = GeneratorOptions::instance();
984 202
            foreach ($decodedJson['options'] as $name => $value) {
985 202
                $options->setOptionValue($name, $value);
0 ignored issues
show
Bug introduced by
The method setOptionValue() does not exist on WsdlToPhp\PackageGenerat...ader\AbstractYamlReader. It seems like you code against a sub-type of WsdlToPhp\PackageGenerat...ader\AbstractYamlReader such as WsdlToPhp\PackageGenerat...Reader\GeneratorOptions. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

985
                $options->/** @scrutinizer ignore-call */ 
986
                          setOptionValue($name, $value);
Loading history...
986
            }
987
            // create generator instance with options
988 202
            $instance = new self($options);
989
            // load services
990 202
            foreach ($decodedJson['containers']['services'] as $service) {
991 202
                $instance->getContainers()->getServices()->add(self::getModelInstanceFromJsonArrayEntry($instance, $service));
992
            }
993
            // load structs
994 202
            foreach ($decodedJson['containers']['structs'] as $struct) {
995 202
                $instance->getContainers()->getStructs()->add(self::getModelInstanceFromJsonArrayEntry($instance, $struct));
996
            }
997
        } else {
998 2
            throw new InvalidArgumentException(sprintf('Json is invalid, please check error %s', json_last_error()));
999
        }
1000
1001 202
        return $instance;
1002
    }
1003
1004 448
    protected function initialize(): self
1005
    {
1006
        return $this
1007 448
            ->initContainers()
1008 448
            ->initParsers()
1009 448
            ->initFiles()
1010 448
            ->initSoapClient()
1011 444
            ->initWsdl()
1012
        ;
1013
    }
1014
1015 448
    protected function initSoapClient(): self
1016
    {
1017 448
        if (!isset($this->soapClient)) {
1018 448
            $this->soapClient = new GeneratorSoapClient($this);
1019
        }
1020
1021 444
        return $this;
1022
    }
1023
1024 448
    protected function initContainers(): self
1025
    {
1026 448
        if (!isset($this->containers)) {
1027 448
            $this->containers = new GeneratorContainers($this);
1028
        }
1029
1030 448
        return $this;
1031
    }
1032
1033 448
    protected function initParsers(): self
1034
    {
1035 448
        if (!isset($this->parsers)) {
1036 448
            $this->parsers = new GeneratorParsers($this);
1037
        }
1038
1039 448
        return $this;
1040
    }
1041
1042 448
    protected function initFiles(): self
1043
    {
1044 448
        if (!isset($this->files)) {
1045 448
            $this->files = new GeneratorFiles($this);
1046
        }
1047
1048 448
        return $this;
1049
    }
1050
1051 12
    protected function initDirectory(): self
1052
    {
1053 12
        Utils::createDirectory($this->getOptions()->getDestination());
1054 12
        if (!is_writable($this->getOptionDestination())) {
1055
            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__);
1056
        }
1057
1058 12
        return $this;
1059
    }
1060
1061 446
    protected function initWsdl(): self
1062
    {
1063 446
        $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), $this->getUrlContent($this->getOptionOrigin())));
0 ignored issues
show
Bug introduced by
It seems like $this->getUrlContent($this->getOptionOrigin()) can also be of type null; however, parameter $content of WsdlToPhp\PackageGenerat...del\Wsdl::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1063
        $this->setWsdl(new Wsdl($this, $this->getOptionOrigin(), /** @scrutinizer ignore-type */ $this->getUrlContent($this->getOptionOrigin())));
Loading history...
1064
1065 446
        return $this;
1066
    }
1067
1068 16
    protected function doSanityChecks(): self
1069
    {
1070 16
        $destination = $this->getOptionDestination();
1071 16
        if (empty($destination)) {
1072 2
            throw new InvalidArgumentException('Package\'s destination must be defined', __LINE__);
1073
        }
1074
1075 14
        $composerName = $this->getOptionComposerName();
1076 14
        if ($this->getOptionStandalone() && empty($composerName)) {
1077 2
            throw new InvalidArgumentException('Package\'s composer name must be defined', __LINE__);
1078
        }
1079
1080 12
        return $this;
1081
    }
1082
1083 14
    protected function doParse(): self
1084
    {
1085 14
        $this->parsers->doParse();
1086
1087 14
        return $this;
1088
    }
1089
1090 12
    protected function doGenerate(): self
1091
    {
1092 12
        $this->files->doGenerate();
1093
1094 12
        return $this;
1095
    }
1096
1097 446
    protected function setWsdl(Wsdl $wsdl): self
1098
    {
1099 446
        $this->wsdl = $wsdl;
1100
1101 446
        return $this;
1102
    }
1103
1104 156
    protected function getGather(AbstractModel $model): string
1105
    {
1106 156
        return Utils::getPart($this->getOptionGatherMethods(), $model->getCleanName());
1107
    }
1108
1109 448
    protected function setOptions(GeneratorOptions $options): self
1110
    {
1111 448
        $this->options = $options;
1112
1113 448
        return $this;
1114
    }
1115
1116 202
    protected static function getModelInstanceFromJsonArrayEntry(Generator $generator, array $jsonArrayEntry): AbstractModel
1117
    {
1118 202
        return AbstractModel::instanceFromSerializedJson($generator, $jsonArrayEntry);
1119
    }
1120
}
1121