Skip to content
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

Merged
merged 2 commits into from
Jul 23, 2024
Merged

Add test for ValidConstantFunctionRule #282

merged 2 commits into from
Jul 23, 2024

Conversation

VincentLanglet
Copy link
Owner

No description provided.

@@ -7,4 +7,6 @@
{{ constant('ThisDoesNotExist::SomeKey') }}
{{ constant(someVar) }}
{{ constant('ThisDoesNotExist::class') }}
{{ constant(1) }}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruudk you wrote in your initial PR bffffcb

        $constant = $argument->getAttribute('value');
        if (!\is_string($constant)) {
            return $node;
        }

Is there valid case when the value is not a string or should we display an error for this case ?

Copy link
Contributor

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.

Copy link
Contributor

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-commenter
Copy link

codecov-commenter commented Jul 21, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5846e15) to head (1ddb1c8).

❗ 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.
📢 Have feedback on the report? Share it here.

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),
Copy link
Owner Author

@VincentLanglet VincentLanglet Jul 21, 2024

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VincentLanglet VincentLanglet marked this pull request as ready for review July 22, 2024 07:53
@VincentLanglet VincentLanglet merged commit 388f5c2 into main Jul 23, 2024
18 checks passed
@VincentLanglet VincentLanglet deleted the constantRule branch July 23, 2024 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants