Skip to content

Commit

Permalink
Do not generate return type for constructors and destructors
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Oct 23, 2020
1 parent e6f8fdb commit 768e6a0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
58 changes: 31 additions & 27 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,16 @@ public function getSendByString(): string {
throw new Exception("Invalid sendBy value");
}

/**
* @return SimpleType[]
*/
public function getMethodsynopsisType(): array {
return $this->type->types ?? $this->phpDocType->types;
public function getMethodsynopsisType(): Type {
if ($this->type) {
return $this->type;
}

if ($this->phpDocType) {
return $this->phpDocType;
}

throw new Exception("A parameter must have a type");
}

public function hasProperDefaultValue(): bool {
Expand Down Expand Up @@ -589,11 +594,8 @@ public function equals(ReturnInfo $other): bool {
&& Type::equals($this->type, $other->type);
}

/**
* @return SimpleType[]
*/
public function getMethodsynopsisType(): array {
return $this->type->types ?? ($this->phpDocType->types ?? [SimpleType::void()]);
public function getMethodsynopsisType(): ?Type {
return $this->type ?? $this->phpDocType;
}
}

Expand Down Expand Up @@ -1470,22 +1472,24 @@ function generateMethodsynopsis(DOMDocument $doc, FuncInfo $funcInfo): DOMElemen
$methodsynopsis->appendChild($modifierElement);
}

$types = $funcInfo->return->getMethodsynopsisType();
if (count($types) > 1) {
$typeElement = $doc->createElement('type');
$classAttribute = $doc->createAttribute('class');
$classAttribute->value = 'union';
$typeElement->appendChild($classAttribute);
$returnType = $funcInfo->return->getMethodsynopsisType();
if ($returnType) {
if (count($returnType->types) > 1) {
$typeElement = $doc->createElement('type');
$classAttribute = $doc->createAttribute('class');
$classAttribute->value = 'union';
$typeElement->appendChild($classAttribute);

foreach ($types as $type) {
$unionTypeElement = $doc->createElement('type', $type->name);
$typeElement->appendChild($unionTypeElement);
foreach ($returnType->types as $type) {
$unionTypeElement = $doc->createElement('type', $type->name);
$typeElement->appendChild($unionTypeElement);
}
} else {
$typeElement = $doc->createElement('type', $returnType->types[0]->name);
}
} else {
$typeElement = $doc->createElement('type', $types[0]->name);
}

$methodsynopsis->appendChild($typeElement);
$methodsynopsis->appendChild($typeElement);
}

$methodname = $doc->createElement('methodname', $funcInfo->name->__toString());
$methodsynopsis->appendChild($methodname);
Expand All @@ -1502,19 +1506,19 @@ function generateMethodsynopsis(DOMDocument $doc, FuncInfo $funcInfo): DOMElemen
}
$methodsynopsis->appendChild($methodparam);

$types = $arg->getMethodsynopsisType();
if (count($types) > 1) {
$paramType = $arg->getMethodsynopsisType();
if (count($paramType->types) > 1) {
$typeElement = $doc->createElement('type');
$classAttribute = $doc->createAttribute('class');
$classAttribute->value = 'union';
$typeElement->appendChild($classAttribute);

foreach ($types as $type) {
foreach ($paramType->types as $type) {
$unionTypeElement = $doc->createElement('type', $type->name);
$typeElement->appendChild($unionTypeElement);
}
} else {
$typeElement = $doc->createElement('type', $types[0]->name);
$typeElement = $doc->createElement('type', $paramType->types[0]->name);
}

$methodparam->appendChild($typeElement);
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/methodsynopses/PhpToken___construct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- PhpToken::__construct -->
<methodsynopsis>
<modifier>final</modifier><modifier>public</modifier><type>void</type><methodname>PhpToken::__construct</methodname>
<modifier>final</modifier><modifier>public</modifier><methodname>PhpToken::__construct</methodname>
<methodparam><type>int</type><parameter>id</parameter></methodparam>
<methodparam><type>string</type><parameter>text</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>line</parameter><initializer>-1</initializer></methodparam>
Expand Down

0 comments on commit 768e6a0

Please sign in to comment.