Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #312 - Fix getter return type #313

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/File/AbstractModelFile.php
Original file line number Diff line number Diff line change
@@ -400,7 +400,12 @@ protected function getStructAttributeTypeGetAnnotation(StructAttributeModel $att
return '\\DOMDocument|string|null';
}

return sprintf('%s%s%s', $this->getStructAttributeTypeAsPhpType($attribute, false), $this->useBrackets($attribute, $returnArrayType) ? '[]' : '', !$nullableItemType && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null');
return sprintf(
'%s%s%s',
$this->getStructAttributeTypeAsPhpType($attribute, false),
$this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
!$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
);
}

protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $attribute, bool $returnArrayType = true, bool $itemType = false): string
@@ -413,7 +418,11 @@ protected function getStructAttributeTypeSetAnnotation(StructAttributeModel $att
return 'array|string';
}

return sprintf('%s%s', $this->getStructAttributeTypeAsPhpType($attribute, $returnArrayType), $this->useBrackets($attribute, !$itemType) ? '[]' : '');
return sprintf(
'%s%s',
$this->getStructAttributeTypeAsPhpType($attribute, $returnArrayType),
$this->useBrackets($attribute, !$itemType) ? '[]' : ''
);
}

protected function useBrackets(StructAttributeModel $attribute, bool $returnArrayType = true): bool
21 changes: 10 additions & 11 deletions src/File/Struct.php
Original file line number Diff line number Diff line change
@@ -347,17 +347,16 @@ protected function addStructMethodGetBodyReturn(PhpMethod $method, StructAttribu

protected function addStructMethodGet(StructAttributeModel $attribute): self
{
switch (true) {
// it can either be a string, a DOMDocument or null...
case $attribute->isXml():
$returnType = '';

break;

default:
$returnType = (!$attribute->getRemovableFromRequest() && !$attribute->isAChoice() && $attribute->isRequired() ? '' : '?').$this->getStructAttributeTypeAsPhpType($attribute);

break;
// it can either be a string, a DOMDocument or null...
if ($attribute->isXml()) {
$returnType = '';
} else {
$returnType = (
!$attribute->getRemovableFromRequest()
&& !$attribute->isAChoice()
&& $attribute->isRequired()
&& !$attribute->isNullable() ? '' : '?'
).$this->getStructAttributeTypeAsPhpType($attribute);
}

$method = new PhpMethod(
10 changes: 5 additions & 5 deletions src/File/StructArray.php
Original file line number Diff line number Diff line change
@@ -40,11 +40,6 @@ public function addStructMethodsSetAndGet(): self
return $this;
}

protected function addClassElement(): AbstractModelFile
{
return AbstractModelFile::addClassElement();
}

public function setModel(AbstractModel $model): self
{
if ($model instanceof StructModel && !$model->isArray()) {
@@ -54,6 +49,11 @@ public function setModel(AbstractModel $model): self
return parent::setModel($model);
}

protected function addClassElement(): AbstractModelFile
{
return AbstractModelFile::addClassElement();
}

/**
* Disable this feature within StructArray class.
*/
20 changes: 10 additions & 10 deletions tests/resources/generated/ValidBannerInfo.php
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ class ApiBannerInfo extends AbstractStructBase
* - base: soapenc:Array
* - nillable: true
* - ref: soapenc:arrayType
* @var \StructType\ApiBannerPhraseInfo[]
* @var \StructType\ApiBannerPhraseInfo[]|null
*/
protected ?array $Phrases = null;
/**
@@ -89,7 +89,7 @@ class ApiBannerInfo extends AbstractStructBase
* - base: soapenc:Array
* - nillable: true
* - ref: soapenc:arrayType
* @var string[]
* @var string[]|null
*/
protected ?array $MinusKeywords = null;
/**
@@ -155,7 +155,7 @@ class ApiBannerInfo extends AbstractStructBase
* - base: soapenc:Array
* - nillable: true
* - ref: soapenc:arrayType
* @var \StructType\ApiSitelink[]
* @var \StructType\ApiSitelink[]|null
*/
protected ?array $Sitelinks = null;
/**
@@ -165,7 +165,7 @@ class ApiBannerInfo extends AbstractStructBase
* - base: soapenc:Array
* - nillable: true
* - ref: soapenc:arrayType
* @var string[]
* @var string[]|null
*/
protected ?array $AdWarnings = null;
/**
@@ -182,7 +182,7 @@ class ApiBannerInfo extends AbstractStructBase
* - base: soapenc:Array
* - nillable: true
* - ref: soapenc:arrayType
* @var \StructType\ApiRejectReason[]
* @var \StructType\ApiRejectReason[]|null
*/
protected ?array $ModerateRejectionReasons = null;
/**
@@ -520,7 +520,7 @@ public function setGeo(?string $geo = null): self
}
/**
* Get Phrases value
* @return \StructType\ApiBannerPhraseInfo[]
* @return \StructType\ApiBannerPhraseInfo[]|null
*/
public function getPhrases(): ?array
{
@@ -587,7 +587,7 @@ public function addToPhrases(\StructType\ApiBannerPhraseInfo $item): self
}
/**
* Get MinusKeywords value
* @return string[]
* @return string[]|null
*/
public function getMinusKeywords(): ?array
{
@@ -838,7 +838,7 @@ public function setStatusSitelinksModerate(?string $statusSitelinksModerate = nu
}
/**
* Get Sitelinks value
* @return \StructType\ApiSitelink[]
* @return \StructType\ApiSitelink[]|null
*/
public function getSitelinks(): ?array
{
@@ -905,7 +905,7 @@ public function addToSitelinks(\StructType\ApiSitelink $item): self
}
/**
* Get AdWarnings value
* @return string[]
* @return string[]|null
*/
public function getAdWarnings(): ?array
{
@@ -995,7 +995,7 @@ public function setFixedOnModeration(?string $fixedOnModeration = null): self
}
/**
* Get ModerateRejectionReasons value
* @return \StructType\ApiRejectReason[]
* @return \StructType\ApiRejectReason[]|null
*/
public function getModerateRejectionReasons(): ?array
{
4 changes: 2 additions & 2 deletions tests/resources/generated/ValidHouseProfileData.php
Original file line number Diff line number Diff line change
@@ -372,7 +372,7 @@ class ApiHouseProfileData extends AbstractStructBase
* - base: soap-enc:Array
* - nillable: true
* - ref: soap-enc:arrayType
* @var \StructType\ApiLift[]
* @var \StructType\ApiLift[]|null
*/
protected ?array $lifts = null;
/**
@@ -1691,7 +1691,7 @@ public function setGas_system(?\StructType\ApiGasSystem $gas_system = null): sel
}
/**
* Get lifts value
* @return \StructType\ApiLift[]
* @return \StructType\ApiLift[]|null
*/
public function getLifts(): ?array
{
Loading