Everywhere yoda conditions are

This commit is contained in:
David Stone
2025-02-09 00:20:10 -07:00
parent d74f6d1a53
commit be0ab98895
213 changed files with 691 additions and 412 deletions
inc
admin-pages
api
checkout
class-ajax.phpclass-api.phpclass-async-calls.phpclass-dashboard-widgets.phpclass-domain-mapping.phpclass-geolocation.phpclass-logger.phpclass-requirements.phpclass-session-cookie.phpclass-settings.phpclass-sunrise.phpclass-user-switching.php
compat
country
database
debug
deprecated
development
domain-mapping
duplication
functions
gateways
helpers
installers
integrations
limitations
limits
list-tables
managers
models
objects
site-templates
sso
tax
traits
ui
views
admin-pages
checkout
templates
order-bump
order-summary
period-selection
pricing-table
dashboard-statistics
dashboard-widgets
legacy
settings

@@ -240,7 +240,7 @@ abstract class Base_Admin_Page {
global $submenu;
if ($this->get_submenu_title() && $this->type === 'menu' && isset($submenu[ $this->id ]) && $submenu[ $this->id ][0][3] === $this->get_title()) {
if ($this->get_submenu_title() && 'menu' === $this->type && isset($submenu[ $this->id ]) && $submenu[ $this->id ][0][3] === $this->get_title()) {
$submenu[ $this->id ][0][0] = $this->get_submenu_title();
}
}
@@ -416,7 +416,7 @@ abstract class Base_Admin_Page {
/**
* Create the admin page or sub-page
*/
$this->page_hook = $this->type === 'menu' ? $this->add_toplevel_menu_page() : $this->add_submenu_page();
$this->page_hook = 'menu' === $this->type ? $this->add_toplevel_menu_page() : $this->add_submenu_page();
/**
* Add the default hooks

@@ -196,7 +196,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
*/
public function handle_edit_page(): void {
$settings_to_save = wu_request('submit') !== 'restore' ? $_POST : []; // don't worry, this gets cleaned later on.
$settings_to_save = 'restore' !== wu_request('submit') ? $_POST : []; // don't worry, this gets cleaned later on.
$this->save_page_settings($settings_to_save);
@@ -413,7 +413,7 @@ abstract class Base_Customer_Facing_Admin_Page extends Base_Admin_Page {
*/
public function save_settings($meta_id, $user_id, $meta_key, $_meta_value): void {
if (wu_request('action') !== 'meta-box-order') {
if ('meta-box-order' !== wu_request('action')) {
return;
}

@@ -195,7 +195,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
</div>";
break;
case $targets_count === 1:
case 1 === $targets_count:
$customer = wu_get_customer($targets[0]);
$url_atts = [

@@ -118,7 +118,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
$display_targets = [];
if ($targets) {
if ($target_type === 'customers') {
if ('customers' === $target_type) {
foreach ($targets as $key => $value) {
$customer = wu_get_customer($value);
@@ -149,7 +149,7 @@ class Broadcast_List_Admin_Page extends List_Admin_Page {
}
}
if ($target_type === 'products') {
if ('products' === $target_type) {
foreach ($targets as $key => $value) {
$product = wu_get_product($value);

@@ -187,7 +187,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page {
$preview_type = wu_request('type', 'user');
if ($preview_type === 'visitor') {
if ('visitor' === $preview_type) {
global $current_user;
$current_user = wp_set_current_user(0);
@@ -549,13 +549,13 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page {
]
);
if ($default_field_slug === 'name' || $default_field_slug === 'id' || $default_field_slug === 'default_value') {
if ('name' === $default_field_slug || 'id' === $default_field_slug || 'default_value' === $default_field_slug) {
unset($default_field['wrapper_html_attr']['v-if']);
$default_field['wrapper_html_attr']['v-show'] = sprintf('type && require("type", %s) && require("tab", "%s")', json_encode($reqs), $tab);
}
if ($default_field_slug === 'id') {
if ('id' === $default_field_slug) {
$default_field['html_attr']['v-bind:required'] = sprintf('type && require("type", %s) && require("tab", "content")', json_encode($reqs));
}
}
@@ -701,7 +701,7 @@ class Checkout_Form_Edit_Admin_Page extends Edit_Admin_Page {
$state = array_map(
function ($value) {
if ($value === 'false' || $value === 'true') {
if ('false' === $value || 'true' === $value) {
$value = (int) wu_string_to_bool($value);
}

@@ -623,6 +623,7 @@ class Discount_Code_Edit_Admin_Page extends Edit_Admin_Page {
return $this->object;
}
/**
* Discount_Codes have titles.
*

@@ -511,6 +511,7 @@ class Domain_Edit_Admin_Page extends Edit_Admin_Page {
return $this->object;
}
/**
* Domains have titles.
*

@@ -367,7 +367,7 @@ abstract class Edit_Admin_Page extends Base_Admin_Page {
$show_modified = wu_get_isset($atts, 'modified', true);
if ($this->edit && $show_modified === true) {
if ($this->edit && true === $show_modified) {
$atts['fields']['date_modified'] = [
'title' => __('Last Modified at', 'wp-ultimo'),
'type' => 'text-display',

@@ -496,7 +496,7 @@ class Email_Edit_Admin_Page extends Edit_Admin_Page {
*/
public function handle_page_redirect($page): void {
if ($page->get_id() === 'wp-ultimo-edit-email') {
if ('wp-ultimo-edit-email' === $page->get_id()) {
if (wu_request('test_notice')) {
$test_notice = wu_request('test_notice');

@@ -276,6 +276,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
exit;
}
/**
* Events have titles.
*
@@ -285,6 +286,7 @@ class Event_View_Admin_Page extends Edit_Admin_Page {
return false;
}
/**
* Handles the save of this form.
*

@@ -26,6 +26,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
* @var bool
*/
public $has_search;
/**
* The id/name/slug of the object being edited/created. e.g: plan
*
@@ -209,7 +210,7 @@ abstract class List_Admin_Page extends Base_Admin_Page {
*/
public function save_screen_option($value, $option, $other_value) {
return $value === false && is_numeric($other_value) ? (int) $other_value : $value;
return false === $value && is_numeric($other_value) ? (int) $other_value : $value;
}
/**

@@ -1120,6 +1120,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page {
return $this->object;
}
/**
* Memberships have titles.
*
@@ -1129,6 +1130,7 @@ class Membership_Edit_Admin_Page extends Edit_Admin_Page {
return false;
}
/**
* Handle convert to lifetime.
*

@@ -537,7 +537,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
*/
$type = wu_request('type', 'product');
if ($type === 'product') {
if ('product' === $type) {
$product = wu_get_product(wu_request('product_id'));
if (empty($product)) {
@@ -1270,7 +1270,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
static $payment;
if ($payment !== null) {
if (null !== $payment) {
return $payment;
}
@@ -1292,6 +1292,7 @@ class Payment_Edit_Admin_Page extends Edit_Admin_Page {
return new Payment();
}
/**
* Payments have titles.
*

@@ -1050,6 +1050,7 @@ class Product_Edit_Admin_Page extends Edit_Admin_Page {
return $this->object;
}
/**
* Products have titles.
*

@@ -520,7 +520,7 @@ class Settings_Admin_Page extends Wizard_Admin_Page {
wp_die(__('You do not have the permissions required to change settings.', 'wp-ultimo'));
}
if ( ! isset($_POST['active_gateways']) && wu_request('tab') === 'payment-gateways') {
if ( ! isset($_POST['active_gateways']) && 'payment-gateways' === wu_request('tab')) {
$_POST['active_gateways'] = [];
}

@@ -735,9 +735,9 @@ class Setup_Wizard_Admin_Page extends Wizard_Admin_Page {
$step = wu_request('step');
if ($step === 'your-company') {
if ('your-company' === $step) {
$fields_to_save = $this->get_general_settings();
} elseif ($step === 'payment-gateways') {
} elseif ('payment-gateways' === $step) {
$fields_to_save = $this->get_payment_settings();
} else {
return;

@@ -738,6 +738,7 @@ class Site_Edit_Admin_Page extends Edit_Admin_Page {
return $this->object;
}
/**
* Sites have titles.
*

@@ -239,7 +239,7 @@ class Site_List_Admin_Page extends List_Admin_Page {
$domain_type = wu_request('tab', is_subdomain_install() ? 'sub-domain' : 'sub-directory');
if ($domain_type === 'domain') {
if ('domain' === $domain_type) {
$domain = wu_request('domain', '');
$path = '/';
} else {

@@ -630,7 +630,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// Finally get the correct version number
$known = ['Version', $browser_name_short, 'other'];
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
$pattern = '#(?<browser>' . implode('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if ( ! preg_match_all($pattern, (string) $user_agent, $matches)) {
// We have no matching number just continue
@@ -639,7 +639,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
// See how many we have
$i = count($matches['browser']);
if ($i !== 1) {
if (1 !== $i) {
// We will have two since we are not using 'other' argument yet
// See if version is before or after the name
@@ -695,6 +695,7 @@ class System_Info_Admin_Page extends Base_Admin_Page {
return (array) get_option('active_plugins', []);
}
/**
* Get memory usage
*/

@@ -322,7 +322,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
$action = wu_request('submit_button', 'none');
if ($action === 'none') {
if ('none' === $action) {
WP_Ultimo()->notices->add(__('Something wrong happened', 'wp-ultimo'), 'error', 'network-admin');
return;
@@ -336,7 +336,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
return;
}
if ($action === 'download') {
if ('download' === $action) {
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
header('Content-Type: application/octet-stream');
@@ -346,7 +346,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
readfile($file);
exit;
} elseif ($action === 'delete') {
} elseif ('delete' === $action) {
$status = unlink($file);
if ( ! $status) {

@@ -367,6 +367,7 @@ class Webhook_Edit_Admin_Page extends Edit_Admin_Page {
return new Webhook();
}
/**
* Webhooks have titles.
*

@@ -110,7 +110,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
$this->register_page_settings();
if ($this->current_site->get_type() === 'customer_owned') {
if ('customer_owned' === $this->current_site->get_type()) {
parent::__construct();
add_action('admin_menu', [$this, 'unset_default_my_sites_menu']);
@@ -187,7 +187,7 @@ class My_Sites_Admin_Page extends Base_Customer_Facing_Admin_Page {
*/
public function force_screen_options(): void {
if (get_current_screen()->id !== 'toplevel_page_sites') {
if ('toplevel_page_sites' !== get_current_screen()->id) {
return;
}