-
Notifications
You must be signed in to change notification settings - Fork 153
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
Allow only bool|float|int|string for sprintf() #200
Conversation
is this doable? Should I continue with fixing tests? |
Hello, sorry for the late reply, i didn't get notified for some reason. |
Yes exactly. Because now it allows me to pass whatever and static analysis cannot catch it. I get notified on runtime and that's already late. Eg. passing an object without |
About your failed pipeline, i think the reason the test fails is that it cannot find your new sprintf(). The sprintf() used by the test is fetch by 'require_once DIR . '/../../generated/strings.php';' which doesn't match anymore since your new sprintf lives in 'lib/special_cases.php', so you need to edit the require_once |
Thanks. Ok, so it sounds viable and I can proceed with this? |
Honestly, no idea. You should ask the guys from psalm or phpstan to know if this is possible. From the point of view of safe, this is actually pretty tricky to test because the php language itself wont throw errors if you don't respect docblocks. |
To be fair, if you are sure than phpstan and psalm will work with your new param then you don't really need to test it. You can just edit the require to make the test succesfull again and be done with it |
Another things you can try, which may be easier and cleaner, is to edit CustomPhpStanFunctionMap.php instead. We actually use the stubs from phpstan to generate the typehints and the docblock of our generated functions. The file itself allow us to overwrite phpstan stubs. So you simply add a new line in CustomPhpStanFunctionMap for sprintf with your new type bool|float|int|string. It is cleaner because you don't have to put sprintf in the special_case file. The only possible issue is, I don't know if you can write '...args' in the stubs. But I think you should try this way instead |
Yea I tested it so that's np. I was rather wondering about the way I solved it here, did not find easier way to fix the typehints then to redefine the function.
this sounds the best so far, thanks! will try |
Hello @simPod Did you manage to make it work? |
@Kharhamel yes, I'm still into it. Are you asking to check whether this is stale or need to move it forward? |
No just checking if it is stale don't worry |
Hello @simPod, are you still on it? |
I needed to resolve these PRs but unfortunately there's no activity. php/phd#24 |
If you are blocked by the doc not being updated, you can overload the typings in this file: CustomPhpStanFunctionMap.php
|
@simPod I am closing this PR since it is too old. If you still want to implement this feature, you better start over to not have conflicts. |
Allow only bool|float|int|string for sprintf()