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

fix/270: undefined array offset #292

Merged
merged 4 commits into from
May 23, 2022
Merged

fix/270: undefined array offset #292

merged 4 commits into from
May 23, 2022

Conversation

Sidsector9
Copy link
Contributor

@Sidsector9 Sidsector9 commented May 21, 2022

Description of the Change

This PR checks if the value returned by transient is an array before accessing an offset.
Also replaces the deprecated filter block_categories with block_categories_all

Closes #270

Verification Process

  1. Set WP_DEBUG and WP_DEBUG_LOG to true
  2. Using develop, open a page that uses the Sophi Automation Block
  3. Delete all transients (wp transient delete --all) and reload the page
  4. Observe the error on the page
  5. Checkout to branch fix/270 and repeat (3)
  6. Observe the error no longer exists on the page

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Fixed: replace deprecated block_categories filter with block_categories_all.
Fixed: fix warning shown due to access of undefined array

Credits

Props @Sidsector9

@Sidsector9 Sidsector9 requested a review from cadic May 21, 2022 10:10
@Sidsector9 Sidsector9 self-assigned this May 21, 2022
@jeffpaul jeffpaul added this to the 1.1.3 milestone May 21, 2022
Copy link
Contributor

@cadic cadic left a comment

Choose a reason for hiding this comment

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

@Sidsector9 thank you for the fix. Loogs good, just a concern about the better approach to test array offset

@@ -176,7 +176,7 @@ private function set_status( $data ) {
);

if ( empty( $data['success'] ) ) {
$data['retry'] = $this->status['retry'] + 1;
$data['retry'] = is_array( $this->status ) ? $this->status['retry'] + 1 : 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Despite the fact that checking $this->status is array will resolve the issue, but it still a potential warning if retry offset doesn't exist in the array. Could we check for isset( $this->status['retry'] )?

Copy link
Contributor Author

@Sidsector9 Sidsector9 May 22, 2022

Choose a reason for hiding this comment

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

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jeffpaul jeffpaul merged commit 13e86c6 into develop May 23, 2022
@jeffpaul jeffpaul deleted the fix/270 branch May 23, 2022 14:06
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.

Warning on displaying the page with Sophi Block
3 participants