-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Incorrect array bounds in docs #26
Comments
I misattributed the issue, yes, the above code is also incorrect but the code generation problem comes from https://github.com/phpro/soap-client/blob/05bded4ca8b46c463de1337f256bb9763532e0b5/src/Phpro/SoapClient/CodeGenerator/TypeEnhancer/MetaTypeEnhancer.php#L33 |
Want me to open a separate issue? |
The problem indeed is not located in this repository. However, you are right : Static analysis complains in the ArrayBoundsCalculator inside the code generator MetaTypeEnhancer and should be fixed there. This format works for psalm: (given /**
* @param array{0: string, 1 ?: string} $items
*/
function x(array $items): void {}
x([]);
x(['1']);
x(['1', '2']);
x(['1', '2', '3']); https://psalm.dev/r/cb9ee08186 However phpstan does not seem to understand the max bound: https://phpstan.org/r/d38f0bd5-2a03-4798-96a5-8c5a5f42b501 Not sure what the best way forward would be:
How do you see this? |
An option could be to do shapes (option 1) for small enough max occurs (e.g. < 100) and fall back to 3 |
I take it back, the only correct way is option 3 because also shapes don’t allow for non-contiguous arrays. |
The result is actually always a |
Yeah, you are right, non-contiguous arrays do not work anyway. So, list and non-empty-list it 😄 |
Option 1 would still be the better option for smaller shapes though. Phpstan doesn't check the upper bound, but it would still be mor viable regarding the lower bounds. So I'm thinking about having option 1 and maybe limit it to a specific amount of items - which then would fallback to option 3. One other possibility is to not use the list, but only use the maxOccurs to set an upper bound like this:
For completeness : There is also the IteratorAssembler. That one could never use option 1, but could use option 3 or the newly introduced option. I'm kinda thinking the last option I proposed would be the most exact and easiest option to implement at this point which can be reused for the iterator as well. What's your preference? |
Provided a fix in phpro/soap-client#518 Can you take a look to see if this would work for you? |
Bug Report
Summary
The array key boundaries generated in XsdTypeFormatter are incorrect. They attempt to define the length of the array but instead they define the shape of the keys.
Current behaviour
Given this element:
The resulting type is this:
This would reject a 0 indexed array like this (because it only allows keys from 1 to 20):
Such an array would be totally fine though.
Expected behaviour
Instead of limiting the array keys I think it would be good enough to differentiate list and non-empty-list.
See
wsdl-reader/src/Formatter/XsdTypeFormatter.php
Line 21 in 32d32e0
The text was updated successfully, but these errors were encountered: