[8.x] Consistently negate conditions in @includeUnless() Blade directive #40077
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://twitter.com/gonedark/status/1471514212363079681
Before this change,
@includeUnless($undefined ?? true, 'template')
would result in a PHP Warning and an unexpected condition result, because$undefined ?? true
would be compiled as! $undefined ?? true
, which due to!
having precedence over??
is different than! ($undefined ?? true)
(which is how@unless
would compile it).This change necessitated the creation of
renderUnless()
, because@includeUnless()
accepts multiple arguments, and parsing out the first argument to a Blade directive is fraught. SorenderUnless()
takes the parameters as-is, and negates the condition inside the method.@includeUnless()
also lacked unit tests, which I added.This change makes
@includeUnless()
work more like@unless()
, which already correctly wraps the condition in parentheses (or rather, does not remove the parentheses that are already there).