-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add test for ValidConstantFunctionRule #282
Conversation
@@ -7,4 +7,6 @@ | |||
{{ constant('ThisDoesNotExist::SomeKey') }} | |||
{{ constant(someVar) }} | |||
{{ constant('ThisDoesNotExist::class') }} | |||
{{ constant(1) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because the return type was mixed according to psalm or PHPStan. Shouldn't be the case I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe beter to report an error in that case.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #282 +/- ##
=============================================
+ Coverage 99.91% 100.00% +0.08%
- Complexity 726 729 +3
=============================================
Files 65 65
Lines 2259 2266 +7
=============================================
+ Hits 2257 2266 +9
+ Misses 2 0 -2 ☔ View full report in Codecov by Sentry. |
if ('::class' === strtolower(substr($constant, -7))) { | ||
$this->addError( | ||
sprintf('You cannot use the Twig function "constant()" to access "%s". You could provide an object and call constant("class", $object) or use the class name directly as a string.', $constant), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take any suggestion here @ruudk but I'd like to avoid a too long error message.
So far I always had short message like "Variable should be called foo" or "Expected 2 spaces, found 1". This gave report with all the error messages written on single line every time and I'm not happy with the fact that this error would be certainly written with multiples lines.
Maybe letter something like an additional help text could be written, but so far I'd like a short message.
I try 'You cannot use the function "constant()" to resolve class names.'
but take any suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine. This is coming directly from https://github.com/twigphp/Twig/blob/1377f2da4efa020d2ad9b8fb8b722d688ab297ad/src/Extension/CoreExtension.php#L1474
76f73f7
to
e407dbc
Compare
e407dbc
to
1ddb1c8
Compare
No description provided.