@@ -33,8 +33,8 @@ |
||
33 | 33 | $description = implode("\n", $description); |
34 | 34 | } |
35 | 35 | if ($description) { |
36 | - $this->description = $description; |
|
37 | - } |
|
36 | + $this->description = $description; |
|
37 | + } |
|
38 | 38 | return $this; |
39 | 39 | } |
40 | 40 |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace gossi\codegen\model; |
4 | 4 | |
5 | -interface PhpTypeInterface extends NamespaceInterface |
|
6 | -{ |
|
5 | +interface PhpTypeInterface extends NamespaceInterface { |
|
7 | 6 | public function getName(): ?string; |
8 | 7 | |
9 | 8 | public function getQualifiedName(): ?string; |
@@ -4,12 +4,24 @@ |
||
4 | 4 | |
5 | 5 | interface PhpTypeInterface extends NamespaceInterface |
6 | 6 | { |
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
7 | 10 | public function getName(): ?string; |
8 | 11 | |
12 | + /** |
|
13 | + * @return string |
|
14 | + */ |
|
9 | 15 | public function getQualifiedName(): ?string; |
10 | 16 | |
17 | + /** |
|
18 | + * @return parts\NamePart |
|
19 | + */ |
|
11 | 20 | public function setName(?string $name); |
12 | 21 | |
22 | + /** |
|
23 | + * @return parts\QualifiedNamePart |
|
24 | + */ |
|
13 | 25 | public function setQualifiedName(?string $qualifiedName); |
14 | 26 | |
15 | 27 | public function __toString(): string; |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | interface PhpTypeInterface extends NamespaceInterface |
6 | 6 | { |
7 | - public function getName(): ?string; |
|
7 | + public function getName(): ?string; |
|
8 | 8 | |
9 | - public function getQualifiedName(): ?string; |
|
9 | + public function getQualifiedName(): ?string; |
|
10 | 10 | |
11 | - public function setName(?string $name); |
|
11 | + public function setName(?string $name); |
|
12 | 12 | |
13 | - public function setQualifiedName(?string $qualifiedName); |
|
13 | + public function setQualifiedName(?string $qualifiedName); |
|
14 | 14 | |
15 | - public function __toString(): string; |
|
15 | + public function __toString(): string; |
|
16 | 16 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function __construct($name = null) { |
57 | 57 | $this->setName($name); |
58 | - $this->initTypes(); |
|
59 | - } |
|
58 | + $this->initTypes(); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Sets whether this parameter is passed by reference |
@@ -85,16 +85,16 @@ discard block |
||
85 | 85 | * @return ParamTag |
86 | 86 | */ |
87 | 87 | public function getDocblockTag(): ParamTag { |
88 | - $type = ''; |
|
89 | - if ($this->getNullable()) { |
|
90 | - $type = 'null'; |
|
91 | - } |
|
92 | - if ($this->getTypes()) { |
|
93 | - if ($type) { |
|
94 | - $type .= '|'; |
|
95 | - } |
|
96 | - $type .= TypeUtils::typesToExpression($this->getTypes()); |
|
97 | - } |
|
88 | + $type = ''; |
|
89 | + if ($this->getNullable()) { |
|
90 | + $type = 'null'; |
|
91 | + } |
|
92 | + if ($this->getTypes()) { |
|
93 | + if ($type) { |
|
94 | + $type .= '|'; |
|
95 | + } |
|
96 | + $type .= TypeUtils::typesToExpression($this->getTypes()); |
|
97 | + } |
|
98 | 98 | return ParamTag::create() |
99 | 99 | ->setType($type) |
100 | 100 | ->setVariable($this->getName()) |
@@ -53,12 +53,12 @@ |
||
53 | 53 | $property->setParent($this); |
54 | 54 | $types = $property->getTypes(); |
55 | 55 | |
56 | - if ($types) { |
|
57 | - foreach ($types as $type) { |
|
58 | - $this->addUseStatement($type); |
|
59 | - $property->addType($type); |
|
60 | - } |
|
61 | - } |
|
56 | + if ($types) { |
|
57 | + foreach ($types as $type) { |
|
58 | + $this->addUseStatement($type); |
|
59 | + $property->addType($type); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | $this->properties->set($property->getName(), $property); |
64 | 64 |
@@ -78,19 +78,19 @@ |
||
78 | 78 | return $this->interfaces; |
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * @return iterable|PhpInterface[] |
|
83 | - */ |
|
84 | - public function getPhpInterfaces(): iterable |
|
85 | - { |
|
86 | - $interfaces = []; |
|
87 | - foreach ($this->interfaces as $interface) { |
|
88 | - $interfaces[] = interface_exists($interface) ? |
|
89 | - PhpInterface::fromName($interface) : PhpInterface::create($interface); |
|
90 | - } |
|
91 | - |
|
92 | - return $interfaces; |
|
93 | - } |
|
81 | + /** |
|
82 | + * @return iterable|PhpInterface[] |
|
83 | + */ |
|
84 | + public function getPhpInterfaces(): iterable |
|
85 | + { |
|
86 | + $interfaces = []; |
|
87 | + foreach ($this->interfaces as $interface) { |
|
88 | + $interfaces[] = interface_exists($interface) ? |
|
89 | + PhpInterface::fromName($interface) : PhpInterface::create($interface); |
|
90 | + } |
|
91 | + |
|
92 | + return $interfaces; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Checks whether interfaces exists |
@@ -75,18 +75,18 @@ |
||
75 | 75 | return $this->traits; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * @return iterable|PhpTrait[] |
|
80 | - */ |
|
81 | - public function getPhpTraits(): iterable { |
|
82 | - $traits = []; |
|
83 | - foreach ($this->traits as $trait) { |
|
84 | - $traits[] = trait_exists($trait) ? |
|
85 | - PhpTrait::fromName($trait) : PhpTrait::create($trait); |
|
86 | - } |
|
87 | - |
|
88 | - return $traits; |
|
89 | - } |
|
78 | + /** |
|
79 | + * @return iterable|PhpTrait[] |
|
80 | + */ |
|
81 | + public function getPhpTraits(): iterable { |
|
82 | + $traits = []; |
|
83 | + foreach ($this->traits as $trait) { |
|
84 | + $traits[] = trait_exists($trait) ? |
|
85 | + PhpTrait::fromName($trait) : PhpTrait::create($trait); |
|
86 | + } |
|
87 | + |
|
88 | + return $traits; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Checks whether a trait exists |
@@ -52,7 +52,7 @@ |
||
52 | 52 | if ($type !== $qualifiedType) { |
53 | 53 | $type = $qualifiedType; |
54 | 54 | } else { |
55 | - $type = '\\'.$type; |
|
55 | + $type = '\\' . $type; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 |
@@ -45,47 +45,47 @@ |
||
45 | 45 | $p->setName($name); |
46 | 46 | $p->setPassedByReference($param->byRef); |
47 | 47 | |
48 | - $type = null; |
|
49 | - if ($param->type instanceof NullableType) { |
|
50 | - $param->type = $param->type->type; |
|
51 | - $p->setNullable(true); |
|
52 | - } |
|
53 | - if ($param->type instanceof Identifier) { |
|
54 | - $param->type = $param->type->name; |
|
55 | - } |
|
56 | - if (is_string($param->type)) { |
|
48 | + $type = null; |
|
49 | + if ($param->type instanceof NullableType) { |
|
50 | + $param->type = $param->type->type; |
|
51 | + $p->setNullable(true); |
|
52 | + } |
|
53 | + if ($param->type instanceof Identifier) { |
|
54 | + $param->type = $param->type->name; |
|
55 | + } |
|
56 | + if (is_string($param->type)) { |
|
57 | 57 | $type = $param->type; |
58 | 58 | } |
59 | 59 | if ($param->type instanceof Name) { |
60 | - $type = implode('\\', $param->type->parts); |
|
61 | - $qualifiedType = TypeUtils::guessQualifiedName($this->struct, $type); |
|
62 | - if ($type !== $qualifiedType) { |
|
63 | - $type = $qualifiedType; |
|
64 | - } else { |
|
65 | - $type = '\\'.$type; |
|
66 | - } |
|
67 | - } |
|
60 | + $type = implode('\\', $param->type->parts); |
|
61 | + $qualifiedType = TypeUtils::guessQualifiedName($this->struct, $type); |
|
62 | + if ($type !== $qualifiedType) { |
|
63 | + $type = $qualifiedType; |
|
64 | + } else { |
|
65 | + $type = '\\'.$type; |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | if ($type) { |
70 | - $p->addType($type); |
|
71 | - } |
|
70 | + $p->addType($type); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | $this->parseValue($p, $param); |
74 | 74 | |
75 | 75 | if ($p->getExpression() === 'null') { |
76 | - $p->setNullable(true); |
|
77 | - } |
|
76 | + $p->setNullable(true); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | $tag = $params->find($p, static function (ParamTag $t, $p) { |
80 | 80 | return $t->getVariable() === '$' . $p->getName(); |
81 | 81 | }); |
82 | 82 | |
83 | 83 | if ($tag !== null) { |
84 | - $types = TypeUtils::expressionToTypes($tag->getType()); |
|
85 | - foreach ($types as $type) { |
|
86 | - $p->addType(TypeUtils::guessQualifiedName($this->struct, $type)); |
|
87 | - } |
|
88 | - $p->setTypeDescription($tag->getDescription()); |
|
84 | + $types = TypeUtils::expressionToTypes($tag->getType()); |
|
85 | + foreach ($types as $type) { |
|
86 | + $p->addType(TypeUtils::guessQualifiedName($this->struct, $type)); |
|
87 | + } |
|
88 | + $p->setTypeDescription($tag->getDescription()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $m->addParameter($p); |
@@ -24,12 +24,12 @@ |
||
24 | 24 | $vars = $docblock->getTags('var'); |
25 | 25 | if ($vars->size() > 0) { |
26 | 26 | $var = $vars->get(0); |
27 | - $types = TypeUtils::expressionToTypes($var->getType()); |
|
28 | - foreach($types as $type) { |
|
29 | - $type = TypeUtils::guessQualifiedName($this->struct, $type); |
|
30 | - $member->addType($type); |
|
31 | - } |
|
32 | - $member->setTypeDescription($var->getDescription()); |
|
27 | + $types = TypeUtils::expressionToTypes($var->getType()); |
|
28 | + foreach($types as $type) { |
|
29 | + $type = TypeUtils::guessQualifiedName($this->struct, $type); |
|
30 | + $member->addType($type); |
|
31 | + } |
|
32 | + $member->setTypeDescription($var->getDescription()); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | if ($vars->size() > 0) { |
26 | 26 | $var = $vars->get(0); |
27 | 27 | $types = TypeUtils::expressionToTypes($var->getType()); |
28 | - foreach($types as $type) { |
|
28 | + foreach ($types as $type) { |
|
29 | 29 | $type = TypeUtils::guessQualifiedName($this->struct, $type); |
30 | 30 | $member->addType($type); |
31 | 31 | } |
@@ -34,7 +34,6 @@ discard block |
||
34 | 34 | * Sets the type |
35 | 35 | * |
36 | 36 | * @param null|Map|string[]|PhpTypeInterface[] $types |
37 | - * @param string $description |
|
38 | 37 | * |
39 | 38 | * @return $this |
40 | 39 | */ |
@@ -54,7 +53,6 @@ discard block |
||
54 | 53 | * adds a type |
55 | 54 | * |
56 | 55 | * @param string|PhpTypeInterface $type |
57 | - * @param string $description |
|
58 | 56 | * @return $this |
59 | 57 | */ |
60 | 58 | public function addType($type) { |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | private $typeNullable = false; |
28 | 28 | |
29 | 29 | public function initTypes(): void { |
30 | - $this->types = new Map(); |
|
31 | - } |
|
30 | + $this->types = new Map(); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Sets the type |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return $this |
40 | 40 | */ |
41 | - public function setTypes(?iterable $types) { |
|
42 | - if (!$types) { |
|
43 | - return $this; |
|
44 | - } |
|
45 | - $this->types->clear(); |
|
46 | - foreach ($types as $type) { |
|
47 | - $this->addType($type); |
|
48 | - } |
|
49 | - |
|
50 | - return $this; |
|
41 | + public function setTypes(?iterable $types) { |
|
42 | + if (!$types) { |
|
43 | + return $this; |
|
44 | + } |
|
45 | + $this->types->clear(); |
|
46 | + foreach ($types as $type) { |
|
47 | + $this->addType($type); |
|
48 | + } |
|
49 | + |
|
50 | + return $this; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | * @return $this |
59 | 59 | */ |
60 | 60 | public function addType($type) { |
61 | - if ($type === 'null') { |
|
62 | - $this->setNullable(true); |
|
63 | - return $this; |
|
64 | - } |
|
65 | - if ($type) { |
|
66 | - if (!$type instanceof PhpTypeInterface) { |
|
67 | - $type = new PhpType($type); |
|
68 | - } |
|
69 | - |
|
70 | - $this->types->set($type->getQualifiedName(), $type); |
|
71 | - } |
|
61 | + if ($type === 'null') { |
|
62 | + $this->setNullable(true); |
|
63 | + return $this; |
|
64 | + } |
|
65 | + if ($type) { |
|
66 | + if (!$type instanceof PhpTypeInterface) { |
|
67 | + $type = new PhpType($type); |
|
68 | + } |
|
69 | + |
|
70 | + $this->types->set($type->getQualifiedName(), $type); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | return $this; |
74 | 74 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @return $this |
81 | 81 | */ |
82 | 82 | public function setTypeDescription(string $description) { |
83 | - if (!$description) { |
|
84 | - return $this; |
|
85 | - } |
|
83 | + if (!$description) { |
|
84 | + return $this; |
|
85 | + } |
|
86 | 86 | $this->typeDescription = $description; |
87 | 87 | return $this; |
88 | 88 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function getTypeExpression(): ?string { |
100 | - return TypeUtils::typesToExpression($this->types); |
|
101 | - } |
|
100 | + return TypeUtils::typesToExpression($this->types); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Returns the type description |