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() { | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Ran when full sync has just started. | ||
| 50 | * | ||
| 51 | * @access public | ||
| 52 | * | ||
| 53 | * @param array $config Full sync configuration for this sync module. | ||
| 54 | */ | ||
| 55 | 	public function full_sync_start( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Ran when full sync has just finished. | ||
| 61 | * | ||
| 62 | * @access public | ||
| 63 | * | ||
| 64 | * @param string $checksum Deprecated since 7.3.0. | ||
| 65 | */ | ||
| 66 | 	public function full_sync_end( $checksum ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Retrieve the number of terms. | ||
| 72 | * | ||
| 73 | * @access public | ||
| 74 | * | ||
| 75 | * @return int Number of terms. | ||
| 76 | */ | ||
| 77 | 	public function term_count() { | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Retrieve the number of rows in the `term_taxonomy` table. | ||
| 84 | * | ||
| 85 | * @access public | ||
| 86 | * | ||
| 87 | * @return int Number of terms. | ||
| 88 | */ | ||
| 89 | 	public function term_taxonomy_count() { | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Retrieve the number of term relationships. | ||
| 96 | * | ||
| 97 | * @access public | ||
| 98 | * | ||
| 99 | * @return int Number of rows in the term relationships table. | ||
| 100 | */ | ||
| 101 | 	public function term_relationship_count() { | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Retrieve the number of posts with a particular post status within a certain range. | ||
| 108 | * | ||
| 109 | * @access public | ||
| 110 | * | ||
| 111 | * @todo Prepare the SQL query before executing it. | ||
| 112 | * | ||
| 113 | * @param string $status Post status. | ||
|  | |||
| 114 | * @param int $min_id Minimum post ID. | ||
| 115 | * @param int $max_id Maximum post ID. | ||
| 116 | * @return int Number of posts. | ||
| 117 | */ | ||
| 118 | View Code Duplication | 	public function post_count( $status = null, $min_id = null, $max_id = null ) { | |
| 140 | |||
| 141 | /** | ||
| 142 | * Retrieve the posts with a particular post status. | ||
| 143 | * | ||
| 144 | * @access public | ||
| 145 | * | ||
| 146 | * @todo Implement range and actually use max_id/min_id arguments. | ||
| 147 | * | ||
| 148 | * @param string $status Post status. | ||
| 149 | * @param int $min_id Minimum post ID. | ||
| 150 | * @param int $max_id Maximum post ID. | ||
| 151 | * @return array Array of posts. | ||
| 152 | */ | ||
| 153 | 	public function get_posts( $status = null, $min_id = null, $max_id = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 167 | |||
| 168 | /** | ||
| 169 | * Retrieve a post object by the post ID. | ||
| 170 | * | ||
| 171 | * @access public | ||
| 172 | * | ||
| 173 | * @param int $id Post ID. | ||
| 174 | * @return \WP_Post Post object. | ||
| 175 | */ | ||
| 176 | 	public function get_post( $id ) { | ||
| 179 | |||
| 180 | /** | ||
| 181 | * Update or insert a post. | ||
| 182 | * | ||
| 183 | * @access public | ||
| 184 | * | ||
| 185 | * @param \WP_Post $post Post object. | ||
| 186 | * @param bool $silent Whether to perform a silent action. Not used in this implementation. | ||
| 187 | */ | ||
| 188 | 	public function upsert_post( $post, $silent = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 247 | |||
| 248 | /** | ||
| 249 | * Delete a post by the post ID. | ||
| 250 | * | ||
| 251 | * @access public | ||
| 252 | * | ||
| 253 | * @param int $post_id Post ID. | ||
| 254 | */ | ||
| 255 | 	public function delete_post( $post_id ) { | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Retrieve the checksum for posts within a range. | ||
| 261 | * | ||
| 262 | * @access public | ||
| 263 | * | ||
| 264 | * @param int $min_id Minimum post ID. | ||
| 265 | * @param int $max_id Maximum post ID. | ||
| 266 | * @return int The checksum. | ||
| 267 | */ | ||
| 268 | 	public function posts_checksum( $min_id = null, $max_id = null ) { | ||
| 272 | |||
| 273 | /** | ||
| 274 | * Retrieve the checksum for post meta within a range. | ||
| 275 | * | ||
| 276 | * @access public | ||
| 277 | * | ||
| 278 | * @param int $min_id Minimum post meta ID. | ||
| 279 | * @param int $max_id Maximum post meta ID. | ||
| 280 | * @return int The checksum. | ||
| 281 | */ | ||
| 282 | 	public function post_meta_checksum( $min_id = null, $max_id = null ) { | ||
| 286 | |||
| 287 | /** | ||
| 288 | * Retrieve the number of comments with a particular comment status within a certain range. | ||
| 289 | * | ||
| 290 | * @access public | ||
| 291 | * | ||
| 292 | * @todo Prepare the SQL query before executing it. | ||
| 293 | * | ||
| 294 | * @param string $status Comment status. | ||
| 295 | * @param int $min_id Minimum comment ID. | ||
| 296 | * @param int $max_id Maximum comment ID. | ||
| 297 | * @return int Number of comments. | ||
| 298 | */ | ||
| 299 | View Code Duplication | 	public function comment_count( $status = null, $min_id = null, $max_id = null ) { | |
| 321 | |||
| 322 | /** | ||
| 323 | * Translate a comment status to a value of the comment_approved field. | ||
| 324 | * | ||
| 325 | * @access private | ||
| 326 | * | ||
| 327 | * @param string $status Comment status. | ||
| 328 | * @return string|bool New comment_approved value, false if the status doesn't affect it. | ||
| 329 | */ | ||
| 330 | 	private function comment_status_to_approval_value( $status ) { | ||
| 350 | |||
| 351 | /** | ||
| 352 | * Retrieve the comments with a particular comment status. | ||
| 353 | * | ||
| 354 | * @access public | ||
| 355 | * | ||
| 356 | * @todo Implement range and actually use max_id/min_id arguments. | ||
| 357 | * | ||
| 358 | * @param string $status Comment status. | ||
| 359 | * @param int $min_id Minimum comment ID. | ||
| 360 | * @param int $max_id Maximum comment ID. | ||
| 361 | * @return array Array of comments. | ||
| 362 | */ | ||
| 363 | 	public function get_comments( $status = null, $min_id = null, $max_id = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 375 | |||
| 376 | /** | ||
| 377 | * Retrieve a comment object by the comment ID. | ||
| 378 | * | ||
| 379 | * @access public | ||
| 380 | * | ||
| 381 | * @param int $id Comment ID. | ||
| 382 | * @return \WP_Comment Comment object. | ||
| 383 | */ | ||
| 384 | 	public function get_comment( $id ) { | ||
| 387 | |||
| 388 | /** | ||
| 389 | * Update or insert a comment. | ||
| 390 | * | ||
| 391 | * @access public | ||
| 392 | * | ||
| 393 | * @param \WP_Comment $comment Comment object. | ||
| 394 | */ | ||
| 395 | 	public function upsert_comment( $comment ) { | ||
| 442 | |||
| 443 | /** | ||
| 444 | * Trash a comment by the comment ID. | ||
| 445 | * | ||
| 446 | * @access public | ||
| 447 | * | ||
| 448 | * @param int $comment_id Comment ID. | ||
| 449 | */ | ||
| 450 | 	public function trash_comment( $comment_id ) { | ||
| 453 | |||
| 454 | /** | ||
| 455 | * Delete a comment by the comment ID. | ||
| 456 | * | ||
| 457 | * @access public | ||
| 458 | * | ||
| 459 | * @param int $comment_id Comment ID. | ||
| 460 | */ | ||
| 461 | 	public function delete_comment( $comment_id ) { | ||
| 464 | |||
| 465 | /** | ||
| 466 | * Mark a comment by the comment ID as spam. | ||
| 467 | * | ||
| 468 | * @access public | ||
| 469 | * | ||
| 470 | * @param int $comment_id Comment ID. | ||
| 471 | */ | ||
| 472 | 	public function spam_comment( $comment_id ) { | ||
| 475 | |||
| 476 | /** | ||
| 477 | * Trash the comments of a post. | ||
| 478 | * | ||
| 479 | * @access public | ||
| 480 | * | ||
| 481 | * @param int $post_id Post ID. | ||
| 482 | * @param array $statuses Post statuses. Not used in this implementation. | ||
| 483 | */ | ||
| 484 | 	public function trashed_post_comments( $post_id, $statuses ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 487 | |||
| 488 | /** | ||
| 489 | * Untrash the comments of a post. | ||
| 490 | * | ||
| 491 | * @access public | ||
| 492 | * | ||
| 493 | * @param int $post_id Post ID. | ||
| 494 | */ | ||
| 495 | 	public function untrashed_post_comments( $post_id ) { | ||
| 498 | |||
| 499 | /** | ||
| 500 | * Retrieve the checksum for comments within a range. | ||
| 501 | * | ||
| 502 | * @access public | ||
| 503 | * | ||
| 504 | * @param int $min_id Minimum comment ID. | ||
| 505 | * @param int $max_id Maximum comment ID. | ||
| 506 | * @return int The checksum. | ||
| 507 | */ | ||
| 508 | 	public function comments_checksum( $min_id = null, $max_id = null ) { | ||
| 512 | |||
| 513 | /** | ||
| 514 | * Retrieve the checksum for comment meta within a range. | ||
| 515 | * | ||
| 516 | * @access public | ||
| 517 | * | ||
| 518 | * @param int $min_id Minimum comment meta ID. | ||
| 519 | * @param int $max_id Maximum comment meta ID. | ||
| 520 | * @return int The checksum. | ||
| 521 | */ | ||
| 522 | 	public function comment_meta_checksum( $min_id = null, $max_id = null ) { | ||
| 526 | |||
| 527 | /** | ||
| 528 | * Retrieve the checksum for all options. | ||
| 529 | * | ||
| 530 | * @access public | ||
| 531 | * | ||
| 532 | * @return int The checksum. | ||
| 533 | */ | ||
| 534 | 	public function options_checksum() { | ||
| 541 | |||
| 542 | /** | ||
| 543 | * Update the value of an option. | ||
| 544 | * | ||
| 545 | * @access public | ||
| 546 | * | ||
| 547 | * @param string $option Option name. | ||
| 548 | * @param mixed $value Option value. | ||
| 549 | * @return bool False if value was not updated and true if value was updated. | ||
| 550 | */ | ||
| 551 | 	public function update_option( $option, $value ) { | ||
| 554 | |||
| 555 | /** | ||
| 556 | * Retrieve an option value based on an option name. | ||
| 557 | * | ||
| 558 | * @access public | ||
| 559 | * | ||
| 560 | * @param string $option Name of option to retrieve. | ||
| 561 | * @param mixed $default Optional. Default value to return if the option does not exist. | ||
| 562 | * @return mixed Value set for the option. | ||
| 563 | */ | ||
| 564 | 	public function get_option( $option, $default = false ) { | ||
| 567 | |||
| 568 | /** | ||
| 569 | * Remove an option by name. | ||
| 570 | * | ||
| 571 | * @access public | ||
| 572 | * | ||
| 573 | * @param string $option Name of option to remove. | ||
| 574 | * @return bool True, if option is successfully deleted. False on failure. | ||
| 575 | */ | ||
| 576 | 	public function delete_option( $option ) { | ||
| 579 | |||
| 580 | /** | ||
| 581 | * Change the info of the current theme. | ||
| 582 | * | ||
| 583 | * @access public | ||
| 584 | * | ||
| 585 | * @param array $theme_info Theme info array. | ||
| 586 | */ | ||
| 587 | 	public function set_theme_info( $theme_info ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 590 | |||
| 591 | /** | ||
| 592 | * Whether the current theme supports a certain feature. | ||
| 593 | * | ||
| 594 | * @access public | ||
| 595 | * | ||
| 596 | * @param string $feature Name of the feature. | ||
| 597 | */ | ||
| 598 | 	public function current_theme_supports( $feature ) { | ||
| 601 | |||
| 602 | /** | ||
| 603 | * Retrieve metadata for the specified object. | ||
| 604 | * | ||
| 605 | * @access public | ||
| 606 | * | ||
| 607 | * @param string $type Meta type. | ||
| 608 | * @param int $object_id ID of the object. | ||
| 609 | * @param string $meta_key Meta key. | ||
| 610 | * @param bool $single If true, return only the first value of the specified meta_key. | ||
| 611 | * | ||
| 612 | * @return mixed Single metadata value, or array of values. | ||
| 613 | */ | ||
| 614 | 	public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) { | ||
| 617 | |||
| 618 | /** | ||
| 619 | * Stores remote meta key/values alongside an ID mapping key. | ||
| 620 | * | ||
| 621 | * @access public | ||
| 622 | * | ||
| 623 | * @todo Refactor to not use interpolated values when preparing the SQL query. | ||
| 624 | * | ||
| 625 | * @param string $type Meta type. | ||
| 626 | * @param int $object_id ID of the object. | ||
| 627 | * @param string $meta_key Meta key. | ||
| 628 | * @param mixed $meta_value Meta value. | ||
| 629 | * @param int $meta_id ID of the meta. | ||
| 630 | * | ||
| 631 | * @return bool False if meta table does not exist, true otherwise. | ||
| 632 | */ | ||
| 633 | 	public function upsert_metadata( $type, $object_id, $meta_key, $meta_value, $meta_id ) { | ||
| 675 | |||
| 676 | /** | ||
| 677 | * Delete metadata for the specified object. | ||
| 678 | * | ||
| 679 | * @access public | ||
| 680 | * | ||
| 681 | * @todo Refactor to not use interpolated values when preparing the SQL query. | ||
| 682 | * | ||
| 683 | * @param string $type Meta type. | ||
| 684 | * @param int $object_id ID of the object. | ||
| 685 | * @param array $meta_ids IDs of the meta objects to delete. | ||
| 686 | */ | ||
| 687 | 	public function delete_metadata( $type, $object_id, $meta_ids ) { | ||
| 705 | |||
| 706 | /** | ||
| 707 | * Delete metadata with a certain key for the specified objects. | ||
| 708 | * | ||
| 709 | * @access public | ||
| 710 | * | ||
| 711 | * @todo Test this out to make sure it works as expected. | ||
| 712 | * @todo Refactor to not use interpolated values when preparing the SQL query. | ||
| 713 | * | ||
| 714 | * @param string $type Meta type. | ||
| 715 | * @param array $object_ids IDs of the objects. | ||
| 716 | * @param string $meta_key Meta key. | ||
| 717 | */ | ||
| 718 | 	public function delete_batch_metadata( $type, $object_ids, $meta_key ) { | ||
| 734 | |||
| 735 | /** | ||
| 736 | * Retrieve value of a constant based on the constant name. | ||
| 737 | * | ||
| 738 | * We explicitly return null instead of false if the constant doesn't exist. | ||
| 739 | * | ||
| 740 | * @access public | ||
| 741 | * | ||
| 742 | * @param string $constant Name of constant to retrieve. | ||
| 743 | * @return mixed Value set for the constant. | ||
| 744 | */ | ||
| 745 | 	public function get_constant( $constant ) { | ||
| 746 | $value = get_option( 'jetpack_constant_' . $constant ); | ||
| 747 | |||
| 748 | 		if ( $value ) { | ||
| 749 | return $value; | ||
| 750 | } | ||
| 751 | |||
| 752 | return null; | ||
| 753 | } | ||
| 754 | |||
| 755 | /** | ||
| 756 | * Set the value of a constant. | ||
| 757 | * | ||
| 758 | * @access public | ||
| 759 | * | ||
| 760 | * @param string $constant Name of constant to retrieve. | ||
| 761 | * @param mixed $value Value set for the constant. | ||
| 762 | */ | ||
| 763 | 	public function set_constant( $constant, $value ) { | ||
| 764 | update_option( 'jetpack_constant_' . $constant, $value ); | ||
| 765 | } | ||
| 766 | |||
| 767 | /** | ||
| 768 | * Retrieve the number of the available updates of a certain type. | ||
| 769 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. | ||
| 770 | * | ||
| 771 | * @access public | ||
| 772 | * | ||
| 773 | * @param string $type Type of updates to retrieve. | ||
| 774 | * @return int|null Number of updates available, `null` if type is invalid or missing. | ||
| 775 | */ | ||
| 776 | 	public function get_updates( $type ) { | ||
| 777 | $all_updates = get_option( 'jetpack_updates', array() ); | ||
| 778 | |||
| 779 | 		if ( isset( $all_updates[ $type ] ) ) { | ||
| 780 | return $all_updates[ $type ]; | ||
| 781 | 		} else { | ||
| 782 | return null; | ||
| 783 | } | ||
| 784 | } | ||
| 785 | |||
| 786 | /** | ||
| 787 | * Set the available updates of a certain type. | ||
| 788 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. | ||
| 789 | * | ||
| 790 | * @access public | ||
| 791 | * | ||
| 792 | * @param string $type Type of updates to set. | ||
| 793 | * @param int $updates Total number of updates. | ||
| 794 | */ | ||
| 795 | 	public function set_updates( $type, $updates ) { | ||
| 796 | $all_updates = get_option( 'jetpack_updates', array() ); | ||
| 797 | $all_updates[ $type ] = $updates; | ||
| 798 | update_option( 'jetpack_updates', $all_updates ); | ||
| 799 | } | ||
| 800 | |||
| 801 | /** | ||
| 802 | * Retrieve a callable value based on its name. | ||
| 803 | * | ||
| 804 | * @access public | ||
| 805 | * | ||
| 806 | * @param string $name Name of the callable to retrieve. | ||
| 807 | * @return mixed Value of the callable. | ||
| 808 | */ | ||
| 809 | 	public function get_callable( $name ) { | ||
| 810 | $value = get_option( 'jetpack_' . $name ); | ||
| 811 | |||
| 812 | 		if ( $value ) { | ||
| 813 | return $value; | ||
| 814 | } | ||
| 815 | |||
| 816 | return null; | ||
| 817 | } | ||
| 818 | |||
| 819 | /** | ||
| 820 | * Update the value of a callable. | ||
| 821 | * | ||
| 822 | * @access public | ||
| 823 | * | ||
| 824 | * @param string $name Callable name. | ||
| 825 | * @param mixed $value Callable value. | ||
| 826 | */ | ||
| 827 | 	public function set_callable( $name, $value ) { | ||
| 828 | update_option( 'jetpack_' . $name, $value ); | ||
| 829 | } | ||
| 830 | |||
| 831 | /** | ||
| 832 | * Retrieve a network option value based on a network option name. | ||
| 833 | * | ||
| 834 | * @access public | ||
| 835 | * | ||
| 836 | * @param string $option Name of network option to retrieve. | ||
| 837 | * @return mixed Value set for the network option. | ||
| 838 | */ | ||
| 839 | 	public function get_site_option( $option ) { | ||
| 840 | return get_option( 'jetpack_network_' . $option ); | ||
| 841 | } | ||
| 842 | |||
| 843 | /** | ||
| 844 | * Update the value of a network option. | ||
| 845 | * | ||
| 846 | * @access public | ||
| 847 | * | ||
| 848 | * @param string $option Network option name. | ||
| 849 | * @param mixed $value Network option value. | ||
| 850 | * @return bool False if value was not updated and true if value was updated. | ||
| 851 | */ | ||
| 852 | 	public function update_site_option( $option, $value ) { | ||
| 853 | return update_option( 'jetpack_network_' . $option, $value ); | ||
| 854 | } | ||
| 855 | |||
| 856 | /** | ||
| 857 | * Remove a network option by name. | ||
| 858 | * | ||
| 859 | * @access public | ||
| 860 | * | ||
| 861 | * @param string $option Name of option to remove. | ||
| 862 | * @return bool True, if option is successfully deleted. False on failure. | ||
| 863 | */ | ||
| 864 | 	public function delete_site_option( $option ) { | ||
| 865 | return delete_option( 'jetpack_network_' . $option ); | ||
| 866 | } | ||
| 867 | |||
| 868 | /** | ||
| 869 | * Retrieve the terms from a particular taxonomy. | ||
| 870 | * | ||
| 871 | * @access public | ||
| 872 | * | ||
| 873 | * @param string $taxonomy Taxonomy slug. | ||
| 874 | * @return array|\WP_Error Array of terms or WP_Error object on failure. | ||
| 875 | */ | ||
| 876 | 	public function get_terms( $taxonomy ) { | ||
| 877 | $t = $this->ensure_taxonomy( $taxonomy ); | ||
| 878 | 		if ( ! $t || is_wp_error( $t ) ) { | ||
| 879 | return $t; | ||
| 880 | } | ||
| 881 | return get_terms( $taxonomy ); | ||
| 882 | } | ||
| 883 | |||
| 884 | /** | ||
| 885 | * Retrieve a particular term. | ||
| 886 | * | ||
| 887 | * @access public | ||
| 888 | * | ||
| 889 | * @param string $taxonomy Taxonomy slug. | ||
| 890 | * @param int $term_id ID of the term. | ||
| 891 | * @param bool $is_term_id Whether this is a `term_id` or a `term_taxonomy_id`. | ||
| 892 | * @return \WP_Term|\WP_Error Term object on success, \WP_Error object on failure. | ||
| 893 | */ | ||
| 894 | 	public function get_term( $taxonomy, $term_id, $is_term_id = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 895 | $t = $this->ensure_taxonomy( $taxonomy ); | ||
| 896 | 		if ( ! $t || is_wp_error( $t ) ) { | ||
| 897 | return $t; | ||
| 898 | } | ||
| 899 | |||
| 900 | return get_term( $term_id, $taxonomy ); | ||
| 901 | } | ||
| 902 | |||
| 903 | /** | ||
| 904 | * Verify a taxonomy is legitimate and register it if necessary. | ||
| 905 | * | ||
| 906 | * @access private | ||
| 907 | * | ||
| 908 | * @param string $taxonomy Taxonomy slug. | ||
| 909 | * @return bool|void|\WP_Error True if already exists; void if it was registered; \WP_Error on error. | ||
| 910 | */ | ||
| 911 | 	private function ensure_taxonomy( $taxonomy ) { | ||
| 930 | |||
| 931 | /** | ||
| 932 | * Retrieve all terms from a taxonomy that are related to an object with a particular ID. | ||
| 933 | * | ||
| 934 | * @access public | ||
| 935 | * | ||
| 936 | * @param int $object_id Object ID. | ||
| 937 | * @param string $taxonomy Taxonomy slug. | ||
| 938 | * @return array|bool|\WP_Error Array of terms on success, `false` if no terms or post doesn't exist, \WP_Error on failure. | ||
| 939 | */ | ||
| 940 | 	public function get_the_terms( $object_id, $taxonomy ) { | ||
| 943 | |||
| 944 | /** | ||
| 945 | * Insert or update a term. | ||
| 946 | * | ||
| 947 | * @access public | ||
| 948 | * | ||
| 949 | * @param \WP_Term $term_object Term object. | ||
| 950 | * @return array|bool|\WP_Error Array of term_id and term_taxonomy_id if updated, true if inserted, \WP_Error on failure. | ||
| 951 | */ | ||
| 952 | 	public function update_term( $term_object ) { | ||
| 985 | |||
| 986 | /** | ||
| 987 | * Delete a term by the term ID and its corresponding taxonomy. | ||
| 988 | * | ||
| 989 | * @access public | ||
| 990 | * | ||
| 991 | * @param int $term_id Term ID. | ||
| 992 | * @param string $taxonomy Taxonomy slug. | ||
| 993 | * @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. | ||
| 994 | */ | ||
| 995 | 	public function delete_term( $term_id, $taxonomy ) { | ||
| 999 | |||
| 1000 | /** | ||
| 1001 | * Add/update terms of a particular taxonomy of an object with the specified ID. | ||
| 1002 | * | ||
| 1003 | * @access public | ||
| 1004 | * | ||
| 1005 | * @param int $object_id The object to relate to. | ||
| 1006 | * @param string $taxonomy The context in which to relate the term to the object. | ||
| 1007 | * @param string|int|array $terms A single term slug, single term id, or array of either term slugs or ids. | ||
| 1008 | * @param bool $append Optional. If false will delete difference of terms. Default false. | ||
| 1009 | */ | ||
| 1010 | 	public function update_object_terms( $object_id, $taxonomy, $terms, $append ) { | ||
| 1014 | |||
| 1015 | /** | ||
| 1016 | * Remove certain term relationships from the specified object. | ||
| 1017 | * | ||
| 1018 | * @access public | ||
| 1019 | * | ||
| 1020 | * @todo Refactor to not use interpolated values when preparing the SQL query. | ||
| 1021 | * | ||
| 1022 | * @param int $object_id ID of the object. | ||
| 1023 | * @param array $tt_ids Term taxonomy IDs. | ||
| 1024 | * @return bool True on success, false on failure. | ||
| 1025 | */ | ||
| 1026 | 	public function delete_object_terms( $object_id, $tt_ids ) { | ||
| 1071 | |||
| 1072 | /** | ||
| 1073 | * Retrieve the number of users. | ||
| 1074 | * Not supported in this replicastore. | ||
| 1075 | * | ||
| 1076 | * @access public | ||
| 1077 | */ | ||
| 1078 | 	public function user_count() { | ||
| 1081 | |||
| 1082 | /** | ||
| 1083 | * Retrieve a user object by the user ID. | ||
| 1084 | * | ||
| 1085 | * @access public | ||
| 1086 | * | ||
| 1087 | * @param int $user_id User ID. | ||
| 1088 | * @return \WP_User User object. | ||
| 1089 | */ | ||
| 1090 | 	public function get_user( $user_id ) { | ||
| 1093 | |||
| 1094 | /** | ||
| 1095 | * Insert or update a user. | ||
| 1096 | * Not supported in this replicastore. | ||
| 1097 | * | ||
| 1098 | * @access public | ||
| 1099 | * @throws \Exception If this method is invoked. | ||
| 1100 | * | ||
| 1101 | * @param \WP_User $user User object. | ||
| 1102 | */ | ||
| 1103 | 	public function upsert_user( $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 1106 | |||
| 1107 | /** | ||
| 1108 | * Delete a user. | ||
| 1109 | * Not supported in this replicastore. | ||
| 1110 | * | ||
| 1111 | * @access public | ||
| 1112 | * @throws \Exception If this method is invoked. | ||
| 1113 | * | ||
| 1114 | * @param int $user_id User ID. | ||
| 1115 | */ | ||
| 1116 | 	public function delete_user( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 1119 | |||
| 1120 | /** | ||
| 1121 | * Update/insert user locale. | ||
| 1122 | * Not supported in this replicastore. | ||
| 1123 | * | ||
| 1124 | * @access public | ||
| 1125 | * @throws \Exception If this method is invoked. | ||
| 1126 | * | ||
| 1127 | * @param int $user_id User ID. | ||
| 1128 | * @param string $local The user locale. | ||
| 1129 | */ | ||
| 1130 | 	public function upsert_user_locale( $user_id, $local ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 1133 | |||
| 1134 | /** | ||
| 1135 | * Delete user locale. | ||
| 1136 | * Not supported in this replicastore. | ||
| 1137 | * | ||
| 1138 | * @access public | ||
| 1139 | * @throws \Exception If this method is invoked. | ||
| 1140 | * | ||
| 1141 | * @param int $user_id User ID. | ||
| 1142 | */ | ||
| 1143 | 	public function delete_user_locale( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 1146 | |||
| 1147 | /** | ||
| 1148 | * Retrieve the user locale. | ||
| 1149 | * | ||
| 1150 | * @access public | ||
| 1151 | * | ||
| 1152 | * @param int $user_id User ID. | ||
| 1153 | * @return string The user locale. | ||
| 1154 | */ | ||
| 1155 | 	public function get_user_locale( $user_id ) { | ||
| 1158 | |||
| 1159 | /** | ||
| 1160 | * Retrieve the allowed mime types for the user. | ||
| 1161 | * Not supported in this replicastore. | ||
| 1162 | * | ||
| 1163 | * @access public | ||
| 1164 | * | ||
| 1165 | * @param int $user_id User ID. | ||
| 1166 | */ | ||
| 1167 | 	public function get_allowed_mime_types( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
| 1170 | |||
| 1171 | /** | ||
| 1172 | * Retrieve all the checksums we are interested in. | ||
| 1173 | * Currently that is posts, comments, post meta and comment meta. | ||
| 1174 | * | ||
| 1175 | * @access public | ||
| 1176 | * | ||
| 1177 | * @return array Checksums. | ||
| 1178 | */ | ||
| 1179 | 	public function checksum_all() { | ||
| 1190 | |||
| 1191 | /** | ||
| 1192 | * Retrieve the columns that are needed to calculate a checksum for an object type. | ||
| 1193 | * | ||
| 1194 | * @access public | ||
| 1195 | * | ||
| 1196 | * @todo Refactor to not use interpolated values and prepare the SQL query. | ||
| 1197 | * | ||
| 1198 | * @param string $object_type Object type. | ||
| 1199 | * @return array|bool Columns, or false if invalid object type is specified. | ||
| 1200 | */ | ||
| 1201 | 	public function get_checksum_columns_for_object_type( $object_type ) { | ||
| 1221 | |||
| 1222 | /** | ||
| 1223 | * Grabs the minimum and maximum object ids for the given parameters. | ||
| 1224 | * | ||
| 1225 | * @access public | ||
| 1226 | * | ||
| 1227 | * @param string $id_field The id column in the table to query. | ||
| 1228 | * @param string $object_table The table to query. | ||
| 1229 | * @param string $where A sql where clause without 'WHERE'. | ||
| 1230 | * @param int $bucket_size The maximum amount of objects to include in the query. | ||
| 1231 | * For `term_relationships` table, the bucket size will refer to the amount | ||
| 1232 | * of distinct object ids. This will likely include more database rows than | ||
| 1233 | * the bucket size implies. | ||
| 1234 | * | ||
| 1235 | * @return object An object with min_id and max_id properties. | ||
| 1236 | */ | ||
| 1237 | 	public function get_min_max_object_id( $id_field, $object_table, $where, $bucket_size ) { | ||
| 1256 | |||
| 1257 | /** | ||
| 1258 | * Retrieve the checksum histogram for a specific object type. | ||
| 1259 | * | ||
| 1260 | * @access public | ||
| 1261 | * | ||
| 1262 | * @todo Refactor to not use interpolated values and properly prepare the SQL query. | ||
| 1263 | * | ||
| 1264 | * @param string $object_type Object type. | ||
| 1265 | * @param int $buckets Number of buckets to split the objects to. | ||
| 1266 | * @param int $start_id Minimum object ID. | ||
| 1267 | * @param int $end_id Maximum object ID. | ||
| 1268 | * @param array $columns Table columns to calculate the checksum from. | ||
| 1269 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. | ||
| 1270 | * @param string $salt Salt, used for $wpdb->prepare()'s args. | ||
| 1271 | * @return array The checksum histogram. | ||
| 1272 | */ | ||
| 1273 | 	public function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true, $salt = '' ) { | ||
| 1377 | |||
| 1378 | /** | ||
| 1379 | * Retrieve the checksum for a specific database table. | ||
| 1380 | * | ||
| 1381 | * @access private | ||
| 1382 | * | ||
| 1383 | * @todo Refactor to properly prepare the SQL query. | ||
| 1384 | * | ||
| 1385 | * @param string $table Table name. | ||
| 1386 | * @param array $columns Table columns to calculate the checksum from. | ||
| 1387 | * @param int $id_column Name of the unique ID column. | ||
| 1388 | * @param string $where_sql Additional WHERE clause SQL. | ||
| 1389 | * @param int $min_id Minimum object ID. | ||
| 1390 | * @param int $max_id Maximum object ID. | ||
| 1391 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. | ||
| 1392 | * @param string $salt Salt, used for $wpdb->prepare()'s args. | ||
| 1393 | * @return int|\WP_Error The table histogram, or \WP_Error on failure. | ||
| 1394 | */ | ||
| 1395 | 	private function table_checksum( $table, $columns, $id_column, $where_sql = '1=1', $min_id = null, $max_id = null, $strip_non_ascii = true, $salt = '' ) { | ||
| 1442 | |||
| 1443 | /** | ||
| 1444 | * Retrieve the type of the checksum. | ||
| 1445 | * | ||
| 1446 | * @access public | ||
| 1447 | * | ||
| 1448 | * @return string Type of the checksum. | ||
| 1449 | */ | ||
| 1450 | 	public function get_checksum_type() { | ||
| 1453 | |||
| 1454 | /** | ||
| 1455 | * Count the meta values in a table, within a specified range. | ||
| 1456 | * | ||
| 1457 | * @access private | ||
| 1458 | * | ||
| 1459 | * @todo Refactor to not use interpolated values when preparing the SQL query. | ||
| 1460 | * | ||
| 1461 | * @param string $table Table name. | ||
| 1462 | * @param string $where_sql Additional WHERE SQL. | ||
| 1463 | * @param int $min_id Minimum meta ID. | ||
| 1464 | * @param int $max_id Maximum meta ID. | ||
| 1465 | * @return int Number of meta values. | ||
| 1466 | */ | ||
| 1467 | 	private function meta_count( $table, $where_sql, $min_id, $max_id ) { | ||
| 1481 | |||
| 1482 | /** | ||
| 1483 | * Wraps a column name in SQL which strips non-ASCII chars. | ||
| 1484 | * This helps normalize data to avoid checksum differences caused by | ||
| 1485 | * badly encoded data in the DB. | ||
| 1486 | * | ||
| 1487 | * @param string $column_name Name of the column. | ||
| 1488 | * @return string Column name, without the non-ASCII chars. | ||
| 1489 | */ | ||
| 1490 | 	public function strip_non_ascii_sql( $column_name ) { | ||
| 1493 | |||
| 1494 | /** | ||
| 1495 | * Used in methods that are not implemented and shouldn't be invoked. | ||
| 1496 | * | ||
| 1497 | * @access private | ||
| 1498 | * @throws \Exception If this method is invoked. | ||
| 1499 | */ | ||
| 1500 | 	private function invalid_call() { | ||
| 1506 | } | ||
| 1507 | 
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.