From c25bd7d8a2017a9eb405b9c149e98cec2ef3a265 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Sun, 2 May 2021 20:00:55 +0100 Subject: [PATCH] refactor: change OrIfs to early returns --- src/admin/layout/class-engine.php | 5 ++--- src/includes/class-convert.php | 5 ++++- src/includes/class-template.php | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/admin/layout/class-engine.php b/src/admin/layout/class-engine.php index 6e29e20..da6004d 100644 --- a/src/admin/layout/class-engine.php +++ b/src/admin/layout/class-engine.php @@ -572,8 +572,8 @@ abstract class Engine { $p_in_min, $p_int_max ); - } else { - return sprintf( + } + return sprintf( '', $l_arr_data['name'], $l_arr_data['id'], @@ -581,7 +581,6 @@ abstract class Engine { $p_in_min, $p_int_max ); - } } } diff --git a/src/includes/class-convert.php b/src/includes/class-convert.php index 16be82d..9390037 100644 --- a/src/includes/class-convert.php +++ b/src/includes/class-convert.php @@ -185,7 +185,10 @@ class Convert { $p_int_index = (int) $p_int_index; } // Return the whole arrow array. - if ( $p_int_index < 0 || $p_int_index > count( $l_arr_arrows ) ) { + if ($p_int_index < 0) { + return $l_arr_arrows; + } + if ($p_int_index > count( $l_arr_arrows )) { return $l_arr_arrows; } // Return a single arrow. diff --git a/src/includes/class-template.php b/src/includes/class-template.php index 83fd66d..b8f91dc 100644 --- a/src/includes/class-template.php +++ b/src/includes/class-template.php @@ -81,10 +81,12 @@ class Template { */ public function __construct( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ) { // No template file type and/or file name set. - if ( empty( $p_str_file_type ) || empty( $p_str_file_name ) ) { + if (empty( $p_str_file_type )) { + return; + } + if (empty( $p_str_file_name )) { return; } - $this->plugin_directory = plugin_dir_path( __DIR__ ); $template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension );