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 ) { |
||
348 | |||
349 | /** |
||
350 | * Retrieve the comments with a particular comment status. |
||
351 | * |
||
352 | * @access public |
||
353 | * |
||
354 | * @todo Implement range and actually use max_id/min_id arguments. |
||
355 | * |
||
356 | * @param string $status Comment status. |
||
357 | * @param int $min_id Minimum comment ID. |
||
358 | * @param int $max_id Maximum comment ID. |
||
359 | * @return array Array of comments. |
||
360 | */ |
||
361 | public function get_comments( $status = null, $min_id = null, $max_id = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
373 | |||
374 | /** |
||
375 | * Retrieve a comment object by the comment ID. |
||
376 | * |
||
377 | * @access public |
||
378 | * |
||
379 | * @param int $id Comment ID. |
||
380 | * @return \WP_Comment Comment object. |
||
381 | */ |
||
382 | public function get_comment( $id ) { |
||
385 | |||
386 | /** |
||
387 | * Update or insert a comment. |
||
388 | * |
||
389 | * @access public |
||
390 | * |
||
391 | * @param \WP_Comment $comment Comment object. |
||
392 | */ |
||
393 | public function upsert_comment( $comment ) { |
||
440 | |||
441 | /** |
||
442 | * Trash a comment by the comment ID. |
||
443 | * |
||
444 | * @access public |
||
445 | * |
||
446 | * @param int $comment_id Comment ID. |
||
447 | */ |
||
448 | public function trash_comment( $comment_id ) { |
||
451 | |||
452 | /** |
||
453 | * Delete a comment by the comment ID. |
||
454 | * |
||
455 | * @access public |
||
456 | * |
||
457 | * @param int $comment_id Comment ID. |
||
458 | */ |
||
459 | public function delete_comment( $comment_id ) { |
||
462 | |||
463 | /** |
||
464 | * Mark a comment by the comment ID as spam. |
||
465 | * |
||
466 | * @access public |
||
467 | * |
||
468 | * @param int $comment_id Comment ID. |
||
469 | */ |
||
470 | public function spam_comment( $comment_id ) { |
||
473 | |||
474 | /** |
||
475 | * Trash the comments of a post. |
||
476 | * |
||
477 | * @access public |
||
478 | * |
||
479 | * @param int $post_id Post ID. |
||
480 | * @param array $statuses Post statuses. Not used in this implementation. |
||
481 | */ |
||
482 | public function trashed_post_comments( $post_id, $statuses ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
485 | |||
486 | /** |
||
487 | * Untrash the comments of a post. |
||
488 | * |
||
489 | * @access public |
||
490 | * |
||
491 | * @param int $post_id Post ID. |
||
492 | */ |
||
493 | public function untrashed_post_comments( $post_id ) { |
||
496 | |||
497 | /** |
||
498 | * Retrieve the checksum for comments within a range. |
||
499 | * |
||
500 | * @access public |
||
501 | * |
||
502 | * @param int $min_id Minimum comment ID. |
||
503 | * @param int $max_id Maximum comment ID. |
||
504 | * @return int The checksum. |
||
505 | */ |
||
506 | public function comments_checksum( $min_id = null, $max_id = null ) { |
||
510 | |||
511 | /** |
||
512 | * Retrieve the checksum for comment meta within a range. |
||
513 | * |
||
514 | * @access public |
||
515 | * |
||
516 | * @param int $min_id Minimum comment meta ID. |
||
517 | * @param int $max_id Maximum comment meta ID. |
||
518 | * @return int The checksum. |
||
519 | */ |
||
520 | public function comment_meta_checksum( $min_id = null, $max_id = null ) { |
||
524 | |||
525 | /** |
||
526 | * Retrieve the checksum for all options. |
||
527 | * |
||
528 | * @access public |
||
529 | * |
||
530 | * @return int The checksum. |
||
531 | */ |
||
532 | public function options_checksum() { |
||
539 | |||
540 | /** |
||
541 | * Update the value of an option. |
||
542 | * |
||
543 | * @access public |
||
544 | * |
||
545 | * @param string $option Option name. |
||
546 | * @param mixed $value Option value. |
||
547 | * @return bool False if value was not updated and true if value was updated. |
||
548 | */ |
||
549 | public function update_option( $option, $value ) { |
||
552 | |||
553 | /** |
||
554 | * Retrieve an option value based on an option name. |
||
555 | * |
||
556 | * @access public |
||
557 | * |
||
558 | * @param string $option Name of option to retrieve. |
||
559 | * @param mixed $default Optional. Default value to return if the option does not exist. |
||
560 | * @return mixed Value set for the option. |
||
561 | */ |
||
562 | public function get_option( $option, $default = false ) { |
||
565 | |||
566 | /** |
||
567 | * Remove an option by name. |
||
568 | * |
||
569 | * @access public |
||
570 | * |
||
571 | * @param string $option Name of option to remove. |
||
572 | * @return bool True, if option is successfully deleted. False on failure. |
||
573 | */ |
||
574 | public function delete_option( $option ) { |
||
577 | |||
578 | /** |
||
579 | * Change the info of the current theme. |
||
580 | * |
||
581 | * @access public |
||
582 | * |
||
583 | * @param array $theme_info Theme info array. |
||
584 | */ |
||
585 | public function set_theme_info( $theme_info ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
588 | |||
589 | /** |
||
590 | * Whether the current theme supports a certain feature. |
||
591 | * |
||
592 | * @access public |
||
593 | * |
||
594 | * @param string $feature Name of the feature. |
||
595 | */ |
||
596 | public function current_theme_supports( $feature ) { |
||
599 | |||
600 | /** |
||
601 | * Retrieve metadata for the specified object. |
||
602 | * |
||
603 | * @access public |
||
604 | * |
||
605 | * @param string $type Meta type. |
||
606 | * @param int $object_id ID of the object. |
||
607 | * @param string $meta_key Meta key. |
||
608 | * @param bool $single If true, return only the first value of the specified meta_key. |
||
609 | * |
||
610 | * @return mixed Single metadata value, or array of values. |
||
611 | */ |
||
612 | public function get_metadata( $type, $object_id, $meta_key = '', $single = false ) { |
||
615 | |||
616 | /** |
||
617 | * Stores remote meta key/values alongside an ID mapping key. |
||
618 | * |
||
619 | * @access public |
||
620 | * |
||
621 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
622 | * |
||
623 | * @param string $type Meta type. |
||
624 | * @param int $object_id ID of the object. |
||
625 | * @param string $meta_key Meta key. |
||
626 | * @param mixed $meta_value Meta value. |
||
627 | * @param int $meta_id ID of the meta. |
||
628 | * |
||
629 | * @return bool False if meta table does not exist, true otherwise. |
||
630 | */ |
||
631 | public function upsert_metadata( $type, $object_id, $meta_key, $meta_value, $meta_id ) { |
||
673 | |||
674 | /** |
||
675 | * Delete metadata for the specified object. |
||
676 | * |
||
677 | * @access public |
||
678 | * |
||
679 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
680 | * |
||
681 | * @param string $type Meta type. |
||
682 | * @param int $object_id ID of the object. |
||
683 | * @param array $meta_ids IDs of the meta objects to delete. |
||
684 | */ |
||
685 | public function delete_metadata( $type, $object_id, $meta_ids ) { |
||
703 | |||
704 | /** |
||
705 | * Delete metadata with a certain key for the specified objects. |
||
706 | * |
||
707 | * @access public |
||
708 | * |
||
709 | * @todo Test this out to make sure it works as expected. |
||
710 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
711 | * |
||
712 | * @param string $type Meta type. |
||
713 | * @param array $object_ids IDs of the objects. |
||
714 | * @param string $meta_key Meta key. |
||
715 | */ |
||
716 | public function delete_batch_metadata( $type, $object_ids, $meta_key ) { |
||
732 | |||
733 | /** |
||
734 | * Retrieve value of a constant based on the constant name. |
||
735 | * |
||
736 | * @access public |
||
737 | * |
||
738 | * @param string $constant Name of constant to retrieve. |
||
739 | * @return mixed Value set for the constant. |
||
740 | */ |
||
741 | public function get_constant( $constant ) { |
||
750 | |||
751 | /** |
||
752 | * Set the value of a constant. |
||
753 | * |
||
754 | * @access public |
||
755 | * |
||
756 | * @param string $constant Name of constant to retrieve. |
||
757 | * @param mixed $value Value set for the constant. |
||
758 | */ |
||
759 | public function set_constant( $constant, $value ) { |
||
762 | |||
763 | /** |
||
764 | * Retrieve the number of the available updates of a certain type. |
||
765 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
766 | * |
||
767 | * @access public |
||
768 | * |
||
769 | * @param string $type Type of updates to retrieve. |
||
770 | * @return int|null Number of updates available, `null` if type is invalid or missing. |
||
771 | */ |
||
772 | public function get_updates( $type ) { |
||
781 | |||
782 | /** |
||
783 | * Set the available updates of a certain type. |
||
784 | * Type is one of: `plugins`, `themes`, `wordpress`, `translations`, `total`, `wp_update_version`. |
||
785 | * |
||
786 | * @access public |
||
787 | * |
||
788 | * @param string $type Type of updates to set. |
||
789 | * @param int $updates Total number of updates. |
||
790 | */ |
||
791 | public function set_updates( $type, $updates ) { |
||
796 | |||
797 | /** |
||
798 | * Retrieve a callable value based on its name. |
||
799 | * |
||
800 | * @access public |
||
801 | * |
||
802 | * @param string $name Name of the callable to retrieve. |
||
803 | * @return mixed Value of the callable. |
||
804 | */ |
||
805 | public function get_callable( $name ) { |
||
814 | |||
815 | /** |
||
816 | * Update the value of a callable. |
||
817 | * |
||
818 | * @access public |
||
819 | * |
||
820 | * @param string $name Callable name. |
||
821 | * @param mixed $value Callable value. |
||
822 | */ |
||
823 | public function set_callable( $name, $value ) { |
||
826 | |||
827 | /** |
||
828 | * Retrieve a network option value based on a network option name. |
||
829 | * |
||
830 | * @access public |
||
831 | * |
||
832 | * @param string $option Name of network option to retrieve. |
||
833 | * @return mixed Value set for the network option. |
||
834 | */ |
||
835 | public function get_site_option( $option ) { |
||
838 | |||
839 | /** |
||
840 | * Update the value of a network option. |
||
841 | * |
||
842 | * @access public |
||
843 | * |
||
844 | * @param string $option Network option name. |
||
845 | * @param mixed $value Network option value. |
||
846 | * @return bool False if value was not updated and true if value was updated. |
||
847 | */ |
||
848 | public function update_site_option( $option, $value ) { |
||
851 | |||
852 | /** |
||
853 | * Remove a network option by name. |
||
854 | * |
||
855 | * @access public |
||
856 | * |
||
857 | * @param string $option Name of option to remove. |
||
858 | * @return bool True, if option is successfully deleted. False on failure. |
||
859 | */ |
||
860 | public function delete_site_option( $option ) { |
||
863 | |||
864 | /** |
||
865 | * Retrieve the terms from a particular taxonomy. |
||
866 | * |
||
867 | * @access public |
||
868 | * |
||
869 | * @param string $taxonomy Taxonomy slug. |
||
870 | * @return array Array of terms. |
||
871 | */ |
||
872 | public function get_terms( $taxonomy ) { |
||
875 | |||
876 | /** |
||
877 | * Retrieve a particular term. |
||
878 | * |
||
879 | * @access public |
||
880 | * |
||
881 | * @param string $taxonomy Taxonomy slug. |
||
882 | * @param int $term_id ID of the term. |
||
883 | * @param bool $is_term_id Whether this is a `term_id` or a `term_taxonomy_id`. |
||
884 | * @return \WP_Term|\WP_Error Term object on success, \WP_Error object on failure. |
||
885 | */ |
||
886 | public function get_term( $taxonomy, $term_id, $is_term_id = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
894 | |||
895 | /** |
||
896 | * Verify a taxonomy is legitimate and register it if necessary. |
||
897 | * |
||
898 | * @access private |
||
899 | * |
||
900 | * @param string $taxonomy Taxonomy slug. |
||
901 | * @return bool|void|\WP_Error True if already exists; void if it was registered; \WP_Error on error. |
||
902 | */ |
||
903 | private function ensure_taxonomy( $taxonomy ) { |
||
922 | |||
923 | /** |
||
924 | * Retrieve all terms from a taxonomy that are related to an object with a particular ID. |
||
925 | * |
||
926 | * @access public |
||
927 | * |
||
928 | * @param int $object_id Object ID. |
||
929 | * @param string $taxonomy Taxonomy slug. |
||
930 | * @return array|bool|\WP_Error Array of terms on success, `false` if no terms or post doesn't exist, \WP_Error on failure. |
||
931 | */ |
||
932 | public function get_the_terms( $object_id, $taxonomy ) { |
||
935 | |||
936 | /** |
||
937 | * Insert or update a term. |
||
938 | * |
||
939 | * @access public |
||
940 | * |
||
941 | * @param \WP_Term $term_object Term object. |
||
942 | * @return array|bool|\WP_Error Array of term_id and term_taxonomy_id if updated, true if inserted, \WP_Error on failure. |
||
943 | */ |
||
944 | public function update_term( $term_object ) { |
||
977 | |||
978 | /** |
||
979 | * Delete a term by the term ID and its corresponding taxonomy. |
||
980 | * |
||
981 | * @access public |
||
982 | * |
||
983 | * @param int $term_id Term ID. |
||
984 | * @param string $taxonomy Taxonomy slug. |
||
985 | * @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. |
||
986 | */ |
||
987 | public function delete_term( $term_id, $taxonomy ) { |
||
990 | |||
991 | /** |
||
992 | * Add/update terms of a particular taxonomy of an object with the specified ID. |
||
993 | * |
||
994 | * @access public |
||
995 | * |
||
996 | * @param int $object_id The object to relate to. |
||
997 | * @param string $taxonomy The context in which to relate the term to the object. |
||
998 | * @param string|int|array $terms A single term slug, single term id, or array of either term slugs or ids. |
||
999 | * @param bool $append Optional. If false will delete difference of terms. Default false. |
||
1000 | */ |
||
1001 | public function update_object_terms( $object_id, $taxonomy, $terms, $append ) { |
||
1004 | |||
1005 | /** |
||
1006 | * Remove certain term relationships from the specified object. |
||
1007 | * |
||
1008 | * @access public |
||
1009 | * |
||
1010 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
1011 | * |
||
1012 | * @param int $object_id ID of the object. |
||
1013 | * @param array $tt_ids Term taxonomy IDs. |
||
1014 | * @return bool True on success, false on failure. |
||
1015 | */ |
||
1016 | public function delete_object_terms( $object_id, $tt_ids ) { |
||
1061 | |||
1062 | /** |
||
1063 | * Retrieve the number of users. |
||
1064 | * Not supported in this replicastore. |
||
1065 | * |
||
1066 | * @access public |
||
1067 | */ |
||
1068 | public function user_count() { |
||
1071 | |||
1072 | /** |
||
1073 | * Retrieve a user object by the user ID. |
||
1074 | * |
||
1075 | * @access public |
||
1076 | * |
||
1077 | * @param int $user_id User ID. |
||
1078 | * @return \WP_User User object. |
||
1079 | */ |
||
1080 | public function get_user( $user_id ) { |
||
1083 | |||
1084 | /** |
||
1085 | * Insert or update a user. |
||
1086 | * Not supported in this replicastore. |
||
1087 | * |
||
1088 | * @access public |
||
1089 | * @throws \Exception If this method is invoked. |
||
1090 | * |
||
1091 | * @param \WP_User $user User object. |
||
1092 | */ |
||
1093 | public function upsert_user( $user ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1096 | |||
1097 | /** |
||
1098 | * Delete a user. |
||
1099 | * Not supported in this replicastore. |
||
1100 | * |
||
1101 | * @access public |
||
1102 | * @throws \Exception If this method is invoked. |
||
1103 | * |
||
1104 | * @param int $user_id User ID. |
||
1105 | */ |
||
1106 | public function delete_user( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1109 | |||
1110 | /** |
||
1111 | * Update/insert user locale. |
||
1112 | * Not supported in this replicastore. |
||
1113 | * |
||
1114 | * @access public |
||
1115 | * @throws \Exception If this method is invoked. |
||
1116 | * |
||
1117 | * @param int $user_id User ID. |
||
1118 | * @param string $local The user locale. |
||
1119 | */ |
||
1120 | public function upsert_user_locale( $user_id, $local ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1123 | |||
1124 | /** |
||
1125 | * Delete user locale. |
||
1126 | * Not supported in this replicastore. |
||
1127 | * |
||
1128 | * @access public |
||
1129 | * @throws \Exception If this method is invoked. |
||
1130 | * |
||
1131 | * @param int $user_id User ID. |
||
1132 | */ |
||
1133 | public function delete_user_locale( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1136 | |||
1137 | /** |
||
1138 | * Retrieve the user locale. |
||
1139 | * |
||
1140 | * @access public |
||
1141 | * |
||
1142 | * @param int $user_id User ID. |
||
1143 | * @return string The user locale. |
||
1144 | */ |
||
1145 | public function get_user_locale( $user_id ) { |
||
1148 | |||
1149 | /** |
||
1150 | * Retrieve the allowed mime types for the user. |
||
1151 | * Not supported in this replicastore. |
||
1152 | * |
||
1153 | * @access public |
||
1154 | * |
||
1155 | * @param int $user_id User ID. |
||
1156 | */ |
||
1157 | public function get_allowed_mime_types( $user_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
||
1160 | |||
1161 | /** |
||
1162 | * Retrieve all the checksums we are interested in. |
||
1163 | * Currently that is posts, comments, post meta and comment meta. |
||
1164 | * |
||
1165 | * @access public |
||
1166 | * |
||
1167 | * @return array Checksums. |
||
1168 | */ |
||
1169 | public function checksum_all() { |
||
1180 | |||
1181 | /** |
||
1182 | * Retrieve the columns that are needed to calculate a checksum for an object type. |
||
1183 | * |
||
1184 | * @access public |
||
1185 | * |
||
1186 | * @todo Refactor to not use interpolated values and prepare the SQL query. |
||
1187 | * |
||
1188 | * @param string $object_type Object type. |
||
1189 | * @return array|bool Columns, or false if invalid object type is specified. |
||
1190 | */ |
||
1191 | public function get_checksum_columns_for_object_type( $object_type ) { |
||
1211 | |||
1212 | /** |
||
1213 | * Grabs the minimum and maximum object ids for the given parameters. |
||
1214 | * |
||
1215 | * @access public |
||
1216 | * |
||
1217 | * @param string $id_field The id column in the table to query. |
||
1218 | * @param string $object_table The table to query. |
||
1219 | * @param string $where A sql where clause without 'WHERE'. |
||
1220 | * @param int $bucket_size The maximum amount of objects to include in the query. |
||
1221 | * For `term_relationships` table, the bucket size will refer to the amount |
||
1222 | * of distinct object ids. This will likely include more database rows than |
||
1223 | * the bucket size implies. |
||
1224 | * |
||
1225 | * @return object An object with min_id and max_id properties. |
||
1226 | */ |
||
1227 | public function get_min_max_object_id( $id_field, $object_table, $where, $bucket_size ) { |
||
1246 | |||
1247 | /** |
||
1248 | * Retrieve the checksum histogram for a specific object type. |
||
1249 | * |
||
1250 | * @access public |
||
1251 | * |
||
1252 | * @todo Refactor to not use interpolated values and properly prepare the SQL query. |
||
1253 | * |
||
1254 | * @param string $object_type Object type. |
||
1255 | * @param int $buckets Number of buckets to split the objects to. |
||
1256 | * @param int $start_id Minimum object ID. |
||
1257 | * @param int $end_id Maximum object ID. |
||
1258 | * @param array $columns Table columns to calculate the checksum from. |
||
1259 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
1260 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
1261 | * @return array The checksum histogram. |
||
1262 | */ |
||
1263 | public function checksum_histogram( $object_type, $buckets, $start_id = null, $end_id = null, $columns = null, $strip_non_ascii = true, $salt = '' ) { |
||
1367 | |||
1368 | /** |
||
1369 | * Retrieve the checksum for a specific database table. |
||
1370 | * |
||
1371 | * @access private |
||
1372 | * |
||
1373 | * @todo Refactor to properly prepare the SQL query. |
||
1374 | * |
||
1375 | * @param string $table Table name. |
||
1376 | * @param array $columns Table columns to calculate the checksum from. |
||
1377 | * @param int $id_column Name of the unique ID column. |
||
1378 | * @param string $where_sql Additional WHERE clause SQL. |
||
1379 | * @param int $min_id Minimum object ID. |
||
1380 | * @param int $max_id Maximum object ID. |
||
1381 | * @param bool $strip_non_ascii Whether to strip non-ASCII characters. |
||
1382 | * @param string $salt Salt, used for $wpdb->prepare()'s args. |
||
1383 | * @return int|\WP_Error The table histogram, or \WP_Error on failure. |
||
1384 | */ |
||
1385 | private function table_checksum( $table, $columns, $id_column, $where_sql = '1=1', $min_id = null, $max_id = null, $strip_non_ascii = true, $salt = '' ) { |
||
1432 | |||
1433 | /** |
||
1434 | * Retrieve the type of the checksum. |
||
1435 | * |
||
1436 | * @access public |
||
1437 | * |
||
1438 | * @return string Type of the checksum. |
||
1439 | */ |
||
1440 | public function get_checksum_type() { |
||
1443 | |||
1444 | /** |
||
1445 | * Count the meta values in a table, within a specified range. |
||
1446 | * |
||
1447 | * @access private |
||
1448 | * |
||
1449 | * @todo Refactor to not use interpolated values when preparing the SQL query. |
||
1450 | * |
||
1451 | * @param string $table Table name. |
||
1452 | * @param string $where_sql Additional WHERE SQL. |
||
1453 | * @param int $min_id Minimum meta ID. |
||
1454 | * @param int $max_id Maximum meta ID. |
||
1455 | * @return int Number of meta values. |
||
1456 | */ |
||
1457 | private function meta_count( $table, $where_sql, $min_id, $max_id ) { |
||
1471 | |||
1472 | /** |
||
1473 | * Wraps a column name in SQL which strips non-ASCII chars. |
||
1474 | * This helps normalize data to avoid checksum differences caused by |
||
1475 | * badly encoded data in the DB. |
||
1476 | * |
||
1477 | * @param string $column_name Name of the column. |
||
1478 | * @return string Column name, without the non-ASCII chars. |
||
1479 | */ |
||
1480 | public function strip_non_ascii_sql( $column_name ) { |
||
1483 | |||
1484 | /** |
||
1485 | * Used in methods that are not implemented and shouldn't be invoked. |
||
1486 | * |
||
1487 | * @access private |
||
1488 | * @throws \Exception If this method is invoked. |
||
1489 | */ |
||
1490 | private function invalid_call() { |
||
1496 | } |
||
1497 |
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.