Skip to content

Commit

Permalink
Merge branch 'release/4.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Aug 25, 2023
2 parents d8ac0a4 + 1c73fad commit 430361c
Show file tree
Hide file tree
Showing 39 changed files with 60 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 4.1.9 - 2023-08-25
- issue #299, pr #301 - Deprecated Warnings for Dynamic Properties
- issue #300, pr #302 - Incorrect default value for integer attribute

## 4.1.8 - 2023-04-20
- issue #285, pr #288 - Type-Error when using regex pattern for decimal restriction
- issue #292, pr #293 - Wrong type for gYearMonth and gMonthDay
Expand Down
11 changes: 9 additions & 2 deletions src/File/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ public function getModel(): ?StructModel
return parent::getModel();
}

protected function addClassElement(): AbstractModelFile
{
$this->getFile()->addString('#[\AllowDynamicProperties]');

return parent::addClassElement();
}

protected function defineUseStatements(): self
{
if ($this->getGenerator()->getOptionValidation()) {
$this->getFile()->addUse(\InvalidArgumentException::class, null, false);
$this->getFile()->addUse(\InvalidArgumentException::class);
}

return parent::defineUseStatements();
Expand Down Expand Up @@ -175,7 +182,7 @@ protected function getStructMethodParameter(StructAttributeModel $attribute): Ph
}

try {
$defaultValue = $attribute->getDefaultValue();
$defaultValue = $attribute->getDefaultValue($this->getStructAttributeTypeAsPhpType($attribute));

return new PhpFunctionParameter(
lcfirst($attribute->getUniqueString($attribute->getCleanName(), 'method')),
Expand Down
5 changes: 5 additions & 0 deletions src/File/StructArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ 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()) {
Expand Down
5 changes: 5 additions & 0 deletions src/File/StructEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function setModel(AbstractModel $model): self
return parent::setModel($model);
}

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

protected function fillClassConstants(ConstantContainer $constants): void
{
/** @var StructModel $model */
Expand Down
10 changes: 2 additions & 8 deletions src/Generator/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,17 @@ public static function getStreamContextOptions(?string $basicAuthLogin = null, ?
public static function getValueWithinItsType($value, ?string $knownType = null)
{
if (is_int($value) || (!is_null($value) && in_array($knownType, [
'time',
'positiveInteger',
'unsignedLong',
'unsignedInt',
'short',
'long',
'int',
'integer',
], true))) {
return intval($value);
return (int) $value;
}
if (is_float($value) || (!is_null($value) && in_array($knownType, [
'float',
'double',
'decimal',
], true))) {
return floatval($value);
return (float) $value;
}
if (is_bool($value) || (!is_null($value) && in_array($knownType, [
'bool',
Expand Down
4 changes: 2 additions & 2 deletions src/Model/StructAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function isList(): bool
/**
* @return null|array|bool|float|int|string
*/
public function getDefaultValue()
public function getDefaultValue(?string $type = null)
{
if (($struct = $this->getTypeStruct()) && $struct->isStruct()) {
return null;
Expand All @@ -149,7 +149,7 @@ public function getDefaultValue()
'DefaultValue',
'defaultValue',
'defaultvalue',
]), $this->getType(true));
]), $type);
}

public function isRequired(): bool
Expand Down
1 change: 1 addition & 0 deletions tests/Generator/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testGetValueWithinItsType(): void
{
$this->assertSame('020', Utils::getValueWithinItsType('020', 'string'));
$this->assertSame('01', Utils::getValueWithinItsType('01', 'string'));
$this->assertSame(1, Utils::getValueWithinItsType('1', 'int'));
$this->assertSame(2.568, Utils::getValueWithinItsType('2.568', 'float'));
$this->assertSame(true, Utils::getValueWithinItsType('true', 'bool'));
$this->assertSame(false, Utils::getValueWithinItsType('false', 'bool'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/StructAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testStructAttributeTypeMustBeBool(): void

$this->assertSame('boolean', $structAttribute->getType(true));
$this->assertSame('Success', $structAttribute->getType());
$this->assertFalse($structAttribute->getDefaultValue());
$this->assertFalse($structAttribute->getDefaultValue('boolean'));
}

public function testIsNullableMustReturnFalse(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiAdGroupsSelectionCriteria extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidAddRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiAddRequest extends AbstractStructBase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiAddRequest extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiАдресРФ extends ApiСостав
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidAddressDelivery_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiAddressDelivery_Type extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidAddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiAddressType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiControlsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiControlsType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiFareItinerary.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiFareItinerary extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiItem extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiNewsArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiNewsArticle extends StructClass
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiOffer extends ApiOrder
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiQuery extends AbstractStructBase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiQuery extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiSearchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiSearchRequest extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidApiVideoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiVideoRequest extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidBannerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiBannerInfo extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidCampaignGetItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiCampaignGetItem extends ApiCampaignBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiDetails extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidExpiryDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiExpiryDate extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidFieldString1000.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiFieldString1000 extends ApiFieldString
{
}
1 change: 1 addition & 0 deletions tests/resources/generated/ValidHotelReservationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiHotelReservationType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidHouseProfileData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiHouseProfileData extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidPaymentCardType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiPaymentCardType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidProposeNewTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiProposeNewTimeType extends ApiResponseObjectType
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiSetExpressCheckoutRequestDetailsType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidShopper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiShopper extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidTaxType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiTaxType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidUniqueID_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiUniqueID_Type extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidUnitTestsStructResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiResult extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidUnitTestsValueListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiValueListType extends AbstractStructBase
{
/**
Expand Down
1 change: 1 addition & 0 deletions tests/resources/generated/ValidWorkingPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @subpackage Structs
* @release 1.1.0
*/
#[\AllowDynamicProperties]
class ApiWorkingPeriod extends AbstractStructBase
{
/**
Expand Down

0 comments on commit 430361c

Please sign in to comment.