Skip to content

Commit 430361c

Browse files
committed
Merge branch 'release/4.1.9'
2 parents d8ac0a4 + 1c73fad commit 430361c

39 files changed

+60
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 4.1.9 - 2023-08-25
4+
- issue #299, pr #301 - Deprecated Warnings for Dynamic Properties
5+
- issue #300, pr #302 - Incorrect default value for integer attribute
6+
37
## 4.1.8 - 2023-04-20
48
- issue #285, pr #288 - Type-Error when using regex pattern for decimal restriction
59
- issue #292, pr #293 - Wrong type for gYearMonth and gMonthDay

src/File/Struct.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ public function getModel(): ?StructModel
4343
return parent::getModel();
4444
}
4545

46+
protected function addClassElement(): AbstractModelFile
47+
{
48+
$this->getFile()->addString('#[\AllowDynamicProperties]');
49+
50+
return parent::addClassElement();
51+
}
52+
4653
protected function defineUseStatements(): self
4754
{
4855
if ($this->getGenerator()->getOptionValidation()) {
49-
$this->getFile()->addUse(\InvalidArgumentException::class, null, false);
56+
$this->getFile()->addUse(\InvalidArgumentException::class);
5057
}
5158

5259
return parent::defineUseStatements();
@@ -175,7 +182,7 @@ protected function getStructMethodParameter(StructAttributeModel $attribute): Ph
175182
}
176183

177184
try {
178-
$defaultValue = $attribute->getDefaultValue();
185+
$defaultValue = $attribute->getDefaultValue($this->getStructAttributeTypeAsPhpType($attribute));
179186

180187
return new PhpFunctionParameter(
181188
lcfirst($attribute->getUniqueString($attribute->getCleanName(), 'method')),

src/File/StructArray.php

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

43+
protected function addClassElement(): AbstractModelFile
44+
{
45+
return AbstractModelFile::addClassElement();
46+
}
47+
4348
public function setModel(AbstractModel $model): self
4449
{
4550
if ($model instanceof StructModel && !$model->isArray()) {

src/File/StructEnum.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function setModel(AbstractModel $model): self
2727
return parent::setModel($model);
2828
}
2929

30+
protected function addClassElement(): AbstractModelFile
31+
{
32+
return AbstractModelFile::addClassElement();
33+
}
34+
3035
protected function fillClassConstants(ConstantContainer $constants): void
3136
{
3237
/** @var StructModel $model */

src/Generator/Utils.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,17 @@ public static function getStreamContextOptions(?string $basicAuthLogin = null, ?
104104
public static function getValueWithinItsType($value, ?string $knownType = null)
105105
{
106106
if (is_int($value) || (!is_null($value) && in_array($knownType, [
107-
'time',
108-
'positiveInteger',
109-
'unsignedLong',
110-
'unsignedInt',
111-
'short',
112-
'long',
113107
'int',
114108
'integer',
115109
], true))) {
116-
return intval($value);
110+
return (int) $value;
117111
}
118112
if (is_float($value) || (!is_null($value) && in_array($knownType, [
119113
'float',
120114
'double',
121115
'decimal',
122116
], true))) {
123-
return floatval($value);
117+
return (float) $value;
124118
}
125119
if (is_bool($value) || (!is_null($value) && in_array($knownType, [
126120
'bool',

src/Model/StructAttribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function isList(): bool
137137
/**
138138
* @return null|array|bool|float|int|string
139139
*/
140-
public function getDefaultValue()
140+
public function getDefaultValue(?string $type = null)
141141
{
142142
if (($struct = $this->getTypeStruct()) && $struct->isStruct()) {
143143
return null;
@@ -149,7 +149,7 @@ public function getDefaultValue()
149149
'DefaultValue',
150150
'defaultValue',
151151
'defaultvalue',
152-
]), $this->getType(true));
152+
]), $type);
153153
}
154154

155155
public function isRequired(): bool

tests/Generator/UtilsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testGetValueWithinItsType(): void
3535
{
3636
$this->assertSame('020', Utils::getValueWithinItsType('020', 'string'));
3737
$this->assertSame('01', Utils::getValueWithinItsType('01', 'string'));
38+
$this->assertSame(1, Utils::getValueWithinItsType('1', 'int'));
3839
$this->assertSame(2.568, Utils::getValueWithinItsType('2.568', 'float'));
3940
$this->assertSame(true, Utils::getValueWithinItsType('true', 'bool'));
4041
$this->assertSame(false, Utils::getValueWithinItsType('false', 'bool'));

tests/Model/StructAttributeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testStructAttributeTypeMustBeBool(): void
7676

7777
$this->assertSame('boolean', $structAttribute->getType(true));
7878
$this->assertSame('Success', $structAttribute->getType());
79-
$this->assertFalse($structAttribute->getDefaultValue());
79+
$this->assertFalse($structAttribute->getDefaultValue('boolean'));
8080
}
8181

8282
public function testIsNullableMustReturnFalse(): void

tests/resources/generated/ValidAdGroupsSelectionCriteria.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @subpackage Structs
1414
* @release 1.1.0
1515
*/
16+
#[\AllowDynamicProperties]
1617
class ApiAdGroupsSelectionCriteria extends AbstractStructBase
1718
{
1819
/**

tests/resources/generated/ValidAddRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @subpackage Structs
1414
* @release 1.1.0
1515
*/
16+
#[\AllowDynamicProperties]
1617
class ApiAddRequest extends AbstractStructBase
1718
{
1819
/**

0 commit comments

Comments
 (0)