@@ -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 |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | $p->setName($name); |
| 44 | 44 | $p->setPassedByReference($param->byRef); |
| 45 | 45 | |
| 46 | - $type = null; |
|
| 46 | + $type = null; |
|
| 47 | 47 | if (is_string($param->type)) { |
| 48 | 48 | $type = $param->type; |
| 49 | 49 | } else if ($param->type instanceof Name) { |
| 50 | - $type = implode('\\', $param->type->parts); |
|
| 51 | - $qualifiedType = TypeUtils::guessQualifiedName($this->struct, $type); |
|
| 52 | - if ($type !== $qualifiedType) { |
|
| 53 | - $type = $qualifiedType; |
|
| 54 | - } else { |
|
| 55 | - $type = '\\'.$type; |
|
| 56 | - } |
|
| 57 | - } |
|
| 50 | + $type = implode('\\', $param->type->parts); |
|
| 51 | + $qualifiedType = TypeUtils::guessQualifiedName($this->struct, $type); |
|
| 52 | + if ($type !== $qualifiedType) { |
|
| 53 | + $type = $qualifiedType; |
|
| 54 | + } else { |
|
| 55 | + $type = '\\'.$type; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | if ($type) { |
| 60 | - $p->addType($type); |
|
| 61 | - } |
|
| 60 | + $p->addType($type); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | $this->parseValue($p, $param); |
| 64 | 64 | |
@@ -67,11 +67,11 @@ discard block |
||
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | 69 | if ($tag !== null) { |
| 70 | - $types = TypeUtils::expressionToTypes($tag->getType()); |
|
| 71 | - foreach ($types as $type) { |
|
| 72 | - $p->addType(TypeUtils::guessQualifiedName($this->struct, $type)); |
|
| 73 | - } |
|
| 74 | - $p->setTypeDescription($tag->getDescription()); |
|
| 70 | + $types = TypeUtils::expressionToTypes($tag->getType()); |
|
| 71 | + foreach ($types as $type) { |
|
| 72 | + $p->addType(TypeUtils::guessQualifiedName($this->struct, $type)); |
|
| 73 | + } |
|
| 74 | + $p->setTypeDescription($tag->getDescription()); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $m->addParameter($p); |
@@ -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 | |
@@ -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 |