Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
GeneratorFiles
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
8 / 8
17
100.00% covered (success)
100.00%
1 / 1
 getClassmapFile
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 doGenerate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 generateStructsClasses
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 getStructFile
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 generateServicesClasses
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 generateClassMap
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 generateTutorialFile
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 generateComposerFile
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\Generator;
6
7use WsdlToPhp\PackageGenerator\File\AbstractModelFile;
8use WsdlToPhp\PackageGenerator\File\ClassMap as ClassMapFile;
9use WsdlToPhp\PackageGenerator\File\Composer as ComposerFile;
10use WsdlToPhp\PackageGenerator\File\Service as ServiceFile;
11use WsdlToPhp\PackageGenerator\File\Struct as StructFile;
12use WsdlToPhp\PackageGenerator\File\StructArray as StructArrayFile;
13use WsdlToPhp\PackageGenerator\File\StructEnum as StructEnumFile;
14use WsdlToPhp\PackageGenerator\File\Tutorial as TutorialFile;
15use WsdlToPhp\PackageGenerator\Model\EmptyModel;
16use WsdlToPhp\PackageGenerator\Model\Struct as StructModel;
17
18class GeneratorFiles extends AbstractGeneratorAware
19{
20    protected ClassMapFile $classmapFile;
21
22    public function getClassmapFile(): ClassMapFile
23    {
24        if (!isset($this->classmapFile)) {
25            $classMapModel = new EmptyModel($this->generator, 'ClassMap');
26            $classMap = new ClassMapFile($this->generator, $classMapModel->getPackagedName());
27            $classMap->setModel($classMapModel);
28            $this->classmapFile = $classMap;
29        }
30
31        return $this->classmapFile;
32    }
33
34    public function doGenerate(): GeneratorFiles
35    {
36        return $this
37            ->generateStructsClasses()
38            ->generateServicesClasses()
39            ->generateClassMap()
40            ->generateTutorialFile()
41            ->generateComposerFile()
42        ;
43    }
44
45    protected function generateStructsClasses(): GeneratorFiles
46    {
47        foreach ($this->getGenerator()->getStructs() as $struct) {
48            if (!$struct->isStruct()) {
49                continue;
50            }
51
52            $this
53                ->getStructFile($struct)
54                ->setModel($struct)
55                ->write()
56            ;
57        }
58
59        return $this;
60    }
61
62    protected function getStructFile(StructModel $struct): AbstractModelFile
63    {
64        if ($struct->isRestriction()) {
65            $file = new StructEnumFile($this->generator, $struct->getPackagedName());
66        } elseif ($struct->isArray()) {
67            $file = new StructArrayFile($this->generator, $struct->getPackagedName());
68        } else {
69            $file = new StructFile($this->generator, $struct->getPackagedName());
70        }
71
72        return $file;
73    }
74
75    protected function generateServicesClasses(): self
76    {
77        foreach ($this->getGenerator()->getServices(true) as $service) {
78            $file = new ServiceFile($this->generator, $service->getPackagedName());
79            $file->setModel($service)->write();
80        }
81
82        return $this;
83    }
84
85    protected function generateClassMap(): self
86    {
87        $this->getClassmapFile()->write();
88
89        return $this;
90    }
91
92    protected function generateTutorialFile(): self
93    {
94        if ($this->generator->getOptionGenerateTutorialFile() && $this->getClassmapFile() instanceof ClassMapFile) {
95            $tutorialFile = new TutorialFile($this->generator, 'tutorial');
96            $tutorialFile->write();
97        }
98
99        return $this;
100    }
101
102    protected function generateComposerFile(): self
103    {
104        if ($this->generator->getOptionStandalone()) {
105            $composerFile = new ComposerFile($this->generator, 'composer');
106            $composerFile->write();
107        }
108
109        return $this;
110    }
111}