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

View File

@ -114,7 +114,7 @@ function wu_array_recursive_diff($array1, $array2, $to_keep = []) {
if (count($array_recursive_diff)) {
$arr_return[ $key ] = $array_recursive_diff;
}
} elseif ((! is_null($value) && $value != $array2[ $key ]) || ($value && $array2[ $key ] && in_array($key, $to_keep, true))) {
} elseif ((! is_null($value) && $array2[ $key ] != $value) || ($value && $array2[ $key ] && in_array($key, $to_keep, true))) {
// phpcs:ignore
$arr_return[ $key ] = $value;
@ -126,6 +126,7 @@ function wu_array_recursive_diff($array1, $array2, $to_keep = []) {
return $arr_return;
}
/**
* Array map implementation to deal with keys.
*

View File

@ -37,6 +37,7 @@ function wu_get_checkout_forms($query = []) {
return \WP_Ultimo\Models\Checkout_Form::query($query);
}
/**
* Returns a checkout_form based on slug.
*
@ -56,7 +57,7 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
*
* @see wu_checkout_form_membership_change_form_fields filter.
*/
if ($checkout_form_slug === 'wu-checkout') {
if ('wu-checkout' === $checkout_form_slug) {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::membership_change_form_fields();
@ -64,7 +65,7 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
$checkout_form->set_settings($checkout_fields);
return $checkout_form;
} elseif ($checkout_form_slug === 'wu-add-new-site') {
} elseif ('wu-add-new-site' === $checkout_form_slug) {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::add_new_site_form_fields();
@ -72,7 +73,7 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
$checkout_form->set_settings($checkout_fields);
return $checkout_form;
} elseif ($checkout_form_slug === 'wu-finish-checkout') {
} elseif ('wu-finish-checkout' === $checkout_form_slug) {
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
$checkout_fields = Checkout_Form::finish_checkout_form_fields();
@ -84,6 +85,7 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
return \WP_Ultimo\Models\Checkout_Form::get_by('slug', $checkout_form_slug);
}
/**
* Creates a new checkout form.
*

View File

@ -97,12 +97,12 @@ function wu_create_checkout_fields($fields = []) {
*/
$visibility = wu_get_isset($field, 'logged', 'always');
if ($visibility !== 'always') {
if ($visibility === 'guests_only' && is_user_logged_in()) {
if ('always' !== $visibility) {
if ('guests_only' === $visibility && is_user_logged_in()) {
continue;
}
if ($visibility === 'logged_only' && ! is_user_logged_in()) {
if ('logged_only' === $visibility && ! is_user_logged_in()) {
continue;
}
}
@ -174,6 +174,7 @@ function wu_get_registration_url($path = false) {
return $url . $path;
}
/**
* Returns the URL for the login page.
*

View File

@ -23,6 +23,7 @@ function wu_get_customer($customer_id) {
return \WP_Ultimo\Models\Customer::get_by_id($customer_id);
}
/**
* Returns a single customer defined by a particular column and value.
*
@ -36,6 +37,7 @@ function wu_get_customer_by($column, $value) {
return \WP_Ultimo\Models\Customer::get_by($column, $value);
}
/**
* Gets a customer based on the hash.
*
@ -83,6 +85,7 @@ function wu_get_customers($query = []) {
return \WP_Ultimo\Models\Customer::query($query);
}
/**
* Returns a customer based on user_id.
*
@ -95,6 +98,7 @@ function wu_get_customer_by_user_id($user_id) {
return \WP_Ultimo\Models\Customer::get_by('user_id', $user_id);
}
/**
* Returns the current customer.
*
@ -105,6 +109,7 @@ function wu_get_current_customer() {
return wu_get_customer_by_user_id(get_current_user_id());
}
/**
* Creates a new customer.
*
@ -154,7 +159,7 @@ function wu_create_customer($customer_data) {
return $user_id;
}
if ($user_id === false) {
if (false === $user_id) {
return new \WP_Error('user', __('We were not able to create a new user with the provided username and email address combination.', 'wp-ultimo'), $customer_data);
}
} else {

View File

@ -127,6 +127,7 @@ function wu_filter_duration_unit($unit, $length) {
return $new_unit;
}
/**
* Get the human time diff.
*
@ -148,7 +149,7 @@ function wu_human_time_diff($from, $limit = '-5 days', $to = false): string {
return sprintf(__('on %s', 'wp-ultimo'), date_i18n(get_option('date_format'), $timestamp_from));
}
if ($to === false) {
if (false === $to) {
$to = wu_get_current_time('timestamp'); // phpcs:ignore
}

View File

@ -23,6 +23,7 @@ function wu_get_discount_code_by_code($coupon_code) {
return \WP_Ultimo\Models\Discount_Code::get_by('code', $coupon_code);
}
/**
* Gets a discount code based on the ID.
*
@ -48,6 +49,7 @@ function wu_get_discount_codes($query = []) {
return \WP_Ultimo\Models\Discount_Code::query($query);
}
/**
* Calculates the discounted price after running it through the discount code.
*
@ -61,9 +63,9 @@ function wu_get_discount_codes($query = []) {
*/
function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
if ($type === 'percentage') {
if ('percentage' === $type) {
$discounted_price = $base_price - ($base_price * ($amount / 100));
} elseif ($type === 'absolute') {
} elseif ('absolute' === $type) {
$discounted_price = $base_price - $amount;
}
@ -73,6 +75,7 @@ function wu_get_discounted_price($base_price, $amount, $type, $format = true) {
return number_format((float) $discounted_price, 2);
}
/**
* Creates a new discount code.
*

View File

@ -36,6 +36,7 @@ function wu_get_domains($query = []) {
return \WP_Ultimo\Models\Domain::query($query);
}
/**
* Returns a domain based on domain.
*
@ -48,6 +49,7 @@ function wu_get_domain_by_domain($domain) {
return \WP_Ultimo\Models\Domain::get_by('domain', $domain);
}
/**
* Creates a new domain.
*

View File

@ -95,6 +95,7 @@ function wu_get_events($query = []) {
return \WP_Ultimo\Models\Event::query($query);
}
/**
* Gets a event on the ID.
*
@ -107,6 +108,7 @@ function wu_get_event($event_id) {
return \WP_Ultimo\Models\Event::get_by_id($event_id);
}
/**
* Returns a event based on slug.
*
@ -119,6 +121,7 @@ function wu_get_event_by_slug($event_slug) {
return \WP_Ultimo\Models\Event::get_by('slug', $event_slug);
}
/**
* Creates a new event.
*
@ -199,7 +202,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
}
}
if ($model_name === 'customer') {
if ('customer' === $model_name) {
$payload = $model->to_search_results();
$payload = [
@ -217,7 +220,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
]
),
];
} elseif ($model_name === 'membership') {
} elseif ('membership' === $model_name) {
$payload = $model->to_search_results();
$p = $payload;
@ -241,7 +244,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
]
),
];
} elseif ($model_name === 'product') {
} elseif ('product' === $model_name) {
$payload = $model->to_search_results();
$payload = [
@ -260,7 +263,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
]
),
];
} elseif ($model_name === 'payment') {
} elseif ('payment' === $model_name) {
$payload = $model->to_search_results();
$payload = [
@ -285,7 +288,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
]
),
];
} elseif ($model_name === 'site') {
} elseif ('site' === $model_name) {
$payload = $model->to_search_results();
$payload = [
@ -301,7 +304,7 @@ function wu_generate_event_payload($model_name, $model = false): array {
]
),
];
} elseif ($model_name === 'domain') {
} elseif ('domain' === $model_name) {
$payload = $model->to_search_results();
$payload = [

View File

@ -61,7 +61,7 @@ function wu_maybe_create_folder($folder, ...$path) {
if ( ! file_exists($htaccess)) {
$fp = @fopen($htaccess, 'w');
@fputs($fp, 'deny from all'); // phpcs:ignore
@fwrite($fp, 'deny from all'); // phpcs:ignore
@fclose($fp); // phpcs:ignore
}
@ -72,7 +72,7 @@ function wu_maybe_create_folder($folder, ...$path) {
if ( ! file_exists($index)) {
$fp = @fopen($index, 'w');
@fputs($fp, ''); // phpcs:ignore
@fwrite($fp, ''); // phpcs:ignore
@fclose($fp); // phpcs:ignore
}

View File

@ -100,7 +100,7 @@ function wu_get_gateway_as_options() {
foreach (wu_get_gateways() as $gateway_slug => $gateway) {
$instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false;
if ($instance === false || $gateway['hidden']) {
if (false === $instance || $gateway['hidden']) {
continue;
}
@ -123,7 +123,7 @@ function wu_get_active_gateway_as_options() {
foreach (wu_get_active_gateways() as $gateway_slug => $gateway) {
$instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false;
if ($instance === false || $gateway['hidden']) {
if (false === $instance || $gateway['hidden']) {
continue;
}

View File

@ -98,6 +98,7 @@ function wu_slugify($term) {
return "wp-ultimo_$term";
}
/**
* Returns the full path to the plugin folder.
*
@ -168,7 +169,7 @@ function wu_are_code_comments_available() {
static $res;
if ($res === null) {
if (null === $res) {
$res = (bool) (new \ReflectionFunction(__FUNCTION__))->getDocComment();
}
@ -184,7 +185,7 @@ function wu_are_code_comments_available() {
*/
function wu_path_join(...$parts): string {
if (sizeof($parts) === 0) {
if (count($parts) === 0) {
return '';
}
@ -255,6 +256,7 @@ function wu_get_function_caller($depth = 1) {
return $caller;
}
/**
* Checks if a particular plugin is skipped in a CLI context.
*

View File

@ -382,8 +382,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
case 'checkbox':
$checked = isset($field['check_if']) && isset($result[$field['check_if']])
|| (isset($field['check_if']) && isset($_POST[$field['check_if']]) && $_POST[$field['check_if']])
|| (isset($field['checked']) && $field['checked'])
? true : false;
|| (isset($field['checked']) && $field['checked']);
?>
<p>

View File

@ -54,6 +54,7 @@ function wu_remove_empty_p($content): ?string {
return preg_replace('#<p>(\s|&nbsp;)*+(<br\s*/*>)*(\s|&nbsp;)*</p>#i', '', $content);
}
/**
* Generates a string containing html attributes to be used inside html tags.
*
@ -107,6 +108,7 @@ function wu_tooltip($tooltip, $icon = 'dashicons-editor-help') {
return $markup;
}
/**
* Adds a tooltip to a HTML element. Needs to be echo'ed.
*
@ -118,6 +120,7 @@ function wu_tooltip_text($tooltip): string {
return sprintf('role="tooltip" aria-label="%s"', esc_attr($tooltip));
}
/**
* Adds a preview tag that displays the image passed on hover.
*

View File

@ -26,6 +26,7 @@ function wu_get_membership($membership_id) {
return Membership::get_by_id($membership_id);
}
/**
* Returns a single membership defined by a particular column and value.
*
@ -39,6 +40,7 @@ function wu_get_membership_by($column, $value) {
return Membership::get_by($column, $value);
}
/**
* Gets a membership based on the hash.
*
@ -79,6 +81,7 @@ function wu_get_memberships($query = []) {
return Membership::query($query);
}
/**
* Creates a new membership.
*
@ -165,6 +168,7 @@ function wu_get_membership_customers($product_id) {
return $results;
}
/**
* Returns a membership based on the customer gateway ID.
*
@ -267,6 +271,7 @@ function wu_get_membership_product_price($membership, $product_id, $quantity, $o
return $temp_payment->get_total();
}
/**
* Creates a new payment for a membership.
*

View File

@ -81,7 +81,7 @@ function wu_model_get_required_fields($class_name) {
$validation_rules = (new $class_name())->validation_rules();
foreach ($validation_rules as $field => $validation_rule) {
if (str_contains((string) $validation_rule, 'required|') || $validation_rule === 'required') {
if (str_contains((string) $validation_rule, 'required|') || 'required' === $validation_rule) {
$required_fields[] = $field;
}
}

View File

@ -119,7 +119,7 @@ function wu_is_login_page() {
$is_login_element_present = \WP_Ultimo\UI\Login_Form_Element::get_instance()->is_actually_loaded();
$is_default_wp_login = $pagenow === 'wp-login.php';
$is_default_wp_login = 'wp-login.php' === $pagenow;
return $is_login_element_present || $is_default_wp_login;
}

View File

@ -59,6 +59,7 @@ function wu_get_line_item($line_item_id, $payment_id) {
return wu_get_isset($line_items, $line_item_id, false);
}
/**
* Gets a payment based on the hash.
*
@ -71,6 +72,7 @@ function wu_get_payment_by_hash($hash) {
return \WP_Ultimo\Models\Payment::get_by_hash($hash);
}
/**
* Returns a single payment defined by a particular column and value.
*
@ -84,6 +86,7 @@ function wu_get_payment_by($column, $value) {
return \WP_Ultimo\Models\Payment::get_by($column, $value);
}
/**
* Creates a new payment.
*

View File

@ -91,6 +91,7 @@ function wu_get_product_by_slug($product_slug) {
return Product::get_by('slug', $product_slug);
}
/**
* Returns a single product defined by a particular column and value.
*
@ -151,6 +152,7 @@ function wu_create_product($product_data) {
return is_wp_error($saved) ? $saved : $product;
}
/**
* Returns a list of available product groups.
*

View File

@ -58,7 +58,7 @@ function wu_rest_get_endpoint_schema($class_name, $context = 'create', $force_ge
$from_cache = true;
}
if (empty($schema) && $from_cache === false && $force_generate) {
if (empty($schema) && false === $from_cache && $force_generate) {
$schema = wu_rest_generate_schema($class_name, $context);
}
@ -83,7 +83,7 @@ function wu_rest_generate_schema($class_name, $context = 'create') {
foreach ($schema as $argument_name => &$argument) {
$argument['type'] = wu_rest_treat_argument_type($argument['type']);
$argument['required'] = $context === 'create' ? in_array($argument_name, $required_fields, true) : false;
$argument['required'] = 'create' === $context ? in_array($argument_name, $required_fields, true) : false;
$schema[ $argument_name ] = $argument;
}
@ -103,11 +103,11 @@ function wu_rest_treat_argument_type($type) {
$type = (string) $type;
if ($type === 'bool') {
if ('bool' === $type) {
$type = 'boolean';
} elseif ($type === 'int') {
} elseif ('int' === $type) {
$type = 'integer';
} elseif ($type === 'float') {
} elseif ('float' === $type) {
$type = 'number';
}

View File

@ -100,7 +100,7 @@ function wu_register_settings_field($section_slug, $field_slug, $atts, $priority
*/
function wu_register_settings_side_panel($section_slug, $atts) {
if (wu_request('tab', 'general') !== $section_slug && $section_slug !== 'all') {
if (wu_request('tab', 'general') !== $section_slug && 'all' !== $section_slug) {
return;
}

View File

@ -32,6 +32,7 @@ function wu_get_site($id) {
return \WP_Ultimo\Models\Site::get_by_id($id);
}
/**
* Gets a site based on the hash.
*
@ -116,6 +117,7 @@ function wu_handle_site_domain($domain) {
return (object) $parsed;
}
/**
* Creates a new site.
*

View File

@ -52,6 +52,7 @@ function wu_get_tax_category($tax_category = 'default') {
]
);
}
/**
* Returns the tax categories as a slug => name array.
*
@ -61,6 +62,7 @@ function wu_get_tax_categories_as_options(): array {
return array_map(fn($item) => $item['name'], wu_get_tax_categories());
}
/**
* Calculates the tax value.
*
@ -80,7 +82,7 @@ function wu_get_tax_amount($base_price, $amount, $type, $format = true, $inclusi
*/
$tax_total = $amount;
if ($type === 'percentage') {
if ('percentage' === $type) {
if ( ! $inclusive) {
/**
@ -159,14 +161,14 @@ function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state
/*
* Step 1: The country.
*/
if ($key === 'country' && $rate['country'] === $country) {
if ('country' === $key && $rate['country'] === $country) {
$priority += 10;
}
/*
* Step 2: The state / province
*/
if ($key === 'state' && $state !== '*') {
if ('state' === $key && '*' !== $state) {
if (in_array($state, $value, true)) {
$priority += 1;
} elseif (empty($value) || in_array('*', $value, true)) {
@ -177,7 +179,7 @@ function wu_get_applicable_tax_rates($country, $tax_category = 'default', $state
/*
* Step 3: The city
*/
if ($key === 'city' && $city !== '*') {
if ('city' === $key && '*' !== $city) {
if (in_array($city, $value, true)) {
/*
* If it's a full match, gives 1 point.