@@ -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,20 +58,20 @@ 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 | - if (substr($type, -2, 2) === '[]') { |
|
68 | - $this->addType('iterable'); |
|
69 | - } |
|
70 | - $type = new PhpType($type); |
|
71 | - } |
|
72 | - |
|
73 | - $this->types->set($type->getQualifiedName(), $type); |
|
74 | - } |
|
61 | + if ($type === 'null') { |
|
62 | + $this->setNullable(true); |
|
63 | + return $this; |
|
64 | + } |
|
65 | + if ($type) { |
|
66 | + if (!$type instanceof PhpTypeInterface) { |
|
67 | + if (substr($type, -2, 2) === '[]') { |
|
68 | + $this->addType('iterable'); |
|
69 | + } |
|
70 | + $type = new PhpType($type); |
|
71 | + } |
|
72 | + |
|
73 | + $this->types->set($type->getQualifiedName(), $type); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | return $this; |
77 | 77 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @return $this |
84 | 84 | */ |
85 | 85 | public function setTypeDescription(string $description) { |
86 | - if (!$description) { |
|
87 | - return $this; |
|
88 | - } |
|
86 | + if (!$description) { |
|
87 | + return $this; |
|
88 | + } |
|
89 | 89 | $this->typeDescription = $description; |
90 | 90 | return $this; |
91 | 91 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | public function getTypeExpression(): ?string { |
103 | - return TypeUtils::typesToExpression($this->types); |
|
104 | - } |
|
103 | + return TypeUtils::typesToExpression($this->types); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * Returns the type description |
@@ -6,10 +6,10 @@ |
||
6 | 6 | |
7 | 7 | class PhpType implements PhpTypeInterface |
8 | 8 | { |
9 | - use QualifiedNamePart; |
|
9 | + use QualifiedNamePart; |
|
10 | 10 | |
11 | - public function __construct($qualifiedName) |
|
12 | - { |
|
13 | - $this->setQualifiedName($qualifiedName); |
|
14 | - } |
|
11 | + public function __construct($qualifiedName) |
|
12 | + { |
|
13 | + $this->setQualifiedName($qualifiedName); |
|
14 | + } |
|
15 | 15 | } |
@@ -4,12 +4,10 @@ |
||
4 | 4 | |
5 | 5 | use gossi\codegen\model\parts\QualifiedNamePart; |
6 | 6 | |
7 | -class PhpType implements PhpTypeInterface |
|
8 | -{ |
|
7 | +class PhpType implements PhpTypeInterface { |
|
9 | 8 | use QualifiedNamePart; |
10 | 9 | |
11 | - public function __construct($qualifiedName) |
|
12 | - { |
|
10 | + public function __construct($qualifiedName) { |
|
13 | 11 | $this->setQualifiedName($qualifiedName); |
14 | 12 | } |
15 | 13 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function addSimpleDescParameter(string $name, $types = null, string $typeDescription = null, $defaultValue = null) { |
105 | 105 | $types = (array)$types; |
106 | - $parameter = new PhpParameter($name); |
|
106 | + $parameter = new PhpParameter($name); |
|
107 | 107 | $parameter->setTypes($types); |
108 | 108 | $parameter->setTypeDescription($typeDescription); |
109 | 109 | |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | $docblock = $this->getDocblock(); |
219 | 219 | $tags = $docblock->getTags('param'); |
220 | 220 | foreach ($this->parameters as $param) { |
221 | - if (!empty($noTypeHint[$param->getName()])) { |
|
222 | - continue; |
|
223 | - } |
|
221 | + if (!empty($noTypeHint[$param->getName()])) { |
|
222 | + continue; |
|
223 | + } |
|
224 | 224 | $ptag = $param->getDocblockTag(); |
225 | 225 | |
226 | 226 | $tag = $tags->find($ptag, function (ParamTag $tag, ParamTag $ptag) { |
@@ -102,7 +102,7 @@ |
||
102 | 102 | * @return $this |
103 | 103 | */ |
104 | 104 | public function addSimpleDescParameter(string $name, $types = null, string $typeDescription = null, $defaultValue = null) { |
105 | - $types = (array)$types; |
|
105 | + $types = (array) $types; |
|
106 | 106 | $parameter = new PhpParameter($name); |
107 | 107 | $parameter->setTypes($types); |
108 | 108 | $parameter->setTypeDescription($typeDescription); |
@@ -33,10 +33,10 @@ |
||
33 | 33 | if ($this->isPrimitive($value)) { |
34 | 34 | $obj->setValue($this->getPrimitiveValue($value)); |
35 | 35 | } |
36 | - $expr = $this->getExpression($value); |
|
37 | - if ($expr) { |
|
38 | - $obj->setExpression($expr); |
|
39 | - } |
|
36 | + $expr = $this->getExpression($value); |
|
37 | + if ($expr) { |
|
38 | + $obj->setExpression($expr); |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 |
@@ -78,8 +78,8 @@ |
||
78 | 78 | return $this->name; |
79 | 79 | } |
80 | 80 | |
81 | - public function __toString(): string |
|
82 | - { |
|
83 | - return (string) $this->getName(); |
|
84 | - } |
|
81 | + public function __toString(): string |
|
82 | + { |
|
83 | + return (string) $this->getName(); |
|
84 | + } |
|
85 | 85 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | return new static($name); |
58 | 58 | } |
59 | 59 | |
60 | - public static function fromName(string $name): self |
|
61 | - { |
|
62 | - $ref = new \ReflectionClass($name); |
|
60 | + public static function fromName(string $name): self |
|
61 | + { |
|
62 | + $ref = new \ReflectionClass($name); |
|
63 | 63 | |
64 | - return static::fromFile($ref->getFileName()); |
|
65 | - } |
|
64 | + return static::fromFile($ref->getFileName()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * Creates a new struct |
@@ -135,17 +135,17 @@ discard block |
||
135 | 135 | * @return $this |
136 | 136 | */ |
137 | 137 | public function addUseStatement($qualifiedName, string $alias = null) { |
138 | - if ($qualifiedName instanceof PhpTypeInterface) { |
|
139 | - $qualifiedName = $qualifiedName->getQualifiedName(); |
|
140 | - } |
|
138 | + if ($qualifiedName instanceof PhpTypeInterface) { |
|
139 | + $qualifiedName = $qualifiedName->getQualifiedName(); |
|
140 | + } |
|
141 | 141 | |
142 | - if (TypeUtils::isGlobalQualifiedName($qualifiedName) || TypeUtils::isNativeType($qualifiedName)) { |
|
143 | - return $this; |
|
144 | - } |
|
142 | + if (TypeUtils::isGlobalQualifiedName($qualifiedName) || TypeUtils::isNativeType($qualifiedName)) { |
|
143 | + return $this; |
|
144 | + } |
|
145 | 145 | |
146 | - if (preg_replace('#\\\\[^\\\\]+$#', '', $qualifiedName) === $this->getNamespace()) { |
|
147 | - return $this; |
|
148 | - } |
|
146 | + if (preg_replace('#\\\\[^\\\\]+$#', '', $qualifiedName) === $this->getNamespace()) { |
|
147 | + return $this; |
|
148 | + } |
|
149 | 149 | |
150 | 150 | if (!is_string($alias)) { |
151 | 151 | if (false === strpos($qualifiedName, '\\')) { |
@@ -273,24 +273,24 @@ discard block |
||
273 | 273 | $method->setParent($this); |
274 | 274 | $this->methods->set($method->getName(), $method); |
275 | 275 | $types = $method->getTypes(); |
276 | - if ($types) { |
|
277 | - foreach ($types as $type) { |
|
278 | - $this->addUseStatement($type); |
|
279 | - $method->addType($type); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - foreach ($method->getParameters() as $parameter) { |
|
284 | - $types = $parameter->getTypes(); |
|
285 | - if ($types) { |
|
286 | - foreach ($types as $type) { |
|
287 | - $this->addUseStatement($type); |
|
288 | - $parameter->addType($type); |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - return $this; |
|
276 | + if ($types) { |
|
277 | + foreach ($types as $type) { |
|
278 | + $this->addUseStatement($type); |
|
279 | + $method->addType($type); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + foreach ($method->getParameters() as $parameter) { |
|
284 | + $types = $parameter->getTypes(); |
|
285 | + if ($types) { |
|
286 | + foreach ($types as $type) { |
|
287 | + $this->addUseStatement($type); |
|
288 | + $parameter->addType($type); |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + return $this; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |