Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions inc/models/class-base-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
* @since 2.0.0
* @var Base_Model
*/
protected $_original;

Check warning on line 120 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_original" should not be prefixed with an underscore to indicate visibility

Check warning on line 120 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_original" should not be prefixed with an underscore to indicate visibility

/**
* Map setters to other parameters.
Expand All @@ -125,7 +125,7 @@
* @since 2.0.0
* @var array
*/
protected $_mappings = [];

Check warning on line 128 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_mappings" should not be prefixed with an underscore to indicate visibility

Check warning on line 128 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_mappings" should not be prefixed with an underscore to indicate visibility

/**
* Mocked status. Used to suppress errors.
Expand All @@ -133,7 +133,7 @@
* @since 2.0.0
* @var boolean
*/
public $_mocked = false;

Check warning on line 136 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_mocked" should not be prefixed with an underscore to indicate visibility

Check warning on line 136 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Property name "$_mocked" should not be prefixed with an underscore to indicate visibility

/**
* Constructs the object via the constructor arguments
Expand Down Expand Up @@ -300,7 +300,7 @@
*/
public static function get_schema() {

$instance = new static();

Check warning on line 303 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 303 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

$query_class = new $instance->query_class();

Expand Down Expand Up @@ -338,14 +338,8 @@
return false;
}

$instance = new static();

Check warning on line 341 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 341 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

$pre = apply_filters( "wu_pre_get_by_id_{$instance->model}", null, $item_id );

if ( null !== $pre ) {
return $pre;
}

$query_class = new $instance->query_class();

return $query_class->get_item($item_id);
Expand All @@ -362,14 +356,8 @@
*/
public static function get_by_hash($item_hash) {

$instance = new static();

Check warning on line 359 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 359 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

$pre = apply_filters( "wu_pre_get_by_hash_{$instance->model}", null, $item_hash );

if ( null !== $pre ) {
return $pre;
}

$item_id = Hash::decode($item_hash, sanitize_key((new \ReflectionClass(static::class))->getShortName()));

$query_class = new $instance->query_class();
Expand All @@ -388,14 +376,8 @@
*/
public static function get_by($column, $value) {

$instance = new static();

Check warning on line 379 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 379 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

$pre = apply_filters( "wu_pre_get_by_{$instance->model}", null, $column, $value );

if ( null !== $pre ) {
return $pre;
}

$query_class = new $instance->query_class();

return $query_class->get_item_by($column, $value);
Expand All @@ -411,7 +393,7 @@
*/
public static function get_items($query) {

$instance = new static();

Check warning on line 396 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 396 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

return (new $instance->query_class($query))->query();
}
Expand All @@ -426,7 +408,7 @@
*/
public static function get_items_as_array($query = []) {

$instance = new static();

Check warning on line 411 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

Check warning on line 411 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unsafe usage of new static().

$list = (new $instance->query_class($query))->query();

Expand Down Expand Up @@ -560,7 +542,7 @@
* @param array $data_unserialized The object data that will be stored.
* @param Base_Model $this The object instance.
*/
$meta = apply_filters("wu_{$this->model}_meta_pre_save", $meta, $data_unserialized, $this);

Check warning on line 545 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

Check warning on line 545 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

$blocked_attributes = [
'query_class',
Expand Down Expand Up @@ -596,7 +578,7 @@
* @param array $data_unserialized The object data that will be stored.
* @param Base_Model $this The object instance.
*/
$data = apply_filters("wu_{$this->model}_pre_save", $data, $data_unserialized, $this);

Check warning on line 581 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

Check warning on line 581 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

$is_valid_data = $this->validate();

Expand Down Expand Up @@ -639,7 +621,7 @@
* @param array $data_unserialized The object data that will be stored.
* @param Base_Model $this The object instance.
*/
do_action('wu_model_post_save', $this->model, $data, $data_unserialized, $this);

Check warning on line 624 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

Check warning on line 624 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

/**
* Fires after an object is stored into the database.
Expand All @@ -650,7 +632,7 @@
* @param Base_Model $this The object instance.
* @param bool $new True if the object is new.
*/
do_action("wu_{$this->model}_post_save", $data, $this, $new);

Check warning on line 635 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

Check warning on line 635 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

@param tag must not be named $this. Choose a descriptive alias, for example $instance.

return $saved;
}
Expand Down Expand Up @@ -739,12 +721,12 @@

if ( ! $this->get_meta_table_name()) {

// _doing_it_wrong(__METHOD__, __('This model does not support metadata.', 'ultimate-multisite'), '2.0.0');

Check warning on line 724 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

This comment is 71% valid code; is this commented out code?

Check warning on line 724 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

This comment is 71% valid code; is this commented out code?

return false;
}

// _doing_it_wrong(__METHOD__, __('Model metadata only works for already saved models.', 'ultimate-multisite'), '2.0.0');

Check warning on line 729 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

This comment is 71% valid code; is this commented out code?

Check warning on line 729 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

This comment is 71% valid code; is this commented out code?
return ! (! $this->get_id() && ! $this->_mocked);
}

Expand Down Expand Up @@ -1169,7 +1151,7 @@
* @since 2.0.0
* @return array
*/
public function _get_original() {

Check warning on line 1154 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Method name "_get_original" should not be prefixed with an underscore to indicate visibility

Check warning on line 1154 in inc/models/class-base-model.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Method name "_get_original" should not be prefixed with an underscore to indicate visibility

return $this->_original;
}
Expand Down
6 changes: 0 additions & 6 deletions inc/models/class-customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,6 @@ public function set_type($type) {
*/
public function get_total_grossed() {

$pre = apply_filters( 'wu_pre_customer_get_total_grossed', null, $this );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

static $sum;
Expand Down
6 changes: 0 additions & 6 deletions inc/models/class-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,6 @@ public function delete() {
*/
public static function get_by_site($site) {

$pre = apply_filters( 'wu_pre_domain_get_by_site', null, $site );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

// Allow passing a site object in
Expand Down
6 changes: 0 additions & 6 deletions inc/models/class-membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2320,12 +2320,6 @@ public function set_recurring($recurring): void {
*/
public function get_total_grossed() {

$pre = apply_filters( 'wu_pre_membership_get_total_grossed', null, $this );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

static $sum;
Expand Down
18 changes: 0 additions & 18 deletions inc/models/class-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,12 +1158,6 @@ public function get_membership() {
return $this->membership;
}

$pre = apply_filters( 'wu_pre_site_get_membership', null, $this );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

$table_name = "{$wpdb->base_prefix}wu_memberships";
Expand Down Expand Up @@ -2232,12 +2226,6 @@ public function to_search_results() {
*/
public static function get_all_by_type($type = 'customer_owned', $query_args = []) {

$pre = apply_filters( 'wu_pre_site_get_all_by_type', null, $type, $query_args );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

if ('pending' === $type) {
Expand Down Expand Up @@ -2330,12 +2318,6 @@ public static function get_all_by_categories($categories = [], $query_args = [])
*/
public static function get_all_categories($sites = []) {

$pre = apply_filters( 'wu_pre_site_get_all_categories', null, $sites );

if ( null !== $pre ) {
return $pre;
}

global $wpdb;

$site_ids = [];
Expand Down
192 changes: 0 additions & 192 deletions tests/WP_Ultimo/Models/Base_Model_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
*/
public function test_constructor_accepts_stdclass(): void {

$user_id = self::factory()->user->create();

Check warning on line 62 in tests/WP_Ultimo/Models/Base_Model_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

Check warning on line 62 in tests/WP_Ultimo/Models/Base_Model_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
$obj = new \stdClass();

Check warning on line 63 in tests/WP_Ultimo/Models/Base_Model_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 5 spaces

Check warning on line 63 in tests/WP_Ultimo/Models/Base_Model_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 5 spaces
$obj->user_id = $user_id;

$customer = new Customer($obj);
Expand Down Expand Up @@ -559,198 +559,6 @@
$this->assertNotSame('2030-06-15 10:30:00', $result);
}

/**
* Test wu_pre_get_by_id filter returns null by default (no-callback case).
*/
public function test_wu_pre_get_by_id_filter_returns_null_by_default(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);
$customer_id = $customer->get_id();

// No callback registered — filter returns null, normal query proceeds.
$result = Customer::get_by_id($customer_id);

$this->assertNotFalse($result);
$this->assertSame($customer_id, $result->get_id());
}

/**
* Test wu_pre_get_by_id filter returns instance when callback returns instance.
*/
public function test_wu_pre_get_by_id_filter_returns_instance_when_callback_returns_instance(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);
$customer_id = $customer->get_id();

// Create a stub customer to return from the filter.
$stub = new Customer(['id' => 9999]);

// Register callback that returns the stub.
add_filter('wu_pre_get_by_id_customer', function() use ($stub) {
return $stub;
});

$result = Customer::get_by_id($customer_id);

// Should return the stub, not the real customer.
$this->assertSame(9999, $result->get_id());

remove_filter('wu_pre_get_by_id_customer', function() use ($stub) {
return $stub;
});
}

/**
* Test wu_pre_get_by filter returns null by default (no-callback case).
*/
public function test_wu_pre_get_by_filter_returns_null_by_default(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);

// No callback registered — filter returns null, normal query proceeds.
$result = Customer::get_by('user_id', $user_id);

$this->assertNotFalse($result);
$this->assertSame($user_id, $result->get_user_id());
}

/**
* Test wu_pre_get_by filter returns instance when callback returns instance.
*/
public function test_wu_pre_get_by_filter_returns_instance_when_callback_returns_instance(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);

// Create a stub customer to return from the filter.
$stub = new Customer(['id' => 8888]);

// Register callback that returns the stub.
add_filter('wu_pre_get_by_customer', function() use ($stub) {
return $stub;
});

$result = Customer::get_by('user_id', $user_id);

// Should return the stub, not the real customer.
$this->assertSame(8888, $result->get_id());

remove_filter('wu_pre_get_by_customer', function() use ($stub) {
return $stub;
});
}

/**
* Test wu_pre_get_by_hash filter returns null by default (no-callback case).
*/
public function test_wu_pre_get_by_hash_filter_returns_null_by_default(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);

$hash = $customer->get_hash('id');

// No callback registered — filter returns null, normal query proceeds.
$result = Customer::get_by_hash($hash);

$this->assertNotFalse($result);
$this->assertSame($customer->get_id(), $result->get_id());
}

/**
* Test wu_pre_get_by_hash filter returns instance when callback returns instance.
*/
public function test_wu_pre_get_by_hash_filter_returns_instance_when_callback_returns_instance(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);

$hash = $customer->get_hash('id');

// Create a stub customer to return from the filter.
$stub = new Customer(['id' => 7777]);

// Register callback that returns the stub.
add_filter('wu_pre_get_by_hash_customer', function() use ($stub) {
return $stub;
});

$result = Customer::get_by_hash($hash);

// Should return the stub, not the real customer.
$this->assertSame(7777, $result->get_id());

remove_filter('wu_pre_get_by_hash_customer', function() use ($stub) {
return $stub;
});
}

/**
* Test wu_pre_get_by_id filter discriminates by model name.
*/
public function test_wu_pre_get_by_id_filter_discriminates_by_model(): void {

$user_id = self::factory()->user->create();
$customer = wu_create_customer([
'user_id' => $user_id,
'skip_validation' => true,
]);

$this->assertNotWPError($customer);
$customer_id = $customer->get_id();

// Create a stub to return from the filter.
$stub = new Customer(['id' => 6666]);

// Register callback for 'membership' model (not 'customer').
add_filter('wu_pre_get_by_id_membership', function() use ($stub) {
return $stub;
});

// Customer::get_by_id should NOT be affected by the 'membership' filter.
$result = Customer::get_by_id($customer_id);

$this->assertNotFalse($result);
$this->assertSame($customer_id, $result->get_id());

remove_filter('wu_pre_get_by_id_membership', function() use ($stub) {
return $stub;
});
}

/**
* Tear down test environment.
*/
Expand Down
Loading