AbstractModel::uniqueName returns int when $name and $context already in lower case
xpavp03 opened this issue · 2 comments
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
I'll look to it as soon as possible, thx
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;
}