Skip to content

Commit ba8511e

Browse files
committed
issue #330 - an attribute is required as soon as it is present
Nonetheless, the attribute must not be marked as optional.
1 parent 7c7f7e1 commit ba8511e

13 files changed

Lines changed: 424 additions & 416 deletions

src/Model/Struct.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,18 @@ public function getInheritanceStruct(): ?Struct
286286
public function getTopInheritance(): string
287287
{
288288
$inheritance = $this->getInheritance();
289-
if (!empty($inheritance)) {
290-
$struct = $this->getInheritanceStruct();
291-
while ($struct instanceof Struct) {
292-
$structInheritance = $struct->getInheritance();
293-
if (!empty($structInheritance)) {
294-
$inheritance = $structInheritance;
295-
}
296-
$struct = $struct->getInheritanceStruct();
289+
290+
if (empty($inheritance)) {
291+
return $inheritance;
292+
}
293+
294+
$struct = $this->getInheritanceStruct();
295+
while ($struct instanceof Struct) {
296+
$structInheritance = $struct->getInheritance();
297+
if (!empty($structInheritance)) {
298+
$inheritance = $structInheritance;
297299
}
300+
$struct = $struct->getInheritanceStruct();
298301
}
299302

300303
return $inheritance;

src/Model/StructAttribute.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ public function getSetterName(): string
5959

6060
public function getType(bool $useTypeStruct = false): string
6161
{
62-
if ($useTypeStruct) {
63-
$typeStruct = $this->getTypeStruct();
64-
if ($typeStruct instanceof Struct) {
65-
$type = $typeStruct->getTopInheritance();
62+
if (!$useTypeStruct) {
63+
return $this->type;
64+
}
6665

67-
return $type ?: $this->type;
68-
}
66+
$typeStruct = $this->getTypeStruct();
67+
if (!$typeStruct instanceof Struct) {
68+
return $this->type;
6969
}
7070

71-
return $this->type;
71+
return $typeStruct->getTopInheritance() ?: $this->type;
7272
}
7373

7474
public function setType(string $type): StructAttribute
@@ -154,12 +154,17 @@ public function getDefaultValue(?string $type = null)
154154

155155
public function isRequired(): bool
156156
{
157-
return 'required' === $this->getMetaValue('use', '') || 0 < $this->getMetaValueFirstSet([
158-
'minOccurs',
159-
'minoccurs',
160-
'MinOccurs',
161-
'Minoccurs',
162-
], 0);
157+
return 'optional' !== $this->getMetaValue('use', '')
158+
&& !$this->isNullable()
159+
&& (
160+
'required' === $this->getMetaValue('use', '')
161+
|| 0 < $this->getMetaValueFirstSet([
162+
'minOccurs',
163+
'minoccurs',
164+
'MinOccurs',
165+
'Minoccurs',
166+
], 1)
167+
);
163168
}
164169

165170
public function isNullable(): bool

tests/resources/generated/ValidAddressDelivery_Type.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,42 @@ class ApiAddressDelivery_Type extends AbstractStructBase
2323
* Meta information extracted from the WSDL
2424
* - documentation: First line on delivery address
2525
* - base: string
26-
* @var string|null
26+
* @var string
2727
*/
28-
protected ?string $Street1 = null;
28+
protected string $Street1;
2929
/**
3030
* The Street2
3131
* Meta information extracted from the WSDL
3232
* - documentation: Second line on delivery address
3333
* - base: string
34-
* @var string|null
34+
* @var string
3535
*/
36-
protected ?string $Street2 = null;
36+
protected string $Street2;
3737
/**
3838
* The Street3
3939
* Meta information extracted from the WSDL
4040
* - documentation: Third line on delivery address
4141
* - base: string
42-
* @var string|null
42+
* @var string
4343
*/
44-
protected ?string $Street3 = null;
44+
protected string $Street3;
4545
/**
4646
* The City
4747
* Meta information extracted from the WSDL
4848
* - documentation: The delivery city
4949
* - base: string
50-
* @var string|null
50+
* @var string
5151
*/
52-
protected ?string $City = null;
52+
protected string $City;
5353
/**
5454
* The PostalCode
5555
* Meta information extracted from the WSDL
5656
* - documentation: Postal code for the city
5757
* - base: string
5858
* - length: 4
59-
* @var string|null
59+
* @var string
6060
*/
61-
protected ?string $PostalCode = null;
61+
protected string $PostalCode;
6262
/**
6363
* Constructor method for AddressDelivery_Type
6464
* @uses ApiAddressDelivery_Type::setStreet1()
@@ -72,7 +72,7 @@ class ApiAddressDelivery_Type extends AbstractStructBase
7272
* @param string $city
7373
* @param string $postalCode
7474
*/
75-
public function __construct(?string $street1 = null, ?string $street2 = null, ?string $street3 = null, ?string $city = null, ?string $postalCode = null)
75+
public function __construct(string $street1, string $street2, string $street3, string $city, string $postalCode)
7676
{
7777
$this
7878
->setStreet1($street1)
@@ -83,9 +83,9 @@ public function __construct(?string $street1 = null, ?string $street2 = null, ?s
8383
}
8484
/**
8585
* Get Street1 value
86-
* @return string|null
86+
* @return string
8787
*/
88-
public function getStreet1(): ?string
88+
public function getStreet1(): string
8989
{
9090
return $this->Street1;
9191
}
@@ -94,7 +94,7 @@ public function getStreet1(): ?string
9494
* @param string $street1
9595
* @return \StructType\ApiAddressDelivery_Type
9696
*/
97-
public function setStreet1(?string $street1 = null): self
97+
public function setStreet1(string $street1): self
9898
{
9999
// validation for constraint: string
100100
if (!is_null($street1) && !is_string($street1)) {
@@ -106,9 +106,9 @@ public function setStreet1(?string $street1 = null): self
106106
}
107107
/**
108108
* Get Street2 value
109-
* @return string|null
109+
* @return string
110110
*/
111-
public function getStreet2(): ?string
111+
public function getStreet2(): string
112112
{
113113
return $this->Street2;
114114
}
@@ -117,7 +117,7 @@ public function getStreet2(): ?string
117117
* @param string $street2
118118
* @return \StructType\ApiAddressDelivery_Type
119119
*/
120-
public function setStreet2(?string $street2 = null): self
120+
public function setStreet2(string $street2): self
121121
{
122122
// validation for constraint: string
123123
if (!is_null($street2) && !is_string($street2)) {
@@ -129,9 +129,9 @@ public function setStreet2(?string $street2 = null): self
129129
}
130130
/**
131131
* Get Street3 value
132-
* @return string|null
132+
* @return string
133133
*/
134-
public function getStreet3(): ?string
134+
public function getStreet3(): string
135135
{
136136
return $this->Street3;
137137
}
@@ -140,7 +140,7 @@ public function getStreet3(): ?string
140140
* @param string $street3
141141
* @return \StructType\ApiAddressDelivery_Type
142142
*/
143-
public function setStreet3(?string $street3 = null): self
143+
public function setStreet3(string $street3): self
144144
{
145145
// validation for constraint: string
146146
if (!is_null($street3) && !is_string($street3)) {
@@ -152,9 +152,9 @@ public function setStreet3(?string $street3 = null): self
152152
}
153153
/**
154154
* Get City value
155-
* @return string|null
155+
* @return string
156156
*/
157-
public function getCity(): ?string
157+
public function getCity(): string
158158
{
159159
return $this->City;
160160
}
@@ -163,7 +163,7 @@ public function getCity(): ?string
163163
* @param string $city
164164
* @return \StructType\ApiAddressDelivery_Type
165165
*/
166-
public function setCity(?string $city = null): self
166+
public function setCity(string $city): self
167167
{
168168
// validation for constraint: string
169169
if (!is_null($city) && !is_string($city)) {
@@ -175,9 +175,9 @@ public function setCity(?string $city = null): self
175175
}
176176
/**
177177
* Get PostalCode value
178-
* @return string|null
178+
* @return string
179179
*/
180-
public function getPostalCode(): ?string
180+
public function getPostalCode(): string
181181
{
182182
return $this->PostalCode;
183183
}
@@ -186,7 +186,7 @@ public function getPostalCode(): ?string
186186
* @param string $postalCode
187187
* @return \StructType\ApiAddressDelivery_Type
188188
*/
189-
public function setPostalCode(?string $postalCode = null): self
189+
public function setPostalCode(string $postalCode): self
190190
{
191191
// validation for constraint: string
192192
if (!is_null($postalCode) && !is_string($postalCode)) {

0 commit comments

Comments
 (0)