-
Notifications
You must be signed in to change notification settings - Fork 49
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
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule is not #189
Comments
I did not touched it because it was already configurable. But I think it is good idea to add it condigurable and defaulted to bleeding edge. @ondrejmirtes Do you agree? I will make PR |
So far all the Here I wonder if we will have an issue since if we add it under the same config, it will be a bc break We might also decide to split the For instance, DisallowedEmptyRule and DisallowedShortTernaryRule are rules which requires a lot of changes in a legacy code base. The |
I would preffer to keep BC and just add You can disable rules:
- PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule |
I think it's a bit tricky to set up the configuration correctly. So we want to have a new option to turn on/off DisallowedLooseComparisonRule comfortably. It needs to behave this way: By default:
With this new option set to
With this new option set to
Does this make sense? Can this be achieved in neon config? |
@ondrejmirtes I am not sure it is possible in neon. It would require logical operations in config. I will look at it. |
@ondrejmirtes Basically we would need a way to do: |
It seems impossible in neon. But I have idea. What about make conditonalTags extension accept not only bool but also some struct with advanved conditions? I will think about some resonable format for that |
Can you imagine doing it with a conditionalIncludes compiler extension? |
What about this? parameters:
strictRules:
allRules: true
disallowedLooseComparsion: [%strictRules.allRules%, %featureToggles.bleedingEdge%]
# ...
parametersSchema:
strictRules: structure([
allRules: bool(),
disallowedLooseComparsion: anyOf(bool(), arrayOf(bool()))
# ...
])
conditionalTags:
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule:
phpstan.rules.rule: %strictRules.disallowedLooseComparsion% And extends ConditionalTagsExtension so it accepts not only bool but also array of bools that all have to be true for tag to be added. |
I'd like |
Not sure of it is possible and it definetly would be way more complicated. |
My issue with |
I know it is not ideal but there is no easy way to do it. Problem is that it needs to be evaluated compile-time and nette/di does not support this. So it would (as far as I know) require writing own NeonAdapter and ParametersExtension. Otherwise everything that is not primitive type is converted to Statement and transformed to PHP code evaluated run-time. Only other option I can think about is |
We already have custom NeonAdapter to expand relative paths based on the directory where the config file is: https://github.com/phpstan/phpstan-src/blob/1.8.x/src/DependencyInjection/NeonAdapter.php Do you see a way to adapt that? |
I need to look at it. It woudl require to detect and() as special type of construct that is transformed to something else than Statement (and I am not sure it would be accepted by later processing in nette/di) and then in ConditionalTagsExtension write code to evaluate these special objects. |
Alright, but don't spend too much time on it :) We don't need to solve this at all as these rules are gonna have a standard parameter associated in 2.0. |
I am checking what could be done. At this point it seems that easiest and best option would be PR to nette/di that will add this possibility there. It would require many changes in many files and maintainig own versions of all these files would be burden for PHPStan. |
Or we can just use that option with array and document it somewhere that it is always AND. As far as I can see ConditionalTagsExtension is more or less internal thing anyways. |
Alright, array it is. Please send the pull requests :) |
OK I will prepere PRs |
@ondrejmirtes There are no tests for ConditionalTagsExtension? I finished implementation but I wanted to add tests for it and I did not found any existing test for it. |
Probably not, it's tested by the fact that the configuration works as expected. You could test it by extending PHPStanTestCase, providing different neon files in overriden getAdditionalConfigFiles(), and inspecting what's in |
Frist PR ready for review here: phpstan/phpstan-src#1697 Then I will make change in strict-rules |
We would need phpstan release so we can bump required phpstan version to version with multiple conditions support first. |
The phpstan release is most likely not necessary. After it was merged you should the able to require the next patch version and it will pull the current dev branch :) |
Solved by #191 I think |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Configuration was introduced for rules in #182 (cc @MartinMystikJonas)
But not for PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule
Is there a reason ?
When using bleedingEdge (for other phpstan feature) it would be nice to still be able to disable the DisallowedLooseComparisonRule.
Should we create a new config parameter which default to
%featureToggles.bleedingEdge%
?The text was updated successfully, but these errors were encountered: