Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Replicastore often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Replicastore, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class Replicastore implements Replicastore_Interface { |
||
| 15 | /** |
||
| 16 | * Empty and reset the replicastore. |
||
| 17 | * |
||
| 18 | * @access public |
||
| 19 | */ |
||
| 20 | public function reset() { |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Ran when full sync has just started. |
||
| 44 | * |
||
| 45 | * @access public |
||
| 46 | * |
||
| 47 | * @param array $config Full sync configuration for this sync module. |
||
| 48 | */ |
||
| 49 | public function full_sync_start( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Ran when full sync has just finished. |
||
| 55 | * |
||
| 56 | * @access public |
||
| 57 | * |
||
| 58 | * @param string $checksum Deprecated since 7.3.0. |
||
| 59 | */ |
||
| 60 | public function full_sync_end( $checksum ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Retrieve the number of terms. |
||
| 66 | * |
||
| 67 | * @access public |
||
| 68 | * |
||
| 69 | * @return int Number of terms. |
||
| 70 | */ |
||
| 71 | public function term_count() { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Retrieve the number of posts with a particular post status within a certain range. |
||
| 78 | * |
||
| 79 | * @access public |
||
| 80 | * |
||
| 81 | * @todo Prepare the SQL query before executing it. |
||
| 82 | * |
||
| 83 | * @param string $status Post status. |
||
|
|
|||
| 84 | * @param int $min_id Minimum post ID. |
||
| 85 | * @param int $max_id Maximum post ID. |
||
| 86 | * @return int Number of posts. |
||
| 87 | */ |
||
| 88 | View Code Duplication | public function post_count( $status = null, $min_id = null, $max_id = null ) { |
|
| 110 | |||
| 111 | /** |
||
| 112 | * Retrieve the posts with a particular post status. |
||
| 113 | * |
||
| 114 | * @access public |
||
| 115 | * |
||
| 116 | * @todo Implement range and actually use max_id/min_id arguments. |
||
| 117 | * |
||
| 118 | * @param string $status Post status. |
||
| 119 | * @param int $min_id Minimum post ID. |
||
| 120 | * @param int $max_id Maximum post ID. |
||
| 121 | * @return array Array of posts. |
||
| 122 | */ |
||
| 123 | public function get_posts( $status = null, $min_id = null, $max_id = null ) { |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Retrieve a post object by the post ID. |
||
| 140 | * |
||
| 141 | * @access public |
||
| 142 | * |
||
| 143 | * @param int $id Post ID. |
||
| 144 | * @return \WP_Post Post object. |
||
| 145 | */ |
||
| 146 | public function get_post( $id ) { |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Update or insert a post. |
||
| 152 | * |
||
| 153 | * @access public |
||
| 154 | * |
||
| 155 | * @param \WP_Post $post Post object. |
||
| 156 | * @param bool $silent Whether to perform a silent action. Not used in this implementation. |
||
| 157 | */ |
||
| 158 | public function upsert_post( $post, $silent = false ) { |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Delete a post by the post ID. |
||
| 220 | * |
||
| 221 | * @access public |
||
| 222 | * |
||
| 223 | * @param int $post_id Post ID. |
||
| 224 | */ |
||
| 225 | public function delete_post( $post_id ) { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Retrieve the checksum for posts within a range. |
||
| 231 | * |
||
| 232 | * @access public |
||
| 233 | * |
||
| 234 | * @param int $min_id Minimum post ID. |
||
| 235 | * @param int $max_id Maximum post ID. |
||
| 236 | * @return int The checksum. |
||
| 237 | */ |
||
| 238 | public function posts_checksum( $min_id = null, $max_id = null ) { |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Retrieve the checksum for post meta within a range. |
||
| 245 | * |
||
| 246 | * @access public |
||
| 247 | * |
||
| 248 | * @param int $min_id Minimum post meta ID. |
||
| 249 | * @param int $max_id Maximum post meta ID. |
||
| 250 | * @return int The checksum. |
||
| 251 | */ |
||
| 252 | public function post_meta_checksum( $min_id = null, $max_id = null ) { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Retrieve the number of comments with a particular comment status within a certain range. |
||
| 259 | * |
||
| 260 | * @access public |
||
| 261 | * |
||
| 262 | * @todo Prepare the SQL query before executing it. |
||
| 263 | * |
||
| 264 | * @param string $status Comment status. |
||
| 265 | * @param int $min_id Minimum comment ID. |
||
| 266 | * @param int $max_id Maximum comment ID. |
||
| 267 | * @return int Number of comments. |
||
| 268 | */ |
||
| 269 | View Code Duplication | public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
|
| 291 | |||
| 292 | /** |
||
| 293 | * Translate a comment status to a value of the comment_approved field. |
||
| 294 | * |
||
| 295 | * @access private |
||
| 296 | * |
||
| 297 | * @param string $status Comment status. |
||
| 298 | * @return string|bool New comment_approved value, false if the status doesn't affect it. |
||
| 299 | */ |
||
| 300 | private function comment_status_to_approval_value( $status ) { |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Retrieve the comments with a particular comment status. |
||
| 321 | * |
||
| 322 | * @access public |
||
| 323 | * |
||
| 324 | * @todo Implement range and actually use max_id/min_id arguments. |
||
| 325 | * |
||
| 326 | * @param string $status Comment status. |
||
| 327 | * @param int $min_id Minimum comment ID. |
||
| 328 | * @param int $max_id Maximum comment ID. |
||
| 329 | * @return array Array of comments. |
||
| 330 | */ |
||
| 331 | public function get_comments( $status = null, $min_id = null, $max_id = null ) { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Retrieve a comment object by the comment ID. |
||
| 346 | * |
||
| 347 | * @access public |
||
| 348 | * |
||
| 349 | * @param int $id Comment ID. |
||
| 350 | * @return \WP_Comment Comment object. |
||
| 351 | */ |
||
| 352 | public function get_comment( $id ) { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Update or insert a comment. |
||
| 358 | * |
||
| 359 | * @access public |
||
| 360 | * |
||
| 361 | * @param \WP_Comment $comment Comment object. |
||
| 362 | */ |
||
| 363 | public function upsert_comment( $comment ) { |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Trash a comment by the comment ID. |
||
| 411 | * |
||
| 412 | * @access public |
||
| 413 | * |
||
| 414 | * @param int $comment_id Comment ID. |
||
| 415 | */ |
||
| 416 | public function trash_comment( $comment_id ) { |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Delete a comment by the comment ID. |
||
| 422 | * |
||
| 423 | * @access public |
||
| 424 | * |
||
| 425 | * @param int $comment_id Comment ID. |
||
| 426 | */ |
||
| 427 | public function delete_comment( $comment_id ) { |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Mark a comment by the comment ID as spam. |
||
| 433 | * |
||
| 434 | * @access public |
||
| 435 | * |
||
| 436 | * @param int $comment_id Comment ID. |
||
| 437 | */ |
||
| 438 | public function spam_comment( $comment_id ) { |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Trash the comments of a post. |
||
| 444 | * |
||
| 445 | * @access public |
||
| 446 | * |
||
| 447 | * @param int $post_id Post ID. |
||
| 448 | * @param array $statuses Post statuses. Not used in this implementation. |
||
| 449 | */ |
||
| 450 | public function trashed_post_comments( $post_id, $statuses ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Untrash the comments of a post. |
||
| 456 | * |
||
| 457 | * @access public |
||
| 458 | * |
||
| 459 | * @param int $post_id Post ID. |
||
| 460 | */ |
||
| 461 | public function untrashed_post_comments( $post_id ) { |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Retrieve the checksum for comments within a range. |
||
| 467 | * |
||
| 468 | * @access public |
||
| 469 | * |
||
| 470 | * @param int $min_id Minimum comment ID. |
||
| 471 | * @param int $max_id Maximum comment ID. |
||
| 472 | * @return int The checksum. |
||
| 473 | */ |
||
| 474 | public function comments_checksum( $min_id = null, $max_id = null ) { |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Retrieve the checksum for comment meta within a range. |
||
| 481 | * |
||
| 482 | * @access public |
||
| 483 | * |
||
| 484 | * @param int $min_id Minimum comment meta ID. |
||
| 485 | * @param int $max_id Maximum comment meta ID. |
||
| 486 | * @return int The checksum. |
||
| 487 | */ |
||
| 488 | public function comment_meta_checksum( $min_id = null, $max_id = null ) { |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Retrieve the checksum for all options. |
||
| 495 | * |
||
| 496 | * @access public |
||
| 497 | * |
||
| 498 | * @return int The checksum. |
||
| 499 | */ |
||
| 500 | public function options_checksum() { |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Update the value of an option. |
||
| 510 | * |
||
| 511 | * @access public |
||
| 512 | * |
||
| 513 | * @param string $option Option name. |
||
| 514 | * @param mixed $value Option value. |
||
| 515 | * @return bool False if value was not updated and true if value was updated. |
||
| 516 | */ |
||
| 517 | public function update_option( $option, $value ) { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Retrieve an option value based on an option name. |
||
| 523 | * |
||
| 524 | * @access public |
||
| 525 | * |
||
| 526 | * @param string $option Name of option to retrieve. |
||
| 527 | * @param mixed $default Optional. Default value to return if the option does not exist. |
||
| 528 | * @return mixed Value set for the option. |
||
| 529 | */ |
||
| 530 | public function get_option( $option, $default = false ) { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Remove an option by name. |
||
| 536 | * |
||
| 537 | * @access public |
||
| 538 | * |
||
| 539 | * @param string $option Name of option to remove. |
||
| 540 | * @return bool True, if option is successfully deleted. False on failure. |
||
| 541 | */ |
||
| 542 | public function delete_option( $option ) { |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Change the features that the current theme supports. |
||
| 548 | * Intentionally not implemented in this replicastore. |
||
| 549 | * |
||
| 550 | * @access public |
||
| 551 | * |
||
| 552 | * @param array $theme_support Features that the theme supports. |
||
| 553 | */ |
||
| 554 | public function set_theme_support( $theme_support ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Whether the current theme supports a certain feature. |
||
| 560 | * |
||
| 561 | * @access public |
||
| 562 | * |
||
| 563 | * @param string $feature Name of the feature. |
||
| 564 | */ |
||
| 565 | public function current_theme_supports( $feature ) { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Retrieve metadata for the specified object. |
||
| 571 | * |
||
| 572 | * @access public |
||
| 573 | * |
||
| 574 | * @param string $type Meta type. |
||
| 575 | * @param int $object_id ID of the object. |
||
| 576 | * @param string $meta_key Meta key. |
||
| 577 | * @param bool $single If true, return only the first value of the specified meta_key. |
||
| 578 | * |
||
| 579 | * @return mixed Single metadata value, or array of values. |
||
| 580 | */ |
||
| 581 | public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) { |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Stores remote meta key/values alongside an ID mapping key. |
||
| 587 | * |
||
| 588 | * @access public |
||
| 589 | * |
||
| 590 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
| 591 | * |
||
| 592 | * @param string $type Meta type. |
||
| 593 | * @param int $object_id ID of the object. |
||
| 594 | * @param string $meta_key Meta key. |
||
| 595 | * @param mixed $meta_value Meta value. |
||
| 596 | * @param int $meta_id ID of the meta. |
||
| 597 | * |
||
| 598 | * @return bool False if meta table does not exist, true otherwise. |
||
| 599 | */ |
||
| 600 | public function upsert_metadata( $type, $object_id, $meta_key, $meta_value, $meta_id ) { |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Delete metadata for the specified object. |
||
| 645 | * |
||
| 646 | * @access public |
||
| 647 | * |
||
| 648 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
| 649 | * |
||
| 650 | * @param string $type Meta type. |
||
| 651 | * @param int $object_id ID of the object. |
||
| 652 | * @param array $meta_ids IDs of the meta objects to delete. |
||
| 653 | */ |
||
| 654 | public function delete_metadata( $type, $object_id, $meta_ids ) { |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Delete metadata with a certain key for the specified objects. |
||
| 675 | * |
||
| 676 | * @access public |
||
| 677 | * |
||
| 678 | * @todo Test this out to make sure it works as expected. |
||
| 679 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
| 680 | * |
||
| 681 | * @param string $type Meta type. |
||
| 682 | * @param array $object_ids IDs of the objects. |
||
| 683 | * @param string $meta_key Meta key. |
||
| 684 | */ |
||
| 685 | public function delete_batch_metadata( $type, $object_ids, $meta_key ) { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Retrieve value of a constant based on the constant name. |
||
| 704 | * |
||
| 705 | * @access public |
||
| 706 | * |
||
| 707 | * @param string $constant Name of constant to retrieve. |
||
| 708 | * @return mixed Value set for the constant. |
||
| 709 | */ |
||
| 710 | public function get_constant( $constant ) { |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Set the value of a constant. |
||
| 722 | * |
||
| 723 | * @access public |
||
| 724 | * |
||
| 725 | * @param string $constant Name of constant to retrieve. |
||
| 726 | * @param mixed $value Value set for the constant. |
||
| 727 | */ |
||
| 728 | public function set_constant( $constant, $value ) { |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Retrieve the number of the available updates of a certain type. |
||
| 734 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
| 735 | * |
||
| 736 | * @access public |
||
| 737 | * |
||
| 738 | * @param string $type Type of updates to retrieve. |
||
| 739 | * @return int|null Number of updates available, `null` if type is invalid or missing. |
||
| 740 | */ |
||
| 741 | public function get_updates( $type ) { |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Set the available updates of a certain type. |
||
| 753 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
| 754 | * |
||
| 755 | * @access public |
||
| 756 | * |
||
| 757 | * @param string $type Type of updates to set. |
||
| 758 | * @param int $updates Total number of updates. |
||
| 759 | */ |
||
| 760 | public function set_updates( $type, $updates ) { |
||
| 765 | |||
| 766 | /** |
||
| 767 | * Retrieve a callable value based on its name. |
||
| 768 | * |
||
| 769 | * @access public |
||
| 770 | * |
||
| 771 | * @param string $name Name of the callable to retrieve. |
||
| 772 | * @return mixed Value of the callable. |
||
| 773 | */ |
||
| 774 | public function get_callable( $name ) { |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Update the value of a callable. |
||
| 786 | * |
||
| 787 | * @access public |
||
| 788 | * |
||
| 789 | * @param string $name Callable name. |
||
| 790 | * @param mixed $value Callable value. |
||
| 791 | */ |
||
| 792 | public function set_callable( $name, $value ) { |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Retrieve a network option value based on a network option name. |
||
| 798 | * |
||
| 799 | * @access public |
||
| 800 | * |
||
| 801 | * @param string $option Name of network option to retrieve. |
||
| 802 | * @return mixed Value set for the network option. |
||
| 803 | */ |
||
| 804 | public function get_site_option( $option ) { |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Update the value of a network option. |
||
| 810 | * |
||
| 811 | * @access public |
||
| 812 | * |
||
| 813 | * @param string $option Network option name. |
||
| 814 | * @param mixed $value Network option value. |
||
| 815 | * @return bool False if value was not updated and true if value was updated. |
||
| 816 | */ |
||
| 817 | public function update_site_option( $option, $value ) { |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Remove a network option by name. |
||
| 823 | * |
||
| 824 | * @access public |
||
| 825 | * |
||
| 826 | * @param string $option Name of option to remove. |
||
| 827 | * @return bool True, if option is successfully deleted. False on failure. |
||
| 828 | */ |
||
| 829 | public function delete_site_option( $option ) { |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Retrieve the terms from a particular taxonomy. |
||
| 835 | * |
||
| 836 | * @access public |
||
| 837 | * |
||
| 838 | * @param string $taxonomy Taxonomy slug. |
||
| 839 | * @return array Array of terms. |
||
| 840 | */ |
||
| 841 | public function get_terms( $taxonomy ) { |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Retrieve a particular term. |
||
| 847 | * |
||
| 848 | * @access public |
||
| 849 | * |
||
| 850 | * @param string $taxonomy Taxonomy slug. |
||
| 851 | * @param int $term_id ID of the term. |
||
| 852 | * @param bool $is_term_id Whether this is a `term_id` or a `term_taxonomy_id`. |
||
| 853 | * @return \WP_Term|\WP_Error Term object on success, \WP_Error object on failure. |
||
| 854 | */ |
||
| 855 | public function get_term( $taxonomy, $term_id, $is_term_id = true ) { |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Verify a taxonomy is legitimate and register it if necessary. |
||
| 866 | * |
||
| 867 | * @access private |
||
| 868 | * |
||
| 869 | * @param string $taxonomy Taxonomy slug. |
||
| 870 | * @return bool|void|\WP_Error True if already exists; void if it was registered; \WP_Error on error. |
||
| 871 | */ |
||
| 872 | private function ensure_taxonomy( $taxonomy ) { |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Retrieve all terms from a taxonomy that are related to an object with a particular ID. |
||
| 894 | * |
||
| 895 | * @access public |
||
| 896 | * |
||
| 897 | * @param int $object_id Object ID. |
||
| 898 | * @param string $taxonomy Taxonomy slug. |
||
| 899 | * @return array|bool|\WP_Error Array of terms on success, `false` if no terms or post doesn't exist, \WP_Error on failure. |
||
| 900 | */ |
||
| 901 | public function get_the_terms( $object_id, $taxonomy ) { |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Insert or update a term. |
||
| 907 | * |
||
| 908 | * @access public |
||
| 909 | * |
||
| 910 | * @param \WP_Term $term_object Term object. |
||
| 911 | * @return array|bool|\WP_Error Array of term_id and term_taxonomy_id if updated, true if inserted, \WP_Error on failure. |
||
| 912 | */ |
||
| 913 | public function update_term( $term_object ) { |
||
| 946 | |||
| 947 | /** |
||
| 948 | * Delete a term by the term ID and its corresponding taxonomy. |
||
| 949 | * |
||
| 950 | * @access public |
||
| 951 | * |
||
| 952 | * @param int $term_id Term ID. |
||
| 953 | * @param string $taxonomy Taxonomy slug. |
||
| 954 | * @return bool|int|\WP_Error True on success, false if term doesn't exist. Zero if trying with default category. \WP_Error on invalid taxonomy. |
||
| 955 | */ |
||
| 956 | public function delete_term( $term_id, $taxonomy ) { |
||
| 959 | |||
| 960 | /** |
||
| 961 | * Add/update terms of a particular taxonomy of an object with the specified ID. |
||
| 962 | * |
||
| 963 | * @access public |
||
| 964 | * |
||
| 965 | * @param int $object_id The object to relate to. |
||
| 966 | * @param string $taxonomy The context in which to relate the term to the object. |
||
| 967 | * @param string|int|array $terms A single term slug, single term id, or array of either term slugs or ids. |
||
| 968 | * @param bool $append Optional. If false will delete difference of terms. Default false. |
||
| 969 | */ |
||
| 970 | public function update_object_terms( $object_id, $taxonomy, $terms, $append ) { |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Remove certain term relationships from the specified object. |
||
| 976 | * |
||
| 977 | * @access public |
||
| 978 | * |
||
| 979 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
| 980 | * |
||
| 981 | * @param int $object_id ID of the object. |
||
| 982 | * @param array $tt_ids Term taxonomy IDs. |
||
| 983 | * @return bool True on success, false on failure. |
||
| 984 | */ |
||
| 985 | public function delete_object_terms( $object_id, $tt_ids ) { |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Retrieve the number of users. |
||
| 1033 | * Not supported in this replicastore. |
||
| 1034 | * |
||
| 1035 | * @access public |
||
| 1036 | */ |
||
| 1037 | public function user_count() { |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Retrieve a user object by the user ID. |
||
| 1043 | * |
||
| 1044 | * @access public |
||
| 1045 | * |
||
| 1046 | * @param int $user_id User ID. |
||
| 1047 | * @return \WP_User User object. |
||
| 1048 | */ |
||
| 1049 | public function get_user( $user_id ) { |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * Insert or update a user. |
||
| 1055 | * Not supported in this replicastore. |
||
| 1056 | * |
||
| 1057 | * @access public |
||
| 1058 | * @throws \Exception If this method is invoked. |
||
| 1059 | * |
||
| 1060 | * @param \WP_User $user User object. |
||
| 1061 | */ |
||
| 1062 | public function upsert_user( $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Delete a user. |
||
| 1068 | * Not supported in this replicastore. |
||
| 1069 | * |
||
| 1070 | * @access public |
||
| 1071 | * @throws \Exception If this method is invoked. |
||
| 1072 | * |
||
| 1073 | * @param int $user_id User ID. |
||
| 1074 | */ |
||
| 1075 | public function delete_user( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Update/insert user locale. |
||
| 1081 | * Not supported in this replicastore. |
||
| 1082 | * |
||
| 1083 | * @access public |
||
| 1084 | * @throws \Exception If this method is invoked. |
||
| 1085 | * |
||
| 1086 | * @param int $user_id User ID. |
||
| 1087 | * @param string $local The user locale. |
||
| 1088 | */ |
||
| 1089 | public function upsert_user_locale( $user_id, $local ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1092 | |||
| 1093 | /** |
||
| 1094 | * Delete user locale. |
||
| 1095 | * Not supported in this replicastore. |
||
| 1096 | * |
||
| 1097 | * @access public |
||
| 1098 | * @throws \Exception If this method is invoked. |
||
| 1099 | * |
||
| 1100 | * @param int $user_id User ID. |
||
| 1101 | */ |
||
| 1102 | public function delete_user_locale( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Retrieve the user locale. |
||
| 1108 | * |
||
| 1109 | * @access public |
||
| 1110 | * |
||
| 1111 | * @param int $user_id User ID. |
||
| 1112 | * @return string The user locale. |
||
| 1113 | */ |
||
| 1114 | public function get_user_locale( $user_id ) { |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Retrieve the allowed mime types for the user. |
||
| 1120 | * Not supported in this replicastore. |
||
| 1121 | * |
||
| 1122 | * @access public |
||
| 1123 | * |
||
| 1124 | * @param int $user_id User ID. |
||
| 1125 | */ |
||
| 1126 | public function get_allowed_mime_types( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Retrieve all the checksums we are interested in. |
||
| 1132 | * Currently that is posts, comments, post meta and comment meta. |
||
| 1133 | * |
||
| 1134 | * @access public |
||
| 1135 | * |
||
| 1136 | * @return array Checksums. |
||
| 1137 | */ |
||
| 1138 | public function checksum_all() { |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Retrieve the columns that are needed to calculate a checksum for an object type. |
||
| 1152 | * |
||
| 1153 | * @access public |
||
| 1154 | * |
||
| 1155 | * @todo Refactor to not use interpolated values and prepare the SQL query. |
||
| 1156 | * |
||
| 1157 | * @param string $object_type Object type. |
||
| 1158 | * @return array|bool Columns, or false if invalid object type is specified. |
||
| 1159 | */ |
||
| 1160 | public function get_checksum_columns_for_object_type( $object_type ) { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Retrieve the checksum histogram for a specific object type. |
||
| 1179 | * |
||
| 1180 | * @access public |
||
| 1181 | * |
||
| 1182 | * @todo Refactor to not use interpolated values and properly prepare the SQL query. |
||
| 1183 | * |
||
| 1184 | * @param string $object_type Object type. |
||
| 1185 | * @param int $buckets Number of buckets to split the objects to. |
||
| 1186 | * @param int $start_id Minimum object ID. |
||
| 1187 | * @param int $end_id Maximum object ID. |
||
| 1188 | * @param array $columns Table columns to calculate the checksum from. |
||
| 1189 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
| 1190 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
| 1191 | * @return array The checksum histogram. |
||
| 1192 | */ |
||
| 1193 | public function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true, $salt = '' ) { |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Retrieve the checksum for a specific database table. |
||
| 1286 | * |
||
| 1287 | * @access private |
||
| 1288 | * |
||
| 1289 | * @todo Refactor to properly prepare the SQL query. |
||
| 1290 | * |
||
| 1291 | * @param string $table Table name. |
||
| 1292 | * @param array $columns Table columns to calculate the checksum from. |
||
| 1293 | * @param int $id_column Name of the unique ID column. |
||
| 1294 | * @param string $where_sql Additional WHERE clause SQL. |
||
| 1295 | * @param int $min_id Minimum object ID. |
||
| 1296 | * @param int $max_id Maximum object ID. |
||
| 1297 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
| 1298 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
| 1299 | * @return int|\WP_Error The table histogram, or \WP_Error on failure. |
||
| 1300 | */ |
||
| 1301 | private function table_checksum( $table, $columns, $id_column, $where_sql = '1=1', $min_id = null, $max_id = null, $strip_non_ascii = true, $salt = '' ) { |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Retrieve the type of the checksum. |
||
| 1351 | * |
||
| 1352 | * @access public |
||
| 1353 | * |
||
| 1354 | * @return string Type of the checksum. |
||
| 1355 | */ |
||
| 1356 | public function get_checksum_type() { |
||
| 1359 | |||
| 1360 | /** |
||
| 1361 | * Count the meta values in a table, within a specified range. |
||
| 1362 | * |
||
| 1363 | * @access private |
||
| 1364 | * |
||
| 1365 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
| 1366 | * |
||
| 1367 | * @param string $table Table name. |
||
| 1368 | * @param string $where_sql Additional WHERE SQL. |
||
| 1369 | * @param int $min_id Minimum meta ID. |
||
| 1370 | * @param int $max_id Maximum meta ID. |
||
| 1371 | * @return int Number of meta values. |
||
| 1372 | */ |
||
| 1373 | private function meta_count( $table, $where_sql, $min_id, $max_id ) { |
||
| 1387 | |||
| 1388 | /** |
||
| 1389 | * Wraps a column name in SQL which strips non-ASCII chars. |
||
| 1390 | * This helps normalize data to avoid checksum differences caused by |
||
| 1391 | * badly encoded data in the DB. |
||
| 1392 | * |
||
| 1393 | * @param string $column_name Name of the column. |
||
| 1394 | * @return string Column name, without the non-ASCII chars. |
||
| 1395 | */ |
||
| 1396 | public function strip_non_ascii_sql( $column_name ) { |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Used in methods that are not implemented and shouldn't be invoked. |
||
| 1402 | * |
||
| 1403 | * @access private |
||
| 1404 | * @throws \Exception If this method is invoked. |
||
| 1405 | */ |
||
| 1406 | private function invalid_call() { |
||
| 1412 | } |
||
| 1413 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.