Completed
Push — master ( d47874...c19952 )
by Ashley
02:14
created
src/WP_Queue/Cron.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	 * @param Worker $worker
34 34
 	 * @param int    $interval
35 35
 	 */
36
-	public function __construct( $id, $worker, $interval ) {
37
-		$this->id       = strtolower( str_replace( '\\', '_', $id ) );
36
+	public function __construct($id, $worker, $interval) {
37
+		$this->id       = strtolower(str_replace('\\', '_', $id));
38 38
 		$this->worker   = $worker;
39 39
 		$this->interval = $interval;
40 40
 	}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @return bool
46 46
 	 */
47 47
 	protected function is_enabled() {
48
-		if ( defined( 'DISABLE_WP_QUEUE_CRON' ) && DISABLE_WP_QUEUE_CRON ) {
48
+		if (defined('DISABLE_WP_QUEUE_CRON') && DISABLE_WP_QUEUE_CRON) {
49 49
 			return false;
50 50
 		}
51 51
 
@@ -58,16 +58,16 @@  discard block
 block discarded – undo
58 58
 	 * @return bool
59 59
 	 */
60 60
 	public function init() {
61
-		if ( ! $this->is_enabled() ) {
61
+		if ( ! $this->is_enabled()) {
62 62
 			return false;
63 63
 		}
64 64
 
65
-		add_filter( 'cron_schedules', array( $this, 'schedule_cron' ) );
66
-		add_action( $this->id, array( $this, 'cron_worker' ) );
65
+		add_filter('cron_schedules', array($this, 'schedule_cron'));
66
+		add_action($this->id, array($this, 'cron_worker'));
67 67
 
68
-		if ( ! wp_next_scheduled( $this->id ) ) {
68
+		if ( ! wp_next_scheduled($this->id)) {
69 69
 			// Schedule health check
70
-			wp_schedule_event( time(), $this->id, $this->id );
70
+			wp_schedule_event(time(), $this->id, $this->id);
71 71
 		}
72 72
 
73 73
 		return true;
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return array
82 82
 	 */
83
-	public function schedule_cron( $schedules ) {
84
-		$schedules[ $this->id ] = array(
83
+	public function schedule_cron($schedules) {
84
+		$schedules[$this->id] = array(
85 85
 			'interval' => MINUTE_IN_SECONDS * $this->interval,
86
-			'display'  => sprintf( __( 'Every %d Minutes' ), $this->interval ),
86
+			'display'  => sprintf(__('Every %d Minutes'), $this->interval),
87 87
 		);
88 88
 
89 89
 		return $schedules;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * Process any jobs in the queue.
94 94
 	 */
95 95
 	public function cron_worker() {
96
-		if ( $this->is_worker_locked() ) {
96
+		if ($this->is_worker_locked()) {
97 97
 			return;
98 98
 		}
99 99
 
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 
102 102
 		$this->lock_worker();
103 103
 
104
-		while ( ! $this->time_exceeded() && ! $this->memory_exceeded() ) {
105
-			if ( ! $this->worker->process() ) {
104
+		while ( ! $this->time_exceeded() && ! $this->memory_exceeded()) {
105
+			if ( ! $this->worker->process()) {
106 106
 				break;
107 107
 			}
108 108
 		}
@@ -116,21 +116,21 @@  discard block
 block discarded – undo
116 116
 	 * @return bool
117 117
 	 */
118 118
 	protected function is_worker_locked() {
119
-		return (bool) get_site_transient( $this->id );
119
+		return (bool) get_site_transient($this->id);
120 120
 	}
121 121
 
122 122
 	/**
123 123
 	 * Lock the cron worker.
124 124
 	 */
125 125
 	protected function lock_worker() {
126
-		set_site_transient( $this->id, time(), 300 );
126
+		set_site_transient($this->id, time(), 300);
127 127
 	}
128 128
 
129 129
 	/**
130 130
 	 * Unlock the cron worker.
131 131
 	 */
132 132
 	protected function unlock_worker() {
133
-		delete_site_transient( $this->id );
133
+		delete_site_transient($this->id);
134 134
 	}
135 135
 
136 136
 	/**
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 	 */
144 144
 	protected function memory_exceeded() {
145 145
 		$memory_limit   = $this->get_memory_limit() * 0.8; // 80% of max memory
146
-		$current_memory = memory_get_usage( true );
146
+		$current_memory = memory_get_usage(true);
147 147
 		$return         = false;
148 148
 
149
-		if ( $current_memory >= $memory_limit ) {
149
+		if ($current_memory >= $memory_limit) {
150 150
 			$return = true;
151 151
 		}
152 152
 
153
-		return apply_filters( 'wp_queue_cron_memory_exceeded', $return );
153
+		return apply_filters('wp_queue_cron_memory_exceeded', $return);
154 154
 	}
155 155
 
156 156
 	/**
@@ -159,18 +159,18 @@  discard block
 block discarded – undo
159 159
 	 * @return int
160 160
 	 */
161 161
 	protected function get_memory_limit() {
162
-		if ( function_exists( 'ini_get' ) ) {
163
-			$memory_limit = ini_get( 'memory_limit' );
162
+		if (function_exists('ini_get')) {
163
+			$memory_limit = ini_get('memory_limit');
164 164
 		} else {
165 165
 			$memory_limit = '256M';
166 166
 		}
167 167
 
168
-		if ( ! $memory_limit || - 1 == $memory_limit ) {
168
+		if ( ! $memory_limit || - 1 == $memory_limit) {
169 169
 			// Unlimited, set to 1GB
170 170
 			$memory_limit = '1000M';
171 171
 		}
172 172
 
173
-		return intval( $memory_limit ) * 1024 * 1024;
173
+		return intval($memory_limit) * 1024 * 1024;
174 174
 	}
175 175
 
176 176
 	/**
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 * @return bool
183 183
 	 */
184 184
 	protected function time_exceeded() {
185
-		$finish = $this->start_time + apply_filters( 'wp_queue_cron_time_limit', 20 ); // 20 seconds
185
+		$finish = $this->start_time + apply_filters('wp_queue_cron_time_limit', 20); // 20 seconds
186 186
 		$return = false;
187 187
 
188
-		if ( time() >= $finish ) {
188
+		if (time() >= $finish) {
189 189
 			$return = true;
190 190
 		}
191 191
 
192
-		return apply_filters( 'wp_queue_cron_time_exceeded', $return );
192
+		return apply_filters('wp_queue_cron_time_exceeded', $return);
193 193
 	}
194 194
 }
195 195
\ No newline at end of file
Please login to merge, or discard this patch.