-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Having multiple allowExceptCaseInsensitiveParams
together with disallowedAttributes
does not work
#238
Comments
For now, this seems to work: <?php
declare(strict_types=1);
return [
'parameters' => [
'disallowedAttributes' => [
[
'attribute' => Doctrine\ORM\Mapping\Column::class,
'message' => 'use `utc_datetime_immutable` instead.',
'allowExceptParams' => [
[
'name' => 'type',
'position' => 2,
'typeString' => '"datetime"|"datetime_immutable"',
],
],
],
],
],
]; |
Thanks for the bug, nice catch! For some reason the phpstan-disallowed-calls/src/RuleErrors/DisallowedCallsRuleErrors.php Lines 56 to 60 in 90fdf80
So that's probably why it works for functions, but not for attributes. (Update: no, it's not, it's almost the same code except the For now, I have written a test f22ee42, a failing one, will fix once there's a bit more brain power. And more sleep 😆 |
The reason is that attributes and most other "calls" use a simple key when adding items from the config (the name of the thing):
while calls use a composite key (the reason being that some functions/methods come pre-configured in
This is not very clever but I'm not sure how to do it better, there's always a "but". So for now this will stay. @ruudk You can use the [
'attribute' => AttributeColumn::class,
'message' => 'use `utc_datetime_immutable` instead.',
'allowExceptCaseInsensitiveParams' => [
[
'name' => 'type',
'position' => 2,
'value' => 'datetime',
],
[
'name' => 'type',
'position' => 2,
'value' => 'datetime_immutable',
],
],
], Notice there's just one |
I'm trying to prevent the following:
I can do that with the following config:
It produces:
But as soon as I add another disallowed attribute, it stops working:
It's interesting, because this does seem to work for normal functions:
phpstan-disallowed-calls/disallowed-insecure-calls.neon
Lines 15 to 24 in 90fdf80
The text was updated successfully, but these errors were encountered: