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

AbstractModel::uniqueName returns int when $name and $context already in lower case #254

Open xpavp03 opened 3 years ago

xpavp03 commented 3 years ago

Generating from https://www.imonitor.cz/imonws/BaseWS.asmx?WSDL with default settings taken from your README.MD example.

Parameters of this specific case are: $name = 'spz' $context = '000000005edf52d6000000003b6aed65rowmethod' self::$uniqueNames[$sensitiveKey] === 0 so int 0 is returned

It seems you assumed that $sensitiveKey and $insensitiveKey will always be different so you used the same array for both the counter and resolved unique names.

Fatal error: Uncaught TypeError: Return value of WsdlToPhp\PackageGenerator\Model\AbstractModel::uniqueName() must be of the type string, int returned in /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/Model/AbstractModel.php:439 Stack trace:

0 /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/Model/StructAttribute.php(43): WsdlToPhp\PackageGenerator\Model\AbstractModel::uniqueName('spz', '0000000001bcc60...')

1 /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/File/Struct.php(165): WsdlToPhp\PackageGenerator\Model\StructAttribute->getUniqueString('spz', 'method')

2 /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/File/Struct.php(142): WsdlToPhp\PackageGenerator\File\Struct->getStructMethodParameter(Object(WsdlToPhp\PackageGenerator\Model\StructAttribute))

3 /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/File/Struct.php(108): WsdlToPhp\PackageGenerator\File\Struct->getStructMethodParametersValues()

4 /var/www/app/wsdltophp-src/vendor/wsd in /var/www/app/wsdltophp-src/vendor/wsdltophp/packagegenerator/src/Model/AbstractModel.php on line 439

<?php require_once DIR . '/wsdltophp-src/vendor/autoload.php';

use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions; use WsdlToPhp\PackageGenerator\Generator\Generator;

// Options definition: the configuration file parameter is optional $options = GeneratorOptions::instance(/ '/path/file.yml' /); $options ->setOrigin('https://www.imonitor.cz/imonws/BaseWS.asmx?WSDL') ->setDestination('./imonitor-soap') ->setComposerName('xxx/imonitor-soap'); // Generator instantiation $generator = new Generator($options); // Package generation $generator->generatePackage();

mikaelcom commented 3 years ago

I'll look to it as soon as possible, thx

xpavp03 commented 3 years ago

No need to hurry because of me. I fixed it in my local copy and completed my project. Thank you very much for your work on this project. It's extraordinary.

My fix was rather simple, I just created another array.


    protected static array $uniqueNames = [];
    protected static array $uniqueNamesCounter = [];

    protected static function uniqueName(string $name, string $context): string
    {
        $insensitiveKey = mb_strtolower($name.'_'.$context);
        $sensitiveKey = $name.'_'.$context;
        if (array_key_exists($sensitiveKey, self::$uniqueNames)) {
            return self::$uniqueNames[$sensitiveKey];
        }

        if (!array_key_exists($insensitiveKey, self::$uniqueNames)) {
            self::$uniqueNamesCounter[$insensitiveKey] = 0;
        } else {
            ++self::$uniqueNamesCounter[$insensitiveKey];
        }

        $uniqueName = $name.(self::$uniqueNamesCounter[$insensitiveKey] ? '_'.self::$uniqueNamesCounter[$insensitiveKey] : '');
        self::$uniqueNames[$sensitiveKey] = $uniqueName;

        return $uniqueName;
    }