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:
1 | <?php |
||
8 | class VideoPress_CLI extends WP_CLI_Command { |
||
9 | /** |
||
10 | * Import a VideoPress Video |
||
11 | * |
||
12 | * ## OPTIONS |
||
13 | * |
||
14 | * <guid>: Import the video with the specified guid |
||
15 | * |
||
16 | * ## EXAMPLES |
||
17 | * |
||
18 | * wp videopress import kUJmAcSf |
||
19 | * |
||
20 | */ |
||
21 | public function import( $args ) { |
||
30 | |||
31 | /** |
||
32 | * Manually runs the job to cleanup videos from the media library that failed during the upload process. |
||
33 | * |
||
34 | * ## EXAMPLES |
||
35 | * |
||
36 | * wp videopress cleanup_videos |
||
37 | */ |
||
38 | public function cleanup_videos() { |
||
43 | |||
44 | /** |
||
45 | * List out all of the crons that can be run. |
||
46 | * |
||
47 | * ## EXAMPLES |
||
48 | * |
||
49 | * wp videopress list_crons |
||
50 | */ |
||
51 | public function list_crons() { |
||
80 | |||
81 | /** |
||
82 | * Checks for the current status of a cron job. |
||
83 | * |
||
84 | * ## OPTIONS |
||
85 | * |
||
86 | * <cron_name>: The name of the cron job to check |
||
87 | * |
||
88 | * ## EXAMPLES |
||
89 | * |
||
90 | * wp videopress cron_status cleanup |
||
91 | */ |
||
92 | public function cron_status( $args ) { |
||
93 | |||
94 | if ( ! isset( $args[0] ) ) { |
||
95 | return WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
||
96 | } |
||
97 | |||
98 | $scheduler = VideoPress_Scheduler::init(); |
||
99 | |||
100 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
||
101 | return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
||
102 | } |
||
103 | |||
104 | $time = $scheduler->check_cron( $args[0] ); |
||
105 | |||
106 | View Code Duplication | if ( ! $time ) { |
|
107 | WP_CLI::success( __( 'The cron is not scheduled to run.', 'jetpack' ) ); |
||
108 | |||
109 | } else { |
||
110 | WP_CLI::success( sprintf( __( 'Cron will run at: %s GMT' ), 'jetpack' ), gmdate( 'Y-m-d H:i:s', $time ) ); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Actives the given cron job |
||
116 | * |
||
117 | * ## OPTIONS |
||
118 | * |
||
119 | * <cron_name>: The name of the cron job to check |
||
120 | * |
||
121 | * ## EXAMPLES |
||
122 | * |
||
123 | * wp videopress activate_cron cleanup |
||
124 | */ |
||
125 | View Code Duplication | public function activate_cron( $args ) { |
|
141 | |||
142 | /** |
||
143 | * Actives the given cron job |
||
144 | * |
||
145 | * ## OPTIONS |
||
146 | * |
||
147 | * <cron_name>: The name of the cron job to check |
||
148 | * |
||
149 | * ## EXAMPLES |
||
150 | * |
||
151 | * wp videopress deactivate_cron cleanup |
||
152 | */ |
||
153 | View Code Duplication | public function deactivate_cron( $args ) { |
|
169 | } |
||
170 | |||
172 | } |