Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xpavp03 opened this issue May 26, 2021 · 2 comments
Assignees
Labels

Comments

@xpavp03
Copy link

xpavp03 commented May 26, 2021

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

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
Copy link
Member

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

@xpavp03
Copy link
Author

xpavp03 commented May 27, 2021

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants