Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -50,7 +50,7 @@ class Checkout_Steps extends Rule {
$value = maybe_unserialize($value);
} // end if;
}
$required_fields = Signup_Fields_Manager::get_instance()->get_required_fields();
@ -60,7 +60,7 @@ class Checkout_Steps extends Rule {
return true;
} // end if;
}
$fields = array_column($value, 'fields');
@ -68,7 +68,7 @@ class Checkout_Steps extends Rule {
return true;
} // end if;
}
$all_fields = call_user_func_array('array_merge', $fields);
@ -87,9 +87,9 @@ class Checkout_Steps extends Rule {
return false;
} // end if;
}
} // end if;
}
/**
* Allow developers to bypass the check if a field is auto-submittable.
@ -124,9 +124,9 @@ class Checkout_Steps extends Rule {
return false;
} // end if;
}
} // end foreach;
}
/*
* @todo: Plan, product selection fields must come before the order summary and payment fields.
@ -134,6 +134,6 @@ class Checkout_Steps extends Rule {
return true;
} // end check;
}
} // end class Checkout_Steps;
}

View File

@ -44,21 +44,15 @@ class City extends Rule {
$state = $this->parameter('state') ?? wu_request('billing_state');
if ($country && $state && $city) {
$state = strtoupper((string) $state);
$allowed_cities = wu_get_country_cities(strtoupper((string) $country), $state, false);
if (!empty($allowed_cities)) {
if (! empty($allowed_cities)) {
$check = in_array($city, $allowed_cities, true);
} // end if;
} // end if;
}
}
return $check;
} // end check;
} // end class City;
}
}

View File

@ -35,22 +35,18 @@ class Country extends Rule {
*
* @param mixed $country The country value detected.
*/
public function check($country) : bool { // phpcs:ignore
public function check($country) : bool { // phpcs:ignore
$check = true;
if ($country) {
$country = strtoupper((string) $country);
$allowed_countries = array_keys(wu_get_countries());
$check = in_array($country, $allowed_countries, true);
} // end if;
}
return $check;
} // end check;
} // end class Country;
}
}

View File

@ -46,7 +46,5 @@ class Domain extends Rule {
public function check($value) : bool { // phpcs:ignore
return (bool) preg_match('/^(?!\-)(?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', (string) $value);
} // end check;
} // end class Domain;
}
}

View File

@ -44,19 +44,19 @@ class Exists extends Rule {
*
* @param mixed $value Value being checked.
*/
public function check($value) : bool {
public function check($value): bool {
$this->requireParameters(array(
'model',
'column'
));
$this->requireParameters(
array(
'model',
'column',
)
);
$column = $this->parameter('column');
$model = $this->parameter('model');
// do query
return !!$model::get_by($column, $value);
} // end check;
} // end class Exists;
return (bool) $model::get_by($column, $value);
}
}

View File

@ -49,13 +49,13 @@ class Price_Variations extends Rule {
$value = maybe_unserialize($value);
} // end if;
}
if (!is_array($value)) {
return false;
} // end if;
}
foreach ($value as $price_variation) {
@ -68,7 +68,7 @@ class Price_Variations extends Rule {
return false;
} // end if;
}
/**
* Validation Unit
@ -86,7 +86,7 @@ class Price_Variations extends Rule {
return false;
} // end if;
}
/**
* Check if it is the same as the main duration
@ -97,7 +97,7 @@ class Price_Variations extends Rule {
return false;
} // end if;
}
/**
* Validation Amount
@ -108,18 +108,18 @@ class Price_Variations extends Rule {
$amount = wu_to_float($amount);
} // end if;
}
if (!is_numeric($amount)) {
return false;
} // end if;
}
} // end foreach;
}
return true;
} // end check;
}
} // end class Price_Variations;
}

View File

@ -43,7 +43,7 @@ class Products extends Rule {
*
* @param mixed $products Value being checked.
*/
public function check($products) : bool { // phpcs:ignore
public function check($products) : bool { // phpcs:ignore
$products = (array) $products;
@ -52,15 +52,11 @@ class Products extends Rule {
list($plan, $additional_products) = wu_segregate_products($product_objects);
if ($plan) {
return true;
} // end if;
}
$this->message = __('A plan is required.', 'wp-ultimo');
return false;
} // end check;
} // end class Products;
}
}

View File

@ -9,9 +9,9 @@
namespace WP_Ultimo\Helpers\Validation_Rules;
use \Rakit\Validation\Rule;
use \WP_Ultimo\Checkout\Checkout;
use \WP_Ultimo\Database\Sites\Site_Type;
use Rakit\Validation\Rule;
use WP_Ultimo\Checkout\Checkout;
use WP_Ultimo\Database\Sites\Site_Type;
// Exit if accessed directly
defined('ABSPATH') || exit;
@ -45,49 +45,39 @@ class Site_Template extends Rule {
*
* @param mixed $template_id Value being checked.
*/
public function check($template_id) : bool { // phpcs:ignore
public function check($template_id) : bool { // phpcs:ignore
$template_id = absint($template_id);
if (!$template_id) {
if (! $template_id) {
return true;
} // end if;
}
$site = wu_get_site($template_id);
if (!$site || ($site->get_type() !== Site_Type::SITE_TEMPLATE && $site->get_type() !== Site_Type::CUSTOMER_OWNED)) {
if (! $site || ($site->get_type() !== Site_Type::SITE_TEMPLATE && $site->get_type() !== Site_Type::CUSTOMER_OWNED)) {
$this->message = __('The Template ID does not correspond to a valid Template', 'wp-ultimo');
return false;
} // end if;
}
if ($site->get_type() === Site_Type::CUSTOMER_OWNED) {
if (!wu_get_setting('allow_own_site_as_template')) {
if (! wu_get_setting('allow_own_site_as_template')) {
$this->message = __('You can not use your sites as template', 'wp-ultimo');
return false;
} // end if;
}
$customer = wu_get_current_customer();
if (!$customer || $site->get_customer_id() !== $customer->get_id()) {
if (! $customer || $site->get_customer_id() !== $customer->get_id()) {
$this->message = __('The selected template is not available.', 'wp-ultimo');
return false;
} // end if;
}
return true;
} // end if;
}
$allowed_templates = false;
@ -96,7 +86,6 @@ class Site_Template extends Rule {
$product_ids_or_slugs = array_unique($product_ids_or_slugs);
if ($product_ids_or_slugs) {
$products = array_map('wu_get_product', $product_ids_or_slugs);
$limits = new \WP_Ultimo\Objects\Limitations();
@ -106,25 +95,19 @@ class Site_Template extends Rule {
$products = array_merge(array($plan), $additional_products);
foreach ($products as $product) {
$limits = $limits->merge($product->get_limitations());
} // end foreach;
}
$allowed_templates = $limits->site_templates->get_available_site_templates();
} // end if;
}
if (is_array($allowed_templates) && !in_array($template_id, $allowed_templates)) { // phpcs:ignore
$this->message = __('The selected template is not available for this product.', 'wp-ultimo');
return false;
} // end if;
}
return true;
} // end check;
} // end class Site_Template;
}
}

View File

@ -35,28 +35,22 @@ class State extends Rule {
*
* @param mixed $state The state value detected.
*/
public function check($state) : bool { // phpcs:ignore
public function check($state) : bool { // phpcs:ignore
$check = true;
$country = $this->parameter('country') ?? wu_request('billing_country');
if ($country && $state) {
$state = strtoupper((string) $state);
$allowed_states = array_keys(wu_get_country_states(strtoupper((string) $country), false));
if (!empty($allowed_states)) {
if (! empty($allowed_states)) {
$check = in_array($state, $allowed_states, true);
} // end if;
} // end if;
}
}
return $check;
} // end check;
} // end class State;
}
}

View File

@ -43,7 +43,7 @@ class Unique_Site extends Rule {
*
* @param mixed $value Value being checked.
*/
public function check($value) : bool { // phpcs:ignore
public function check($value) : bool { // phpcs:ignore
$this->requireParameters(array());
@ -52,15 +52,11 @@ class Unique_Site extends Rule {
$results = wpmu_validate_blog_signup($value, 'Test Title');
if ($results['errors']->has_errors()) {
$this->message = $results['errors']->get_error_message();
return false;
} // end if;
}
return true;
} // end check;
} // end class Unique_Site;
}
}

View File

@ -44,12 +44,14 @@ class Unique extends Rule {
*
* @param mixed $value Value being checked.
*/
public function check($value) : bool {
public function check($value): bool {
$this->requireParameters(array(
'model',
'column',
));
$this->requireParameters(
array(
'model',
'column',
)
);
$column = $this->parameter('column');
$model = $this->parameter('model');
@ -76,24 +78,18 @@ class Unique extends Rule {
* Customize the error message for the customer.
*/
if (in_array($model, $user_models, true)) {
$this->message = __('A customer with the same email address or username already exists.', 'wp-ultimo');
}
} // end if;
if (!$existing) {
if ( ! $existing) {
return true;
} // end if;
}
if ( $existing instanceof \WP_User) {
$id = $existing->ID;
} else {
$id = method_exists( $existing, 'get_id' ) ? $existing->get_id() : $existing->id;
$id = method_exists($existing, 'get_id') ? $existing->get_id() : $existing->id;
}
return absint($id) === absint($self_id);
} // end check;
} // end class Unique;
}
}