|
1
|
|
|
<?php |
|
2
|
|
|
namespace gossi\codegen\generator\builder; |
|
3
|
|
|
|
|
4
|
|
|
use gossi\codegen\model\AbstractModel; |
|
5
|
|
|
use gossi\codegen\model\PhpClass; |
|
6
|
|
|
use gossi\codegen\generator\builder\parts\StructBuilderPart; |
|
7
|
|
|
|
|
8
|
|
|
class ClassBuilder extends AbstractBuilder { |
|
9
|
|
|
|
|
10
|
|
|
use StructBuilderPart; |
|
11
|
|
|
|
|
12
|
11 |
|
public function build(AbstractModel $model) { |
|
13
|
11 |
|
$this->sort($model); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
11 |
|
$this->buildHeader($model); |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
// signature |
|
18
|
11 |
|
$this->buildSignature($model); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
// body |
|
21
|
11 |
|
$this->writer->writeln(" {\n")->indent(); |
|
22
|
11 |
|
$this->buildTraits($model); |
|
|
|
|
|
|
23
|
11 |
|
$this->buildConstants($model); |
|
|
|
|
|
|
24
|
11 |
|
$this->buildProperties($model); |
|
|
|
|
|
|
25
|
11 |
|
$this->buildMethods($model); |
|
|
|
|
|
|
26
|
11 |
|
$this->writer->outdent()->rtrim()->write('}'); |
|
27
|
11 |
|
} |
|
28
|
|
|
|
|
29
|
11 |
|
private function buildSignature(PhpClass $model) { |
|
30
|
11 |
|
if ($model->isAbstract()) { |
|
31
|
2 |
|
$this->writer->write('abstract '); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
11 |
|
if ($model->isFinal()) { |
|
35
|
1 |
|
$this->writer->write('final '); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
11 |
|
$this->writer->write('class '); |
|
39
|
11 |
|
$this->writer->write($model->getName()); |
|
40
|
|
|
|
|
41
|
11 |
|
if ($parentClassName = $model->getParentClassName()) { |
|
42
|
1 |
|
$this->writer->write(' extends ' . $parentClassName); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
11 |
|
if ($model->hasInterfaces()) { |
|
46
|
1 |
|
$this->writer->write(' implements '); |
|
47
|
1 |
|
$this->writer->write(implode(', ', $model->getInterfaces()->toArray())); |
|
48
|
|
|
} |
|
49
|
11 |
|
} |
|
50
|
|
|
|
|
51
|
11 |
|
private function sort(PhpClass $model) { |
|
52
|
11 |
|
$this->sortUseStatements($model); |
|
53
|
11 |
|
$this->sortConstants($model); |
|
54
|
11 |
|
$this->sortProperties($model); |
|
55
|
11 |
|
$this->sortMethods($model); |
|
56
|
11 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.