Skip to content

Commit

Permalink
Add null checks and private variables for to address PHP notices and …
Browse files Browse the repository at this point in the history
…deprecations

Added null checks in `function-coauthors.php` and `class-components.php` to prevent possible undefined behaviour when handling non-initialized variables. This makes the code more robust and resilient to potential errors. Moreover, added private string variables in `test-class-table.php` and private `Admin_Apple_Themes` variable to the `test-class-admin-apple-themes.php` which improves the readability and structure of these files.
  • Loading branch information
attackant committed Oct 30, 2023
1 parent fae3994 commit f967836
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions includes/apple-exporter/builders/class-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ private function get_components_from_node( $node ) {
*/
private function get_image_full_size_url( $url ) {

if(null === $url) {
return '';
}

// Strip URL formatting for easier matching.
$url = urldecode( $url );

Expand Down
1 change: 1 addition & 0 deletions tests/admin/test-class-admin-apple-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* A class which is used to test the Admin_Apple_Themes class.
*/
class Admin_Apple_Themes_Test extends Apple_News_Testcase {
private Admin_Apple_Themes $themes;

/**
* A helper function to create the default theme.
Expand Down
2 changes: 2 additions & 0 deletions tests/apple-exporter/components/test-class-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @subpackage Tests
*/
class Apple_News_Table_Test extends Apple_News_Component_TestCase {
private string $html;
private string $html_caption;

/**
* A fixture containing operations to be run before each test.
Expand Down
4 changes: 4 additions & 0 deletions tests/mocks/function-coauthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function coauthors( $between = ', ', $between_last = ' and ', $before = '', $aft
// Get last index.
$last_index = count( $apple_news_coauthors ) - 1;

if(null === $between) {
$between = ', ';
}

// Compute output.
$output = $before
. implode( $between, array_slice( $apple_news_coauthors, 0, $last_index ) )
Expand Down

0 comments on commit f967836

Please sign in to comment.