-
Notifications
You must be signed in to change notification settings - Fork 202
Fix warning for non-variables passed by reference #1080
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
Fix warning for non-variables passed by reference #1080
Conversation
`reset` only takes variables so we can not pass the result of `array_keys` directly but have to use an intermediate variable.
`array_key_exists('schema', $input) ? $input['schema'] : NULL` is equal to `$input['schema'] ?? NULL` on PHP versions that support the null-coalescing operator. Since we already use this elsewhere we already require such PHP versions. This allows us to substitute the simplified one-use variable leading to `$input['schema'] ?? NULL ?? $server->get('schema')`. The expression `?? NULL ??` can be safely transformed to `??` to result in the simplified expression in this commit.
Codecov Report
@@ Coverage Diff @@
## 8.x-4.x #1080 +/- ##
==========================================
Coverage ? 51.06%
Complexity ? 674
==========================================
Files ? 118
Lines ? 1837
Branches ? 0
==========================================
Hits ? 938
Misses ? 899
Partials ? 0
Continue to review full report at Codecov.
|
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.
nice code improvement
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.
Thanks, this is now the second time the server form has PHP warnings in interesting ways on different PHP versions. Before we do any further changes we need to come up with test coverage for the server form. I think a simple browser test to visit the form and configure an example server should be enough?
Can you add a test case?
I don't currently have time to write a test for this, so would hope either someone else can do that or it be moved to a follow-up :) |
While working on PHPStan level 5 it also detected this error, so will merge this without test since we will have coverage by PHPStan. |
…l-graphql#1080) * Fix notice about variables passed by reference `reset` only takes variables so we can not pass the result of `array_keys` directly but have to use an intermediate variable. * Merge variable fallback expressions `array_key_exists('schema', $input) ? $input['schema'] : NULL` is equal to `$input['schema'] ?? NULL` on PHP versions that support the null-coalescing operator. Since we already use this elsewhere we already require such PHP versions. This allows us to substitute the simplified one-use variable leading to `$input['schema'] ?? NULL ?? $server->get('schema')`. The expression `?? NULL ??` can be safely transformed to `??` to result in the simplified expression in this commit. Co-authored-by: Klaus Purer <[email protected]>
#878 made some changes already but left a
reset(array_keys())
call behind which on PHP 7.2 provides a notice when opening the ServerForm.The attached commit solves this by introducing a temporary variable. Based on feedback from PHPMD I've also simplified the expression and added a comment for people who may not be very familiar with the null-coalescing operator.