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 rows in the `term_taxonomy` table. |
||
78 | * |
||
79 | * @access public |
||
80 | * |
||
81 | * @return int Number of terms. |
||
82 | */ |
||
83 | public function term_taxonomy_count() { |
||
87 | |||
88 | /** |
||
89 | * Retrieve the number of term relationships. |
||
90 | * |
||
91 | * @access public |
||
92 | * |
||
93 | * @return int Number of rows in the term relationships table. |
||
94 | */ |
||
95 | public function term_relationship_count() { |
||
99 | |||
100 | /** |
||
101 | * Retrieve the number of posts with a particular post status within a certain range. |
||
102 | * |
||
103 | * @access public |
||
104 | * |
||
105 | * @todo Prepare the SQL query before executing it. |
||
106 | * |
||
107 | * @param string $status Post status. |
||
|
|||
108 | * @param int $min_id Minimum post ID. |
||
109 | * @param int $max_id Maximum post ID. |
||
110 | * @return int Number of posts. |
||
111 | */ |
||
112 | View Code Duplication | public function post_count( $status = null, $min_id = null, $max_id = null ) { |
|
134 | |||
135 | /** |
||
136 | * Retrieve the posts with a particular post status. |
||
137 | * |
||
138 | * @access public |
||
139 | * |
||
140 | * @todo Implement range and actually use max_id/min_id arguments. |
||
141 | * |
||
142 | * @param string $status Post status. |
||
143 | * @param int $min_id Minimum post ID. |
||
144 | * @param int $max_id Maximum post ID. |
||
145 | * @return array Array of posts. |
||
146 | */ |
||
147 | public function get_posts( $status = null, $min_id = null, $max_id = null ) { |
||
161 | |||
162 | /** |
||
163 | * Retrieve a post object by the post ID. |
||
164 | * |
||
165 | * @access public |
||
166 | * |
||
167 | * @param int $id Post ID. |
||
168 | * @return \WP_Post Post object. |
||
169 | */ |
||
170 | public function get_post( $id ) { |
||
173 | |||
174 | /** |
||
175 | * Update or insert a post. |
||
176 | * |
||
177 | * @access public |
||
178 | * |
||
179 | * @param \WP_Post $post Post object. |
||
180 | * @param bool $silent Whether to perform a silent action. Not used in this implementation. |
||
181 | */ |
||
182 | public function upsert_post( $post, $silent = false ) { |
||
241 | |||
242 | /** |
||
243 | * Delete a post by the post ID. |
||
244 | * |
||
245 | * @access public |
||
246 | * |
||
247 | * @param int $post_id Post ID. |
||
248 | */ |
||
249 | public function delete_post( $post_id ) { |
||
252 | |||
253 | /** |
||
254 | * Retrieve the checksum for posts within a range. |
||
255 | * |
||
256 | * @access public |
||
257 | * |
||
258 | * @param int $min_id Minimum post ID. |
||
259 | * @param int $max_id Maximum post ID. |
||
260 | * @return int The checksum. |
||
261 | */ |
||
262 | public function posts_checksum( $min_id = null, $max_id = null ) { |
||
266 | |||
267 | /** |
||
268 | * Retrieve the checksum for post meta within a range. |
||
269 | * |
||
270 | * @access public |
||
271 | * |
||
272 | * @param int $min_id Minimum post meta ID. |
||
273 | * @param int $max_id Maximum post meta ID. |
||
274 | * @return int The checksum. |
||
275 | */ |
||
276 | public function post_meta_checksum( $min_id = null, $max_id = null ) { |
||
280 | |||
281 | /** |
||
282 | * Retrieve the number of comments with a particular comment status within a certain range. |
||
283 | * |
||
284 | * @access public |
||
285 | * |
||
286 | * @todo Prepare the SQL query before executing it. |
||
287 | * |
||
288 | * @param string $status Comment status. |
||
289 | * @param int $min_id Minimum comment ID. |
||
290 | * @param int $max_id Maximum comment ID. |
||
291 | * @return int Number of comments. |
||
292 | */ |
||
293 | View Code Duplication | public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
|
315 | |||
316 | /** |
||
317 | * Translate a comment status to a value of the comment_approved field. |
||
318 | * |
||
319 | * @access private |
||
320 | * |
||
321 | * @param string $status Comment status. |
||
322 | * @return string|bool New comment_approved value, false if the status doesn't affect it. |
||
323 | */ |
||
324 | private function comment_status_to_approval_value( $status ) { |
||
342 | |||
343 | /** |
||
344 | * Retrieve the comments with a particular comment status. |
||
345 | * |
||
346 | * @access public |
||
347 | * |
||
348 | * @todo Implement range and actually use max_id/min_id arguments. |
||
349 | * |
||
350 | * @param string $status Comment status. |
||
351 | * @param int $min_id Minimum comment ID. |
||
352 | * @param int $max_id Maximum comment ID. |
||
353 | * @return array Array of comments. |
||
354 | */ |
||
355 | public function get_comments( $status = null, $min_id = null, $max_id = null ) { |
||
367 | |||
368 | /** |
||
369 | * Retrieve a comment object by the comment ID. |
||
370 | * |
||
371 | * @access public |
||
372 | * |
||
373 | * @param int $id Comment ID. |
||
374 | * @return \WP_Comment Comment object. |
||
375 | */ |
||
376 | public function get_comment( $id ) { |
||
379 | |||
380 | /** |
||
381 | * Update or insert a comment. |
||
382 | * |
||
383 | * @access public |
||
384 | * |
||
385 | * @param \WP_Comment $comment Comment object. |
||
386 | */ |
||
387 | public function upsert_comment( $comment ) { |
||
432 | |||
433 | /** |
||
434 | * Trash a comment by the comment ID. |
||
435 | * |
||
436 | * @access public |
||
437 | * |
||
438 | * @param int $comment_id Comment ID. |
||
439 | */ |
||
440 | public function trash_comment( $comment_id ) { |
||
443 | |||
444 | /** |
||
445 | * Delete a comment by the comment ID. |
||
446 | * |
||
447 | * @access public |
||
448 | * |
||
449 | * @param int $comment_id Comment ID. |
||
450 | */ |
||
451 | public function delete_comment( $comment_id ) { |
||
454 | |||
455 | /** |
||
456 | * Mark a comment by the comment ID as spam. |
||
457 | * |
||
458 | * @access public |
||
459 | * |
||
460 | * @param int $comment_id Comment ID. |
||
461 | */ |
||
462 | public function spam_comment( $comment_id ) { |
||
465 | |||
466 | /** |
||
467 | * Trash the comments of a post. |
||
468 | * |
||
469 | * @access public |
||
470 | * |
||
471 | * @param int $post_id Post ID. |
||
472 | * @param array $statuses Post statuses. Not used in this implementation. |
||
473 | */ |
||
474 | public function trashed_post_comments( $post_id, $statuses ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
477 | |||
478 | /** |
||
479 | * Untrash the comments of a post. |
||
480 | * |
||
481 | * @access public |
||
482 | * |
||
483 | * @param int $post_id Post ID. |
||
484 | */ |
||
485 | public function untrashed_post_comments( $post_id ) { |
||
488 | |||
489 | /** |
||
490 | * Retrieve the checksum for comments within a range. |
||
491 | * |
||
492 | * @access public |
||
493 | * |
||
494 | * @param int $min_id Minimum comment ID. |
||
495 | * @param int $max_id Maximum comment ID. |
||
496 | * @return int The checksum. |
||
497 | */ |
||
498 | public function comments_checksum( $min_id = null, $max_id = null ) { |
||
502 | |||
503 | /** |
||
504 | * Retrieve the checksum for comment meta within a range. |
||
505 | * |
||
506 | * @access public |
||
507 | * |
||
508 | * @param int $min_id Minimum comment meta ID. |
||
509 | * @param int $max_id Maximum comment meta ID. |
||
510 | * @return int The checksum. |
||
511 | */ |
||
512 | public function comment_meta_checksum( $min_id = null, $max_id = null ) { |
||
516 | |||
517 | /** |
||
518 | * Retrieve the checksum for all options. |
||
519 | * |
||
520 | * @access public |
||
521 | * |
||
522 | * @return int The checksum. |
||
523 | */ |
||
524 | public function options_checksum() { |
||
531 | |||
532 | /** |
||
533 | * Update the value of an option. |
||
534 | * |
||
535 | * @access public |
||
536 | * |
||
537 | * @param string $option Option name. |
||
538 | * @param mixed $value Option value. |
||
539 | * @return bool False if value was not updated and true if value was updated. |
||
540 | */ |
||
541 | public function update_option( $option, $value ) { |
||
544 | |||
545 | /** |
||
546 | * Retrieve an option value based on an option name. |
||
547 | * |
||
548 | * @access public |
||
549 | * |
||
550 | * @param string $option Name of option to retrieve. |
||
551 | * @param mixed $default Optional. Default value to return if the option does not exist. |
||
552 | * @return mixed Value set for the option. |
||
553 | */ |
||
554 | public function get_option( $option, $default = false ) { |
||
557 | |||
558 | /** |
||
559 | * Remove an option by name. |
||
560 | * |
||
561 | * @access public |
||
562 | * |
||
563 | * @param string $option Name of option to remove. |
||
564 | * @return bool True, if option is successfully deleted. False on failure. |
||
565 | */ |
||
566 | public function delete_option( $option ) { |
||
569 | |||
570 | /** |
||
571 | * Change the features that the current theme supports. |
||
572 | * Intentionally not implemented in this replicastore. |
||
573 | * |
||
574 | * @access public |
||
575 | * |
||
576 | * @param array $theme_support Features that the theme supports. |
||
577 | */ |
||
578 | public function set_theme_support( $theme_support ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
581 | |||
582 | /** |
||
583 | * Whether the current theme supports a certain feature. |
||
584 | * |
||
585 | * @access public |
||
586 | * |
||
587 | * @param string $feature Name of the feature. |
||
588 | */ |
||
589 | public function current_theme_supports( $feature ) { |
||
592 | |||
593 | /** |
||
594 | * Retrieve metadata for the specified object. |
||
595 | * |
||
596 | * @access public |
||
597 | * |
||
598 | * @param string $type Meta type. |
||
599 | * @param int $object_id ID of the object. |
||
600 | * @param string $meta_key Meta key. |
||
601 | * @param bool $single If true, return only the first value of the specified meta_key. |
||
602 | * |
||
603 | * @return mixed Single metadata value, or array of values. |
||
604 | */ |
||
605 | public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) { |
||
608 | |||
609 | /** |
||
610 | * Stores remote meta key/values alongside an ID mapping key. |
||
611 | * |
||
612 | * @access public |
||
613 | * |
||
614 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
615 | * |
||
616 | * @param string $type Meta type. |
||
617 | * @param int $object_id ID of the object. |
||
618 | * @param string $meta_key Meta key. |
||
619 | * @param mixed $meta_value Meta value. |
||
620 | * @param int $meta_id ID of the meta. |
||
621 | * |
||
622 | * @return bool False if meta table does not exist, true otherwise. |
||
623 | */ |
||
624 | public function upsert_metadata( $type, $object_id, $meta_key, $meta_value, $meta_id ) { |
||
666 | |||
667 | /** |
||
668 | * Delete metadata for the specified object. |
||
669 | * |
||
670 | * @access public |
||
671 | * |
||
672 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
673 | * |
||
674 | * @param string $type Meta type. |
||
675 | * @param int $object_id ID of the object. |
||
676 | * @param array $meta_ids IDs of the meta objects to delete. |
||
677 | */ |
||
678 | public function delete_metadata( $type, $object_id, $meta_ids ) { |
||
696 | |||
697 | /** |
||
698 | * Delete metadata with a certain key for the specified objects. |
||
699 | * |
||
700 | * @access public |
||
701 | * |
||
702 | * @todo Test this out to make sure it works as expected. |
||
703 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
704 | * |
||
705 | * @param string $type Meta type. |
||
706 | * @param array $object_ids IDs of the objects. |
||
707 | * @param string $meta_key Meta key. |
||
708 | */ |
||
709 | public function delete_batch_metadata( $type, $object_ids, $meta_key ) { |
||
725 | |||
726 | /** |
||
727 | * Retrieve value of a constant based on the constant name. |
||
728 | * |
||
729 | * @access public |
||
730 | * |
||
731 | * @param string $constant Name of constant to retrieve. |
||
732 | * @return mixed Value set for the constant. |
||
733 | */ |
||
734 | public function get_constant( $constant ) { |
||
743 | |||
744 | /** |
||
745 | * Set the value of a constant. |
||
746 | * |
||
747 | * @access public |
||
748 | * |
||
749 | * @param string $constant Name of constant to retrieve. |
||
750 | * @param mixed $value Value set for the constant. |
||
751 | */ |
||
752 | public function set_constant( $constant, $value ) { |
||
755 | |||
756 | /** |
||
757 | * Retrieve the number of the available updates of a certain type. |
||
758 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
759 | * |
||
760 | * @access public |
||
761 | * |
||
762 | * @param string $type Type of updates to retrieve. |
||
763 | * @return int|null Number of updates available, `null` if type is invalid or missing. |
||
764 | */ |
||
765 | public function get_updates( $type ) { |
||
774 | |||
775 | /** |
||
776 | * Set the available updates of a certain type. |
||
777 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
778 | * |
||
779 | * @access public |
||
780 | * |
||
781 | * @param string $type Type of updates to set. |
||
782 | * @param int $updates Total number of updates. |
||
783 | */ |
||
784 | public function set_updates( $type, $updates ) { |
||
789 | |||
790 | /** |
||
791 | * Retrieve a callable value based on its name. |
||
792 | * |
||
793 | * @access public |
||
794 | * |
||
795 | * @param string $name Name of the callable to retrieve. |
||
796 | * @return mixed Value of the callable. |
||
797 | */ |
||
798 | public function get_callable( $name ) { |
||
807 | |||
808 | /** |
||
809 | * Update the value of a callable. |
||
810 | * |
||
811 | * @access public |
||
812 | * |
||
813 | * @param string $name Callable name. |
||
814 | * @param mixed $value Callable value. |
||
815 | */ |
||
816 | public function set_callable( $name, $value ) { |
||
819 | |||
820 | /** |
||
821 | * Retrieve a network option value based on a network option name. |
||
822 | * |
||
823 | * @access public |
||
824 | * |
||
825 | * @param string $option Name of network option to retrieve. |
||
826 | * @return mixed Value set for the network option. |
||
827 | */ |
||
828 | public function get_site_option( $option ) { |
||
831 | |||
832 | /** |
||
833 | * Update the value of a network option. |
||
834 | * |
||
835 | * @access public |
||
836 | * |
||
837 | * @param string $option Network option name. |
||
838 | * @param mixed $value Network option value. |
||
839 | * @return bool False if value was not updated and true if value was updated. |
||
840 | */ |
||
841 | public function update_site_option( $option, $value ) { |
||
844 | |||
845 | /** |
||
846 | * Remove a network option by name. |
||
847 | * |
||
848 | * @access public |
||
849 | * |
||
850 | * @param string $option Name of option to remove. |
||
851 | * @return bool True, if option is successfully deleted. False on failure. |
||
852 | */ |
||
853 | public function delete_site_option( $option ) { |
||
856 | |||
857 | /** |
||
858 | * Retrieve the terms from a particular taxonomy. |
||
859 | * |
||
860 | * @access public |
||
861 | * |
||
862 | * @param string $taxonomy Taxonomy slug. |
||
863 | * @return array Array of terms. |
||
864 | */ |
||
865 | public function get_terms( $taxonomy ) { |
||
868 | |||
869 | /** |
||
870 | * Retrieve a particular term. |
||
871 | * |
||
872 | * @access public |
||
873 | * |
||
874 | * @param string $taxonomy Taxonomy slug. |
||
875 | * @param int $term_id ID of the term. |
||
876 | * @param bool $is_term_id Whether this is a `term_id` or a `term_taxonomy_id`. |
||
877 | * @return \WP_Term|\WP_Error Term object on success, \WP_Error object on failure. |
||
878 | */ |
||
879 | public function get_term( $taxonomy, $term_id, $is_term_id = true ) { |
||
887 | |||
888 | /** |
||
889 | * Verify a taxonomy is legitimate and register it if necessary. |
||
890 | * |
||
891 | * @access private |
||
892 | * |
||
893 | * @param string $taxonomy Taxonomy slug. |
||
894 | * @return bool|void|\WP_Error True if already exists; void if it was registered; \WP_Error on error. |
||
895 | */ |
||
896 | private function ensure_taxonomy( $taxonomy ) { |
||
915 | |||
916 | /** |
||
917 | * Retrieve all terms from a taxonomy that are related to an object with a particular ID. |
||
918 | * |
||
919 | * @access public |
||
920 | * |
||
921 | * @param int $object_id Object ID. |
||
922 | * @param string $taxonomy Taxonomy slug. |
||
923 | * @return array|bool|\WP_Error Array of terms on success, `false` if no terms or post doesn't exist, \WP_Error on failure. |
||
924 | */ |
||
925 | public function get_the_terms( $object_id, $taxonomy ) { |
||
928 | |||
929 | /** |
||
930 | * Insert or update a term. |
||
931 | * |
||
932 | * @access public |
||
933 | * |
||
934 | * @param \WP_Term $term_object Term object. |
||
935 | * @return array|bool|\WP_Error Array of term_id and term_taxonomy_id if updated, true if inserted, \WP_Error on failure. |
||
936 | */ |
||
937 | public function update_term( $term_object ) { |
||
970 | |||
971 | /** |
||
972 | * Delete a term by the term ID and its corresponding taxonomy. |
||
973 | * |
||
974 | * @access public |
||
975 | * |
||
976 | * @param int $term_id Term ID. |
||
977 | * @param string $taxonomy Taxonomy slug. |
||
978 | * @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. |
||
979 | */ |
||
980 | public function delete_term( $term_id, $taxonomy ) { |
||
983 | |||
984 | /** |
||
985 | * Add/update terms of a particular taxonomy of an object with the specified ID. |
||
986 | * |
||
987 | * @access public |
||
988 | * |
||
989 | * @param int $object_id The object to relate to. |
||
990 | * @param string $taxonomy The context in which to relate the term to the object. |
||
991 | * @param string|int|array $terms A single term slug, single term id, or array of either term slugs or ids. |
||
992 | * @param bool $append Optional. If false will delete difference of terms. Default false. |
||
993 | */ |
||
994 | public function update_object_terms( $object_id, $taxonomy, $terms, $append ) { |
||
997 | |||
998 | /** |
||
999 | * Remove certain term relationships from the specified object. |
||
1000 | * |
||
1001 | * @access public |
||
1002 | * |
||
1003 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
1004 | * |
||
1005 | * @param int $object_id ID of the object. |
||
1006 | * @param array $tt_ids Term taxonomy IDs. |
||
1007 | * @return bool True on success, false on failure. |
||
1008 | */ |
||
1009 | public function delete_object_terms( $object_id, $tt_ids ) { |
||
1054 | |||
1055 | /** |
||
1056 | * Retrieve the number of users. |
||
1057 | * Not supported in this replicastore. |
||
1058 | * |
||
1059 | * @access public |
||
1060 | */ |
||
1061 | public function user_count() { |
||
1064 | |||
1065 | /** |
||
1066 | * Retrieve a user object by the user ID. |
||
1067 | * |
||
1068 | * @access public |
||
1069 | * |
||
1070 | * @param int $user_id User ID. |
||
1071 | * @return \WP_User User object. |
||
1072 | */ |
||
1073 | public function get_user( $user_id ) { |
||
1076 | |||
1077 | /** |
||
1078 | * Insert or update a user. |
||
1079 | * Not supported in this replicastore. |
||
1080 | * |
||
1081 | * @access public |
||
1082 | * @throws \Exception If this method is invoked. |
||
1083 | * |
||
1084 | * @param \WP_User $user User object. |
||
1085 | */ |
||
1086 | public function upsert_user( $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1089 | |||
1090 | /** |
||
1091 | * Delete a user. |
||
1092 | * Not supported in this replicastore. |
||
1093 | * |
||
1094 | * @access public |
||
1095 | * @throws \Exception If this method is invoked. |
||
1096 | * |
||
1097 | * @param int $user_id User ID. |
||
1098 | */ |
||
1099 | public function delete_user( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1102 | |||
1103 | /** |
||
1104 | * Update/insert user locale. |
||
1105 | * Not supported in this replicastore. |
||
1106 | * |
||
1107 | * @access public |
||
1108 | * @throws \Exception If this method is invoked. |
||
1109 | * |
||
1110 | * @param int $user_id User ID. |
||
1111 | * @param string $local The user locale. |
||
1112 | */ |
||
1113 | public function upsert_user_locale( $user_id, $local ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1116 | |||
1117 | /** |
||
1118 | * Delete user locale. |
||
1119 | * Not supported in this replicastore. |
||
1120 | * |
||
1121 | * @access public |
||
1122 | * @throws \Exception If this method is invoked. |
||
1123 | * |
||
1124 | * @param int $user_id User ID. |
||
1125 | */ |
||
1126 | public function delete_user_locale( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1129 | |||
1130 | /** |
||
1131 | * Retrieve the user locale. |
||
1132 | * |
||
1133 | * @access public |
||
1134 | * |
||
1135 | * @param int $user_id User ID. |
||
1136 | * @return string The user locale. |
||
1137 | */ |
||
1138 | public function get_user_locale( $user_id ) { |
||
1141 | |||
1142 | /** |
||
1143 | * Retrieve the allowed mime types for the user. |
||
1144 | * Not supported in this replicastore. |
||
1145 | * |
||
1146 | * @access public |
||
1147 | * |
||
1148 | * @param int $user_id User ID. |
||
1149 | */ |
||
1150 | public function get_allowed_mime_types( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1153 | |||
1154 | /** |
||
1155 | * Retrieve all the checksums we are interested in. |
||
1156 | * Currently that is posts, comments, post meta and comment meta. |
||
1157 | * |
||
1158 | * @access public |
||
1159 | * |
||
1160 | * @return array Checksums. |
||
1161 | */ |
||
1162 | public function checksum_all() { |
||
1173 | |||
1174 | /** |
||
1175 | * Retrieve the columns that are needed to calculate a checksum for an object type. |
||
1176 | * |
||
1177 | * @access public |
||
1178 | * |
||
1179 | * @todo Refactor to not use interpolated values and prepare the SQL query. |
||
1180 | * |
||
1181 | * @param string $object_type Object type. |
||
1182 | * @return array|bool Columns, or false if invalid object type is specified. |
||
1183 | */ |
||
1184 | public function get_checksum_columns_for_object_type( $object_type ) { |
||
1204 | |||
1205 | /** |
||
1206 | * Retrieve the checksum histogram for a specific object type. |
||
1207 | * |
||
1208 | * @access public |
||
1209 | * |
||
1210 | * @todo Refactor to not use interpolated values and properly prepare the SQL query. |
||
1211 | * |
||
1212 | * @param string $object_type Object type. |
||
1213 | * @param int $buckets Number of buckets to split the objects to. |
||
1214 | * @param int $start_id Minimum object ID. |
||
1215 | * @param int $end_id Maximum object ID. |
||
1216 | * @param array $columns Table columns to calculate the checksum from. |
||
1217 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
1218 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
1219 | * @return array The checksum histogram. |
||
1220 | */ |
||
1221 | public function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true, $salt = '' ) { |
||
1328 | |||
1329 | /** |
||
1330 | * Retrieve the checksum for a specific database table. |
||
1331 | * |
||
1332 | * @access private |
||
1333 | * |
||
1334 | * @todo Refactor to properly prepare the SQL query. |
||
1335 | * |
||
1336 | * @param string $table Table name. |
||
1337 | * @param array $columns Table columns to calculate the checksum from. |
||
1338 | * @param int $id_column Name of the unique ID column. |
||
1339 | * @param string $where_sql Additional WHERE clause SQL. |
||
1340 | * @param int $min_id Minimum object ID. |
||
1341 | * @param int $max_id Maximum object ID. |
||
1342 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
1343 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
1344 | * @return int|\WP_Error The table histogram, or \WP_Error on failure. |
||
1345 | */ |
||
1346 | private function table_checksum( $table, $columns, $id_column, $where_sql = '1=1', $min_id = null, $max_id = null, $strip_non_ascii = true, $salt = '' ) { |
||
1393 | |||
1394 | /** |
||
1395 | * Retrieve the type of the checksum. |
||
1396 | * |
||
1397 | * @access public |
||
1398 | * |
||
1399 | * @return string Type of the checksum. |
||
1400 | */ |
||
1401 | public function get_checksum_type() { |
||
1404 | |||
1405 | /** |
||
1406 | * Count the meta values in a table, within a specified range. |
||
1407 | * |
||
1408 | * @access private |
||
1409 | * |
||
1410 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
1411 | * |
||
1412 | * @param string $table Table name. |
||
1413 | * @param string $where_sql Additional WHERE SQL. |
||
1414 | * @param int $min_id Minimum meta ID. |
||
1415 | * @param int $max_id Maximum meta ID. |
||
1416 | * @return int Number of meta values. |
||
1417 | */ |
||
1418 | private function meta_count( $table, $where_sql, $min_id, $max_id ) { |
||
1432 | |||
1433 | /** |
||
1434 | * Wraps a column name in SQL which strips non-ASCII chars. |
||
1435 | * This helps normalize data to avoid checksum differences caused by |
||
1436 | * badly encoded data in the DB. |
||
1437 | * |
||
1438 | * @param string $column_name Name of the column. |
||
1439 | * @return string Column name, without the non-ASCII chars. |
||
1440 | */ |
||
1441 | public function strip_non_ascii_sql( $column_name ) { |
||
1444 | |||
1445 | /** |
||
1446 | * Used in methods that are not implemented and shouldn't be invoked. |
||
1447 | * |
||
1448 | * @access private |
||
1449 | * @throws \Exception If this method is invoked. |
||
1450 | */ |
||
1451 | private function invalid_call() { |
||
1457 | } |
||
1458 |
This check looks for
@param
annotations 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.