Skip to content

Commit

Permalink
Merge branch 'WsdlToPhp:develop' into superbiche-patch-280
Browse files Browse the repository at this point in the history
  • Loading branch information
superbiche authored Oct 4, 2024
2 parents e014998 + f7f1d23 commit 25d6c0e
Show file tree
Hide file tree
Showing 44 changed files with 123 additions and 45 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# CHANGELOG

## 4.1.13 - 2024-06-21
- issue #312, pr #313 - Invalid getter and annotation for nullable property

## 4.1.12 - 2024-04-13
- issue #308, pr #309 - Symfony 7 / added support for symfony 7

## 4.1.11 - 2023-10-18
- issue #304, pr #305 - Override required PHP version in composer.json

## 4.1.10 - 2023-09-11
- issue #298, pr #303 - Undefined constant "WsdlToPhp\PackageGenerator\Generator\SOAP_1_1"

## 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Developers who helped on this project are listed in the [composer.json](composer
- [Arnaud POINTET](https://github.com/Oipnet)
- [dypa](https://github.com/dypa)
- [tbreuss](https://github.com/tbreuss)
- [Paul Melekhov](https://github.com/gugglegum)
- [Alex Krátký](https://github.com/AlexKratky)

## FAQ

Expand Down
17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@
"role": "Contributor"
},
{
"name": "tbreuss",
"email": "[email protected]",
"name": "gugglegum",
"email": "[email protected]",
"role": "Contributor"
},
{
"name": "tbreuss",
"email": "[email protected]",
"role": "Contributor"
},
{
"name": "Alex Krátký",
"role": "Contributor"
}
],
"support" : {
Expand All @@ -105,8 +114,8 @@
"ext-mbstring": "*",
"ext-soap": "*",
"composer/composer": "^2.0",
"symfony/console": "^4.0|^5.0|^6.0",
"symfony/yaml": "^4.0|^5.0|^6.0",
"symfony/console": "^4.0|^5.0|^6.0|^7.0",
"symfony/yaml": "^4.0|^5.0|^6.0|^7.0",
"wsdltophp/packagebase": "^5.0",
"wsdltophp/phpgenerator": "^4.0",
"wsdltophp/wsdlhandler": "^1.0"
Expand Down
13 changes: 11 additions & 2 deletions src/File/AbstractModelFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/File/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function addAutoloadToComposerJson(array &$content): Composer

protected function addComposerSettings(array &$content): Composer
{
$content = array_merge_recursive($content, $this->getGenerator()->getOptionComposerSettings());
$content = array_replace_recursive($content, $this->getGenerator()->getOptionComposerSettings());

return $this;
}
Expand Down
32 changes: 19 additions & 13 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 Expand Up @@ -340,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(
Expand Down
5 changes: 5 additions & 0 deletions src/File/StructArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,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.
*/
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
4 changes: 2 additions & 2 deletions src/Generator/GeneratorSoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function __construct(Generator $generator)
public function initSoapClient(): self
{
try {
$soapClient = new SoapClient($this->getSoapClientOptions(SOAP_1_1));
$soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_1));
} catch (\SoapFault $fault) {
try {
$soapClient = new SoapClient($this->getSoapClientOptions(SOAP_1_2));
$soapClient = new SoapClient($this->getSoapClientOptions(\SOAP_1_2));
} catch (\SoapFault $fault) {
throw new \InvalidArgumentException(sprintf('Unable to load WSDL at "%s"!', $this->getGenerator()->getOptionOrigin()), __LINE__, $fault);
}
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
Loading

0 comments on commit 25d6c0e

Please sign in to comment.