Passed
Push — add/image-automation ( ddc6bf...57094b )
by Warwick
03:19
created

Cron::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
<?php
2
/**
3
 * The main plugin class.
4
 *
5
 * @package   LSX_WETU_Importer
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright 2016 LightSpeed
10
 */
11
12
namespace lsx\wetu_importer\classes;
13
14
/**
15
 * The Main plugin class.
16
 */
17
class Cron {
18
19
	/**
20
	 * Holds class instance
21
	 *
22
	 * @since 1.0.0
23
	 *
24
	 * @var      object|Module_Template
0 ignored issues
show
Bug introduced by
The type lsx\wetu_importer\classes\Module_Template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
	 */
26
	protected static $instance = null;
27
28
	/**
29
	 * Initialize the plugin by setting localization, filters, and administration functions.
30
	 *
31
	 * @since 1.0.0
32
	 *
33
	 * @access private
34
	 */
35
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
36
		add_action( 'lsx_wetu_importer_settings_before', array( $this, 'watch_for_trigger' ), 200 );
37
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
	/**
40
	 * Return an instance of this class.
41
	 *
42
	 * @since 1.0.0
43
	 *
44
	 * @return    object Cron()    A single instance of this class.
45
	 */
46
	public static function get_instance() {
47
		// If the single instance hasn't been set, set it now.
48
		if ( null === self::$instance ) {
0 ignored issues
show
introduced by
The condition null === self::instance is always false.
Loading history...
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
49
			self::$instance = new self();
50
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
51
		return self::$instance;
52
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
53
54
	/**
55
	 * Watches for changes in the button triggers.
56
	 *
57
	 * @return void
58
	 */
59
	public function watch_for_trigger() {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
60
61
		if ( isset( $_GET['page'] ) && 'lsx-wetu-importer' === $_GET['page'] && isset( $_GET['tab'] ) && 'settings' === $_GET['tab'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Processing form data without nonce verification.
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
62
			$options = lsx_wetu_get_options();
63
64
			// Check what state the option is in.
65
			$accommodation_cron = 'deactivate';
66
			if ( isset( $options['accommodation_images_cron'] ) && '' !== $options['accommodation_images_cron'] ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
67
				$accommodation_cron = 'activate';
68
			}
69
70
			// Check what state the cron is in.
71
			$schedule = false;
72
			if ( wp_next_scheduled( 'lsx_wetu_accommodation_images_cron' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
73
				$schedule = true;
74
			}
75
76
			// If activate and its not running.
77
			if ( false === $schedule && 'activate' === $accommodation_cron ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
78
				$this->schedule();
79
			} elseif ( true === $schedule && 'deactivate' === $accommodation_cron ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
80
				$this->deactivate();
81
			}
82
		}
83
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
84
85
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$task" missing
Loading history...
86
	 * Remove our cron from the shedule.
87
	 *
88
	 * @return void
89
	 */
90
	public function deactivate( $task = 'lsx_wetu_accommodation_images_cron' ) {
91
		wp_clear_scheduled_hook( $task );
92
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
93
94
	/**
95
	 * This function will schedule the cron event.
96
	 *
97
	 * @param string $task
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
98
	 * @return void
99
	 */
100
	public function schedule( $task = 'lsx_wetu_accommodation_images_cron' ) {
101
		add_action( $task, array( $this, 'process' ) );
102
		add_action( $task, 'lsx_wetu_accommodation_images_callback' );
103
		add_action( 'lsx_wetu_accommodation_images_cron', 'lsx_wetu_accommodation_images_callback' );
104
		wp_schedule_event( time(), 'daily', 'lsx_wetu_accommodation_images_cron' );
105
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
106
107
	/**
108
	 * This is the function that will be triggered by the cron event.
109
	 *
110
	 * @return void
111
	 */
112
	public function process() {
113
		// do your stuff.
114
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
115
}
116
Cron::get_instance();
117
118
function lsx_wetu_accommodation_images_callback() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_wetu_accommodation_images_callback()
Loading history...
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
119
120
}
121