Completed
Push — master ( b00023...d35b53 )
by Francis
04:02 queued 11s
created

ClassGenerator::setExtendClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Prometee\SwaggerClientGenerator\Base\Generator;
6
7
use Prometee\SwaggerClientGenerator\Base\Generator\Other\MethodsGeneratorInterface;
8
use Prometee\SwaggerClientGenerator\Base\Generator\Other\PropertiesGeneratorInterface;
9
use Prometee\SwaggerClientGenerator\Base\Generator\Other\TraitsGeneratorInterface;
10
use Prometee\SwaggerClientGenerator\Base\Generator\Other\UsesGeneratorInterface;
11
use Prometee\SwaggerClientGenerator\Base\View\ClassViewInterface;
12
13
class ClassGenerator extends AbstractGenerator implements ClassGeneratorInterface
14
{
15
    /** @var UsesGeneratorInterface */
16
    protected $usesGenerator;
17
    /** @var PropertiesGeneratorInterface */
18
    protected $propertiesGenerator;
19
    /** @var MethodsGeneratorInterface */
20
    protected $methodsGenerator;
21
    /** @var TraitsGeneratorInterface */
22
    protected $traitsGenerator;
23
24
    /** @var string */
25
    protected $generatorType = 'class';
26
    /** @var string */
27
    protected $namespace;
28
    /** @var string */
29
    protected $className;
30
    /** @var string|null */
31
    protected $extendClassName;
32
    /** @var string[] */
33
    protected $implements;
34
35
    /**
36
     * @param ClassViewInterface $classView
37
     * @param UsesGeneratorInterface $usesGenerator
38
     * @param PropertiesGeneratorInterface $propertiesGenerator
39
     * @param MethodsGeneratorInterface $methodsGenerator
40
     * @param TraitsGeneratorInterface $traitsGenerator
41
     */
42
    public function __construct(
43
        ClassViewInterface $classView,
44
        UsesGeneratorInterface $usesGenerator,
45
        PropertiesGeneratorInterface $propertiesGenerator,
46
        MethodsGeneratorInterface $methodsGenerator,
47
        TraitsGeneratorInterface $traitsGenerator
48
    )
49
    {
50
        $this->setView($classView);
51
        $this->usesGenerator = $usesGenerator;
52
        $this->propertiesGenerator = $propertiesGenerator;
53
        $this->methodsGenerator = $methodsGenerator;
54
        $this->traitsGenerator = $traitsGenerator;
55
    }
56
57
    /**
58
     * @param string $namespace
59
     * @param string $className
60
     * @param string|null $extendClass
61
     * @param string[] $implements
62
     */
63
    public function configure(
64
        string $namespace,
65
        string $className,
66
        ?string $extendClass = null,
67
        array $implements = []
68
    )
69
    {
70
        $this->setNamespace($namespace);
71
        $this->setClassName($className);
72
        $this->setExtendClass($extendClass);
73
        $this->setImplements($implements);
74
75
        $this->usesGenerator->configure($this->namespace);
76
        $this->traitsGenerator->configure($this->usesGenerator);
77
        $this->propertiesGenerator->configure($this->usesGenerator);
78
        $this->methodsGenerator->configure($this->usesGenerator);
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function getNamespace(): string
85
    {
86
        return $this->namespace;
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    public function setNamespace(string $namespace): void
93
    {
94
        $this->namespace = $namespace;
95
    }
96
97
    /**
98
     * {@inheritDoc}
99
     */
100
    public function getUsesGenerator(): UsesGeneratorInterface
101
    {
102
        return $this->usesGenerator;
103
    }
104
105
    /**
106
     * {@inheritDoc}
107
     */
108
    public function setUsesGenerator(UsesGeneratorInterface $usesGenerator): void
109
    {
110
        $this->usesGenerator = $usesGenerator;
111
    }
112
113
    /**
114
     * {@inheritDoc}
115
     */
116
    public function getClassName(): string
117
    {
118
        return $this->className;
119
    }
120
121
    /**
122
     * {@inheritDoc}
123
     */
124
    public function setClassName(string $className): void
125
    {
126
        $this->className = $className;
127
    }
128
129
    /**
130
     * {@inheritDoc}
131
     */
132
    public function getGeneratorType(): string
133
    {
134
        return $this->generatorType;
135
    }
136
137
    /**
138
     * {@inheritDoc}
139
     */
140
    public function getTraitsGenerator(): TraitsGeneratorInterface
141
    {
142
        return $this->traitsGenerator;
143
    }
144
145
    /**
146
     * {@inheritDoc}
147
     */
148
    public function setTraitsGenerator(TraitsGeneratorInterface $traitsGenerator): void
149
    {
150
        $this->traitsGenerator = $traitsGenerator;
151
    }
152
153
    /**
154
     * {@inheritDoc}
155
     */
156
    public function getExtendClassName(): ?string
157
    {
158
        return $this->extendClassName;
159
    }
160
161
    /**
162
     * {@inheritDoc}
163
     */
164
    public function setExtendClassName(?string $extendClassName): void
165
    {
166
        $this->extendClassName = $extendClassName;
167
    }
168
169
    /**
170
     * {@inheritDoc}
171
     */
172
    public function setExtendClass(?string $extendClass): void
173
    {
174
        if (null === $extendClass) {
175
            $this->extendClassName = null;
176
            return;
177
        }
178
179
        $this->usesGenerator->guessUse($extendClass);
180
        $extendClassName = $this->usesGenerator->getInternalUseName($extendClass);
181
        $this->setExtendClassName($extendClassName);
182
    }
183
184
    /**
185
     * {@inheritDoc}
186
     */
187
    public function getImplements(): array
188
    {
189
        return $this->implements;
190
    }
191
192
    /**
193
     * {@inheritDoc}
194
     */
195
    public function setImplements(array $implements): void
196
    {
197
        $internalImplements = [];
198
        foreach ($implements as $implement) {
199
            $this->usesGenerator->guessUse($implement);
200
            $internalImplements[] = $this->usesGenerator->getInternalUseName($implement);
201
        }
202
        $this->implements = $internalImplements;
203
    }
204
205
    /**
206
     * {@inheritDoc}
207
     */
208
    public function getPropertiesGenerator(): PropertiesGeneratorInterface
209
    {
210
        return $this->propertiesGenerator;
211
    }
212
213
    /**
214
     * {@inheritDoc}
215
     */
216
    public function setPropertiesGenerator(PropertiesGeneratorInterface $propertiesGenerator): void
217
    {
218
        $this->propertiesGenerator = $propertiesGenerator;
219
    }
220
221
    /**
222
     * {@inheritDoc}
223
     */
224
    public function getMethodsGenerator(): MethodsGeneratorInterface
225
    {
226
        return $this->methodsGenerator;
227
    }
228
229
    /**
230
     * {@inheritDoc}
231
     */
232
    public function setMethodsGenerator(MethodsGeneratorInterface $methodsGenerator): void
233
    {
234
        $this->methodsGenerator = $methodsGenerator;
235
    }
236
}
237