Skip to content

Commit 4ecd3b4

Browse files
committed
issue #312 - Fix getter return type
1 parent 7271073 commit 4ecd3b4

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

src/File/AbstractModelFile.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,12 @@ protected function getStructAttributeTypeGetAnnotation(StructAttributeModel $att
400400
return '\\DOMDocument|string|null';
401401
}
402402

403-
return sprintf('%s%s%s', $this->getStructAttributeTypeAsPhpType($attribute, false), $this->useBrackets($attribute, $returnArrayType) ? '[]' : '', !$nullableItemType && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null');
403+
return sprintf(
404+
'%s%s%s',
405+
$this->getStructAttributeTypeAsPhpType($attribute, false),
406+
$this->useBrackets($attribute, $returnArrayType) ? '[]' : '',
407+
!$nullableItemType && !$attribute->isNullable() && ($attribute->isRequired() || $attribute->isArray() || $attribute->isList()) ? '' : '|null'
408+
);
404409
}
405410

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

416-
return sprintf('%s%s', $this->getStructAttributeTypeAsPhpType($attribute, $returnArrayType), $this->useBrackets($attribute, !$itemType) ? '[]' : '');
421+
return sprintf(
422+
'%s%s',
423+
$this->getStructAttributeTypeAsPhpType($attribute, $returnArrayType),
424+
$this->useBrackets($attribute, !$itemType) ? '[]' : ''
425+
);
417426
}
418427

419428
protected function useBrackets(StructAttributeModel $attribute, bool $returnArrayType = true): bool

src/File/Struct.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,16 @@ protected function addStructMethodGetBodyReturn(PhpMethod $method, StructAttribu
347347

348348
protected function addStructMethodGet(StructAttributeModel $attribute): self
349349
{
350-
switch (true) {
351-
// it can either be a string, a DOMDocument or null...
352-
case $attribute->isXml():
353-
$returnType = '';
354-
355-
break;
356-
357-
default:
358-
$returnType = (!$attribute->getRemovableFromRequest() && !$attribute->isAChoice() && $attribute->isRequired() ? '' : '?').$this->getStructAttributeTypeAsPhpType($attribute);
359-
360-
break;
350+
// it can either be a string, a DOMDocument or null...
351+
if ($attribute->isXml()) {
352+
$returnType = '';
353+
} else {
354+
$returnType = (
355+
!$attribute->getRemovableFromRequest()
356+
&& !$attribute->isAChoice()
357+
&& $attribute->isRequired()
358+
&& !$attribute->isNullable() ? '' : '?'
359+
).$this->getStructAttributeTypeAsPhpType($attribute);
361360
}
362361

363362
$method = new PhpMethod(

src/File/StructArray.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public function addStructMethodsSetAndGet(): self
4040
return $this;
4141
}
4242

43-
protected function addClassElement(): AbstractModelFile
44-
{
45-
return AbstractModelFile::addClassElement();
46-
}
47-
4843
public function setModel(AbstractModel $model): self
4944
{
5045
if ($model instanceof StructModel && !$model->isArray()) {
@@ -54,6 +49,11 @@ public function setModel(AbstractModel $model): self
5449
return parent::setModel($model);
5550
}
5651

52+
protected function addClassElement(): AbstractModelFile
53+
{
54+
return AbstractModelFile::addClassElement();
55+
}
56+
5757
/**
5858
* Disable this feature within StructArray class.
5959
*/

tests/resources/generated/ValidBannerInfo.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ApiBannerInfo extends AbstractStructBase
7979
* - base: soapenc:Array
8080
* - nillable: true
8181
* - ref: soapenc:arrayType
82-
* @var \StructType\ApiBannerPhraseInfo[]
82+
* @var \StructType\ApiBannerPhraseInfo[]|null
8383
*/
8484
protected ?array $Phrases = null;
8585
/**
@@ -89,7 +89,7 @@ class ApiBannerInfo extends AbstractStructBase
8989
* - base: soapenc:Array
9090
* - nillable: true
9191
* - ref: soapenc:arrayType
92-
* @var string[]
92+
* @var string[]|null
9393
*/
9494
protected ?array $MinusKeywords = null;
9595
/**
@@ -155,7 +155,7 @@ class ApiBannerInfo extends AbstractStructBase
155155
* - base: soapenc:Array
156156
* - nillable: true
157157
* - ref: soapenc:arrayType
158-
* @var \StructType\ApiSitelink[]
158+
* @var \StructType\ApiSitelink[]|null
159159
*/
160160
protected ?array $Sitelinks = null;
161161
/**
@@ -165,7 +165,7 @@ class ApiBannerInfo extends AbstractStructBase
165165
* - base: soapenc:Array
166166
* - nillable: true
167167
* - ref: soapenc:arrayType
168-
* @var string[]
168+
* @var string[]|null
169169
*/
170170
protected ?array $AdWarnings = null;
171171
/**
@@ -182,7 +182,7 @@ class ApiBannerInfo extends AbstractStructBase
182182
* - base: soapenc:Array
183183
* - nillable: true
184184
* - ref: soapenc:arrayType
185-
* @var \StructType\ApiRejectReason[]
185+
* @var \StructType\ApiRejectReason[]|null
186186
*/
187187
protected ?array $ModerateRejectionReasons = null;
188188
/**
@@ -520,7 +520,7 @@ public function setGeo(?string $geo = null): self
520520
}
521521
/**
522522
* Get Phrases value
523-
* @return \StructType\ApiBannerPhraseInfo[]
523+
* @return \StructType\ApiBannerPhraseInfo[]|null
524524
*/
525525
public function getPhrases(): ?array
526526
{
@@ -587,7 +587,7 @@ public function addToPhrases(\StructType\ApiBannerPhraseInfo $item): self
587587
}
588588
/**
589589
* Get MinusKeywords value
590-
* @return string[]
590+
* @return string[]|null
591591
*/
592592
public function getMinusKeywords(): ?array
593593
{
@@ -838,7 +838,7 @@ public function setStatusSitelinksModerate(?string $statusSitelinksModerate = nu
838838
}
839839
/**
840840
* Get Sitelinks value
841-
* @return \StructType\ApiSitelink[]
841+
* @return \StructType\ApiSitelink[]|null
842842
*/
843843
public function getSitelinks(): ?array
844844
{
@@ -905,7 +905,7 @@ public function addToSitelinks(\StructType\ApiSitelink $item): self
905905
}
906906
/**
907907
* Get AdWarnings value
908-
* @return string[]
908+
* @return string[]|null
909909
*/
910910
public function getAdWarnings(): ?array
911911
{
@@ -995,7 +995,7 @@ public function setFixedOnModeration(?string $fixedOnModeration = null): self
995995
}
996996
/**
997997
* Get ModerateRejectionReasons value
998-
* @return \StructType\ApiRejectReason[]
998+
* @return \StructType\ApiRejectReason[]|null
999999
*/
10001000
public function getModerateRejectionReasons(): ?array
10011001
{

tests/resources/generated/ValidHouseProfileData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ApiHouseProfileData extends AbstractStructBase
372372
* - base: soap-enc:Array
373373
* - nillable: true
374374
* - ref: soap-enc:arrayType
375-
* @var \StructType\ApiLift[]
375+
* @var \StructType\ApiLift[]|null
376376
*/
377377
protected ?array $lifts = null;
378378
/**
@@ -1691,7 +1691,7 @@ public function setGas_system(?\StructType\ApiGasSystem $gas_system = null): sel
16911691
}
16921692
/**
16931693
* Get lifts value
1694-
* @return \StructType\ApiLift[]
1694+
* @return \StructType\ApiLift[]|null
16951695
*/
16961696
public function getLifts(): ?array
16971697
{

0 commit comments

Comments
 (0)