WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
428 stars 73 forks source link

Wrong type for gYearMonth and gMonthDay #292

Closed tbreuss closed 1 year ago

tbreuss commented 1 year ago

Describe the bug

It seems, that for an "xs:gYearMonth" the generated PHP code has a wrong type hint. This eventually leads to an type hint exception "Cannot assign string to property of type ?int".

To Reproduce

The given XSD looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="AwaitCorrectionFromCompanyType">
        <xs:sequence>
            <xs:element name="ValidAsOf" type="xs:gYearMonth">
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

The corresponding generated PHP code looks like this:

<?php

class AwaitCorrectionFromCompanyType extends AbstractStructBase
{
    /**
     * The ValidAsOf
     * @var int|null
     */
    protected ?int $ValidAsOf = null;

    /**
     * Constructor method for AwaitCorrectionFromCompanyType
     * @param int $validAsOf
     */
    public function __construct(?int $validAsOf = null)
    {
        $this
            ->setValidAsOf($validAsOf);
    }

    /**
     * Get ValidAsOf value
     * @return int|null
     */
    public function getValidAsOf(): ?int
    {
        return $this->ValidAsOf;
    }

    /**
     * Set ValidAsOf value
     * @param int $validAsOf
     */
    public function setValidAsOf(?int $validAsOf = null): self
    {
        // validation for constraint: int
        if (!is_null($validAsOf) && !(is_int($validAsOf) || ctype_digit($validAsOf))) {
            throw new InvalidArgumentException(sprintf('Invalid value %s, please provide an integer value, %s given', var_export($validAsOf, true), gettype($validAsOf)), __LINE__);
        }
        $this->ValidAsOf = $validAsOf;

        return $this;
    }
}

The given XML data looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<AwaitCorrectionFromCompany>
    <ValidAsOf>1997-02+01:00</ValidAsOf>
</AwaitCorrectionFromCompany>

Which leads to a PHP exception "Cannot assign string to property of type ?int".

Expected behavior

My understanding is that the generated PHP type for a "xs:gYearMonth" must be a string.

mikaelcom commented 1 year ago

Types are currently configured within this file: xsd_types.yml. Temporarily, you can use your own file passing the xsd-types-path option. If you succeed to generate a fully functional package, hopefully, without further type issue, please share it with me so I can fix the default types.

tbreuss commented 1 year ago

I'll do it the way you suggested. Thanks.

tbreuss commented 1 year ago

Please see pull request #293, which should fix this issue.

tbreuss commented 1 year ago

Pull request #293 fixes gYearMonth and gMonthDay.