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

@ -208,12 +208,7 @@ abstract class Base_Model implements \JsonSerializable {
$vars = get_object_vars($object);
$this->attributes($vars);
if (empty($this->id)) {
return false;
}
return true;
return !empty($this->id);
}
/**
@ -227,7 +222,7 @@ abstract class Base_Model implements \JsonSerializable {
public function attributes($atts) {
foreach ($atts as $key => $value) {
if ($key === 'meta' && is_array($value)) {
if ('meta' === $key && is_array($value)) {
$this->meta = is_array($this->meta) ? array_merge($this->meta, $value) : $value;
}
@ -691,14 +686,8 @@ abstract class Base_Model implements \JsonSerializable {
return false;
}
if ( ! $this->get_id() && ! $this->_mocked) {
// _doing_it_wrong(__METHOD__, __('Model metadata only works for already saved models.', 'wp-ultimo'), '2.0.0');
return false;
}
return true;
// _doing_it_wrong(__METHOD__, __('Model metadata only works for already saved models.', 'wp-ultimo'), '2.0.0');
return !(! $this->get_id() && ! $this->_mocked);
}
/**
@ -1075,7 +1064,7 @@ abstract class Base_Model implements \JsonSerializable {
public function hydrate(): void {
$attributes = get_object_vars($this);
$attributes = array_filter($attributes, fn ($value) => $value === null);
$attributes = array_filter($attributes, fn ($value) => null === $value);
unset($attributes['meta']);

View File

@ -26,6 +26,7 @@ class Checkout_Form extends Base_Model {
* @var array<string, int>|array<string, string>
*/
public $meta;
/**
* The name of the checkout form.
*
@ -274,6 +275,7 @@ class Checkout_Form extends Base_Model {
$this->settings = $settings;
}
/**
* Returns a specific step by the step name.
*
@ -289,7 +291,7 @@ class Checkout_Form extends Base_Model {
$step_key = array_search($step_name, array_column($settings, 'id'), true);
$step = $step_key !== false ? $settings[ $step_key ] : false;
$step = false !== $step_key ? $settings[ $step_key ] : false;
if ($step) {
$step = wp_parse_args(
@ -303,6 +305,7 @@ class Checkout_Form extends Base_Model {
return $step;
}
/**
* Returns the steps to show in current form
*
@ -336,11 +339,11 @@ class Checkout_Form extends Base_Model {
foreach ($steps as $key => $step) {
$logged = wu_get_isset($step, 'logged', 'always');
$show = $logged === 'always';
$show = 'always' === $logged;
if ($logged === 'guests_only' && ! $user_exists) {
if ('guests_only' === $logged && ! $user_exists) {
$show = true;
} elseif ($logged === 'logged_only' && $user_exists) {
} elseif ('logged_only' === $logged && $user_exists) {
$show = true;
}
@ -369,6 +372,7 @@ class Checkout_Form extends Base_Model {
return $final_steps;
}
/**
* Returns a specific field by the step name and field name.
*
@ -388,7 +392,7 @@ class Checkout_Form extends Base_Model {
$field_key = array_search($field_name, array_column($step['fields'], 'id'), true);
return $field_key !== false ? $step['fields'][ $field_key ] : false;
return false !== $field_key ? $step['fields'][ $field_key ] : false;
}
/**
@ -488,6 +492,7 @@ class Checkout_Form extends Base_Model {
return is_array($fields) ? count($fields) : 0;
}
/**
* Returns the shortcode that needs to be placed to embed this form.
*
@ -510,11 +515,11 @@ class Checkout_Form extends Base_Model {
$fields = [];
if ($template === 'multi-step') {
if ('multi-step' === $template) {
$fields = $this->get_multi_step_template();
$this->set_settings($fields);
} elseif ($template === 'single-step') {
} elseif ('single-step' === $template) {
$fields = $this->get_single_step_template();
}
@ -811,7 +816,7 @@ class Checkout_Form extends Base_Model {
/**
* Deal with special cases.
*/
if ($step_id === 'plan') {
if ('plan' === $step_id) {
$products_list = wu_get_plans(
[
'fields' => 'ids',
@ -873,7 +878,7 @@ class Checkout_Form extends Base_Model {
/**
* Deal with special cases.
*/
if ($step_id === 'template' && wu_get_isset($old_settings, 'allow_template', true)) {
if ('template' === $step_id && wu_get_isset($old_settings, 'allow_template', true)) {
$templates = [];
foreach (wu_get_site_templates() as $site) {
@ -965,7 +970,7 @@ class Checkout_Form extends Base_Model {
$field['type'] = 'submit_button';
$field['id'] = 'submit_button';
if ($step_id === 'account') {
if ('account' === $step_id) {
$field['name'] = __('Continue to the Next Step', 'wp-ultimo');
}

View File

@ -747,7 +747,7 @@ class Customer extends Base_Model {
static $sum;
if ($sum === null) {
if (null === $sum) {
$sum = $wpdb->get_var(
$wpdb->prepare(
"SELECT SUM(total) FROM {$wpdb->base_prefix}wu_payments WHERE parent_id = 0 AND customer_id = %d",
@ -779,7 +779,7 @@ class Customer extends Base_Model {
$minutes_interval += $interval->h * 60;
$minutes_interval += $interval->i;
return $minutes_interval <= apply_filters('wu_is_online_minutes_interval', 3) ? true : false;
return $minutes_interval <= apply_filters('wu_is_online_minutes_interval', 3);
}
/**
@ -796,6 +796,7 @@ class Customer extends Base_Model {
return $this->update_meta('wu_verification_key', $hash);
}
/**
* Returns the saved verification key.
*
@ -817,6 +818,7 @@ class Customer extends Base_Model {
return $this->update_meta('wu_verification_key', false);
}
/**
* Returns the link of the email verification endpoint.
*

View File

@ -514,7 +514,7 @@ class Discount_Code extends Base_Model {
$allowed = $this->get_limit_products() && in_array($product_id, $this->get_allowed_products()); // phpcs:ignore
if ($allowed === false) {
if (false === $allowed) {
return new \WP_Error('discount_code', __('This coupon code is not valid.', 'wp-ultimo'));
}
}
@ -621,6 +621,7 @@ class Discount_Code extends Base_Model {
$this->date_created = $date_created;
}
/**
* Returns a text describing the discount code values.
*

View File

@ -151,6 +151,7 @@ class Domain extends Base_Model {
$this->domain = strtolower($domain);
}
/**
* Gets the URL with schema and all.
*
@ -200,6 +201,7 @@ class Domain extends Base_Model {
return $this->get_blog_id();
}
/**
* Get the site object for this particular mapping.
*
@ -323,6 +325,7 @@ class Domain extends Base_Model {
$this->stage = $stage;
}
/**
* Check if this domain is on a inactive stage.
*
@ -498,6 +501,7 @@ class Domain extends Base_Model {
return $results;
}
/**
* Delete the model from the database.
*
@ -559,7 +563,7 @@ class Domain extends Base_Model {
// Check cache first
$mappings = wp_cache_get('id:' . $site, 'domain_mapping');
if ($mappings === 'none') {
if ('none' === $mappings) {
return false;
}
@ -610,14 +614,14 @@ class Domain extends Base_Model {
foreach ($domains as $domain) {
$data = wp_cache_get('domain:' . $domain, 'domain_mappings');
if ( ! empty($data) && $data !== 'notexists') {
if ( ! empty($data) && 'notexists' !== $data) {
return new static($data);
} elseif ($data === 'notexists') {
} elseif ('notexists' === $data) {
++$not_exists;
}
}
if ($not_exists === count($domains)) {
if (count($domains) === $not_exists) {
// Every domain we checked was found in the cache, but doesn't exist
// so skip the query

View File

@ -198,6 +198,7 @@ class Email extends Post_Base_Model {
return $this->title;
}
/**
* Get style of the email
*
@ -381,7 +382,7 @@ class Email extends Post_Base_Model {
* @param string $type The type being set.
* @return void
*/
public function set_type($type) {
public function set_type($type): void {
if ( ! in_array($type, $this->allowed_types, true)) {
$type = 'system_email';
@ -567,9 +568,9 @@ class Email extends Post_Base_Model {
$target_type = $this->get_target();
if ($target_type === 'admin') {
if ('admin' === $target_type) {
$target_list = self::get_super_admin_targets();
} elseif ($target_type === 'customer') {
} elseif ('customer' === $target_type) {
if ( ! wu_get_isset($payload, 'customer_id')) {
return [];
}

View File

@ -22,9 +22,13 @@ defined('ABSPATH') || exit;
class Event extends Base_Model {
const SEVERITY_SUCCESS = 1;
const SEVERITY_NEUTRAL = 2;
const SEVERITY_INFO = 3;
const SEVERITY_WARNING = 4;
const SEVERITY_FATAL = 5;
/**
@ -253,6 +257,7 @@ class Event extends Base_Model {
return $this->interpolate_message($message, $this->get_payload());
}
/**
* Interpolates the value of a message and its placeholders with the contents of the payload.
*
@ -419,6 +424,7 @@ class Event extends Base_Model {
return false;
}
/**
* Polyfill for the get_object method.
*
@ -429,12 +435,13 @@ class Event extends Base_Model {
$object_type = $this->get_object_type();
if ($object_type !== 'membership') {
if ('membership' !== $object_type) {
return false;
}
return $this->get_object();
}
/**
* Polyfill for the get_object method.
*
@ -445,12 +452,13 @@ class Event extends Base_Model {
$object_type = $this->get_object_type();
if ($object_type !== 'product') {
if ('product' !== $object_type) {
return false;
}
return $this->get_object();
}
/**
* Polyfill for the get_object method.
*
@ -461,12 +469,13 @@ class Event extends Base_Model {
$object_type = $this->get_object_type();
if ($object_type !== 'site') {
if ('site' !== $object_type) {
return false;
}
return $this->get_object();
}
/**
* Polyfill for the get_object method.
*
@ -477,12 +486,13 @@ class Event extends Base_Model {
$object_type = $this->get_object_type();
if ($object_type !== 'customer') {
if ('customer' !== $object_type) {
return false;
}
return $this->get_object();
}
/**
* Polyfill for the get_object method.
*
@ -493,7 +503,7 @@ class Event extends Base_Model {
$object_type = $this->get_object_type();
if ($object_type !== 'payment') {
if ('payment' !== $object_type) {
return false;
}

View File

@ -534,6 +534,7 @@ class Membership extends Base_Model {
return ! empty($this->get_addons());
}
/**
* Gets a list of product ids for addons.
*
@ -558,7 +559,7 @@ class Membership extends Base_Model {
$has_product = wu_get_isset($this->addon_products, $product_id);
if ($has_product && $this->addon_products[ $product_id ] >= 0) {
$this->addon_products[ $product_id ] = $this->addon_products[ $product_id ] + $quantity;
$this->addon_products[ $product_id ] += $quantity;
} else {
$this->addon_products[ $product_id ] = $quantity;
}
@ -582,7 +583,7 @@ class Membership extends Base_Model {
$has_product = wu_get_isset($this->addon_products, $product_id);
if ($has_product && $this->addon_products[ $product_id ] >= 0) {
$this->addon_products[ $product_id ] = $this->addon_products[ $product_id ] - $quantity;
$this->addon_products[ $product_id ] -= $quantity;
}
if ($this->addon_products[ $product_id ] <= 0) {
@ -725,6 +726,7 @@ class Membership extends Base_Model {
*/
return $this;
}
/**
* Schedule a swap for the membership.
*
@ -836,6 +838,7 @@ class Membership extends Base_Model {
return $description;
}
/**
* Returns the times billed in a human-friendly way.
*
@ -854,6 +857,7 @@ class Membership extends Base_Model {
return sprintf($description, $this->get_times_billed(), $this->get_billing_cycles());
}
/**
* Returns the membership price structure in a way human can understand it.
*
@ -1329,6 +1333,7 @@ class Membership extends Base_Model {
$this->auto_renew = (bool) $auto_renew;
}
/**
* Get the discount code applied if exist.
*
@ -1755,6 +1760,7 @@ class Membership extends Base_Model {
return wu_get_payments($query);
}
/**
* Returns the last pending payment for a membership.
*
@ -1870,6 +1876,7 @@ class Membership extends Base_Model {
return $this->update_meta('pending_site', $site);
}
/**
* Returns the pending site, if any.
*
@ -2056,7 +2063,7 @@ class Membership extends Base_Model {
static $sum;
if ($sum === null) {
if (null === $sum) {
$sum = $wpdb->get_var(
$wpdb->prepare(
"SELECT SUM(total) FROM {$wpdb->base_prefix}wu_payments WHERE parent_id = 0 AND membership_id = %d",
@ -2364,7 +2371,7 @@ class Membership extends Base_Model {
];
foreach ($this->_gateway_info as $key => $value) {
if ($value !== $current_gateway[ $key ]) {
if ($current_gateway[ $key ] !== $value) {
$has_change = true;
break;
@ -2390,7 +2397,7 @@ class Membership extends Base_Model {
return PHP_INT_MAX;
}
$limit = $limit === '' ? 1 : $limit;
$limit = '' === $limit ? 1 : $limit;
return $limit - count($this->get_sites());
}
@ -2416,6 +2423,7 @@ class Membership extends Base_Model {
return $this->get_date_trial_end() > gmdate('Y-m-d 23:59:59');
}
/**
* Save (create or update) the model on the database.
*
@ -2497,6 +2505,7 @@ class Membership extends Base_Model {
return parent::save();
}
/**
* Delete the model from the database.
*

View File

@ -266,6 +266,7 @@ class Payment extends Base_Model {
$this->customer_id = absint($customer_id);
}
/**
* Gets the membership object associated with this payment.
*

View File

@ -487,7 +487,7 @@ class Product extends Base_Model {
$this->pricing_type = $pricing_type;
if ($pricing_type === 'free' || $pricing_type === 'contact_us') {
if ('free' === $pricing_type || 'contact_us' === $pricing_type) {
$this->set_amount(0);
$this->set_recurring(false);
@ -1210,11 +1210,11 @@ class Product extends Base_Model {
return $this;
}
if ($duration !== $this->get_duration() || $duration_unit !== $this->get_duration_unit()) {
if ($this->get_duration() !== $duration || $this->get_duration_unit() !== $duration_unit) {
$price_variation = $this->get_price_variation($duration, $duration_unit);
}
if (absint($duration) === $this->get_duration() && $duration_unit === $this->get_duration_unit()) {
if (absint($duration) === $this->get_duration() && $this->get_duration_unit() === $duration_unit) {
$price_variation = [
'amount' => $this->get_amount(),
];
@ -1297,7 +1297,7 @@ class Product extends Base_Model {
$price_variations = $this->get_price_variations();
if ( ! empty($price_variations)) {
if (absint($duration) === 12 && $duration_unit === 'month') {
if (absint($duration) === 12 && 'month' === $duration_unit) {
$duration = 1;
$duration_unit = 'year';

View File

@ -368,6 +368,7 @@ class Site extends Base_Model {
return $this->featured_image_id;
}
/**
* Get featured image url.
*
@ -420,6 +421,7 @@ class Site extends Base_Model {
return Template_Previewer::get_instance()->get_preview_url($this->get_id());
}
/**
* Get the preview URL attrs.
*
@ -496,6 +498,7 @@ class Site extends Base_Model {
$this->site_id = $site_id;
}
/**
* Get title of the site..
*
@ -593,6 +596,7 @@ class Site extends Base_Model {
$this->domain = $domain;
}
/**
* Get path of the site. Used when in sub-directory mode..
*
@ -1044,6 +1048,7 @@ class Site extends Base_Model {
return false;
}
/**
* Get template ID.
*
@ -1172,6 +1177,7 @@ class Site extends Base_Model {
$this->type = $type;
}
/**
* Get the primary mapped domain for this site.
*
@ -1421,6 +1427,7 @@ class Site extends Base_Model {
return absint($primary_site_id) === absint($this->get_id());
}
/**
* Delete the model from the database.
*
@ -1580,7 +1587,7 @@ class Site extends Base_Model {
$error = $saved;
$saved = get_blog_id_from_url($domain, $this->get_path());
if ($saved === 0 || $saved === wu_get_main_site_id()) {
if (0 === $saved || wu_get_main_site_id() === $saved) {
return $error;
}
}
@ -1744,7 +1751,7 @@ class Site extends Base_Model {
global $wpdb;
if ($type === 'pending') {
if ('pending' === $type) {
$table_name = "{$wpdb->base_prefix}wu_membershipmeta";
$customer_id = (int) wu_get_isset($query_args, 'customer_id');

View File

@ -53,7 +53,7 @@ trait Limitable {
* If this is a site, and it's not a customer owned site, we don't have limitations.
* This is because we don't want to limit sites other than the customer owned ones.
*/
if ($this->model === 'site' && $this->get_type() !== Site_Type::CUSTOMER_OWNED) {
if ('site' === $this->model && $this->get_type() !== Site_Type::CUSTOMER_OWNED) {
return new Limitations([]);
}

View File

@ -104,7 +104,7 @@ trait Notable {
$column_name = "wu_{$model}_id";
if ($model === 'site') {
if ('site' === $model) {
$table_name = "{$wpdb->base_prefix}blogmeta";
$column_name = 'blog_id';
@ -120,7 +120,7 @@ trait Notable {
$status = delete_metadata_by_mid("wu_{$model}", $mid['meta_id']);
if ($model === 'site') {
if ('site' === $model) {
$status = delete_metadata_by_mid('blog', $mid['meta_id']);
}