-
Notifications
You must be signed in to change notification settings - Fork 293
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
Bug/#5110 fix php81 warnings #5968
Conversation
d6eba0f
to
a192c4c
Compare
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.
@kuasha420 I left some comments in the PR. Can you check them out? Additionally, I see some other warnings cropping up which I think we can suppress:
Since we are supporting PHP 5, I think maybe we can add the #[ReturnTypeWillChange]
attribute: https://php.watch/versions/8.1/ReturnTypeWillChange Curious to hear your thoughts @eugene-manuilov
There is also a warning here: https://github.com/google/site-kit-wp/blob/develop/includes/Modules/Thank_With_Google.php#L325 Maybe we can cast widgets
to an array
to prevent the warning.
includes/Core/Admin/Screens.php
Outdated
@@ -367,7 +367,10 @@ private function get_screens() { | |||
'render_callback' => function( Context $context ) { | |||
$is_view_only = ! $this->authentication->is_authenticated(); | |||
|
|||
$setup_slug = $context->input()->filter( INPUT_GET, 'slug', FILTER_SANITIZE_STRING ); | |||
$setup_slug = $context->input()->filter( INPUT_GET, 'slug' ); |
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.
@kuasha420 Is there a reason why we can't call htmlspecialchars
here itself? 🤔
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.
The value of slug can be empty (null) and it throws another error for calling htmlspecialchars
with null
if we don't check.
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.
In that case @kuasha420 is it possible to use the Elvis operator here to be consistent with how it's done in other places where you used htmlspecialchars
?
@@ -878,18 +878,14 @@ private function get_inline_tracking_data() { | |||
* @return array The inline data to be output. | |||
*/ | |||
private function get_inline_data() { | |||
$current_user = wp_get_current_user(); |
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!
includes/Modules/Analytics.php
Outdated
@@ -277,17 +277,17 @@ protected function handle_provisioning_callback() { | |||
} | |||
|
|||
// Check for a returned error. | |||
$error = $input->filter( INPUT_GET, 'error', FILTER_SANITIZE_STRING ); | |||
$error = htmlspecialchars( $input->filter( INPUT_GET, 'error' ) ); |
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.
@kuasha420 I think error
might be null
which in that case PHP will complain about passing null to parameter #1 ($string) of type string is deprecated
Thank you for the review, @asvinb ! The errors you mention, I am not seeing them in InstaWP. What's your php 8.1 version. Are those development only error? I have addressed your other comments. Cheers. |
Good question, @asvinb. I lean toward using the |
includes/Core/Admin/Screens.php
Outdated
@@ -367,7 +367,10 @@ private function get_screens() { | |||
'render_callback' => function( Context $context ) { | |||
$is_view_only = ! $this->authentication->is_authenticated(); | |||
|
|||
$setup_slug = $context->input()->filter( INPUT_GET, 'slug', FILTER_SANITIZE_STRING ); | |||
$setup_slug = $context->input()->filter( INPUT_GET, 'slug' ); |
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.
In that case @kuasha420 is it possible to use the Elvis operator here to be consistent with how it's done in other places where you used htmlspecialchars
?
@kuasha420 I'am on PHP 8.1.9 where i can see those errors via QueryMonitor. |
556789e
to
1578f30
Compare
@asvinb Thank you for giving me your PHP version. However, I am not seeing the same errors in my local or an InstaWP site when using PHP 8.1 and rebased to latest develop. I am seeing different errors which are similar and coming from Other than that, I've also tried to add the attribute to the methods based off of your screenshot, but not sure if that's the correct approach and the attribute comment also conflicts with phpcs rules. I have not spent much time on it but looks like we need to upgrade our php codensiffer to properly use attributes without adding bunch of phpcs ignores around it. // phpcs:disable Squiz.Commenting.InlineComment.WrongStyle,Squiz.Commenting.FunctionComment.WrongStyle, Squiz.PHP.CommentedOutCode.Found
#[\ReturnTypeWillChange]
public function offsetUnset( $key ) { Not sure how to proceed here. Cheers. |
@kuasha420 I checked there are no no longer warnings from our code. I'll let @eugene-manuilov @aaemnnosttv check the |
Yes, i think we can allow it in phpcs config file, but i am not sure how to do it. @aaemnnosttv do you know if it is feasible? |
@asvinb @eugene-manuilov Can we add the ignore inline with the attribute rather than around it? |
04ae767
to
0493f60
Compare
@aaemnnosttv I have updated the |
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.
Code looks good with just a couple of comments from me to take a look at.
I've given this another successful smoke test on a PHP 8.1 install, and the remaining work has been suitably captured in followup issues, so, minor comments aside this looks good to go.
public function offsetExists( $key ) { | ||
// phpcs:ignore Squiz.Commenting.InlineComment.WrongStyle,Squiz.PHP.CommentedOutCode.Found | ||
#[\ReturnTypeWillChange] | ||
public function offsetExists( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle |
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.
When I run phpcs
with PHP 8, these lines still raise errors:
Loosening up the rule definition allows linting to pass in PHP 8 as well as older versions.
public function offsetExists( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle | |
public function offsetExists( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment |
public function offsetGet( $key ) { | ||
// phpcs:ignore Squiz.Commenting.InlineComment.WrongStyle,Squiz.PHP.CommentedOutCode.Found | ||
#[\ReturnTypeWillChange] | ||
public function offsetGet( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle |
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.
As above
public function offsetGet( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle | |
public function offsetGet( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment |
public function offsetSet( $key, $value ) { | ||
// phpcs:ignore Squiz.Commenting.InlineComment.WrongStyle,Squiz.PHP.CommentedOutCode.Found | ||
#[\ReturnTypeWillChange] | ||
public function offsetSet( $key, $value ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle |
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.
As above
public function offsetSet( $key, $value ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle | |
public function offsetSet( $key, $value ) { // phpcs:ignore Squiz.Commenting.FunctionComment |
public function offsetUnset( $key ) { | ||
// phpcs:ignore Squiz.Commenting.InlineComment.WrongStyle,Squiz.PHP.CommentedOutCode.Found | ||
#[\ReturnTypeWillChange] | ||
public function offsetUnset( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle |
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.
As above
public function offsetUnset( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment.WrongStyle | |
public function offsetUnset( $key ) { // phpcs:ignore Squiz.Commenting.FunctionComment |
|
||
$_GET['dirty'] = '<script>dirt</script>'; | ||
$this->assertEquals( 'dirt', $context->input()->filter( INPUT_GET, 'dirty', FILTER_SANITIZE_STRING ) ); | ||
$this->assertEquals( '<script>dirt</script>', htmlspecialchars( $context->input()->filter( INPUT_GET, 'dirty' ) ) ); |
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.
This test doesn't seem so useful now as it's effectively just testing the standard htmlspecialchars
function. I'd suggest it should be removed.
$_GET['dirty'] = '<script>dirt</script>'; | |
$this->assertEquals( 'dirt', $context->input()->filter( INPUT_GET, 'dirty', FILTER_SANITIZE_STRING ) ); | |
$this->assertEquals( '<script>dirt</script>', htmlspecialchars( $context->input()->filter( INPUT_GET, 'dirty' ) ) ); |
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 one @kuasha420, LGTM!
Summary
Addresses issue:
Relevant technical choices
The remaining
strpos
andstr_replace
errors are related to how we useadd_submenu_page
and will be addressed in #5998.The remaining
rtrim
errors are caused byload_script_textdomain
function and we are consuming the function correctly in our code. It's something that will probably be fixed in Core.PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist