@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | use PinkCrab\Queue\Queue_Driver\Action_Scheduler\Action_Scheduler_Driver; |
9 | 9 | |
10 | 10 | $r = Action_Scheduler_Driver::get_instance(); |
11 | -Queue_Bootstrap::init( $r ); |
|
11 | +Queue_Bootstrap::init($r); |
|
12 | 12 | |
13 | 13 | |
14 | -$app = ( new App_Factory( __DIR__ ) )->with_wp_dice( true ) |
|
15 | - ->di_rules( array() ) |
|
16 | - ->registration_classes( array() ) |
|
17 | - ->construct_registration_middleware( Queue_Middleware::class ) |
|
14 | +$app = (new App_Factory(__DIR__))->with_wp_dice(true) |
|
15 | + ->di_rules(array()) |
|
16 | + ->registration_classes(array()) |
|
17 | + ->construct_registration_middleware(Queue_Middleware::class) |
|
18 | 18 | ->boot(); |
19 | 19 | |
20 | 20 | // add_action('init', function() use( $app ) { |
@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | // Debug helpers, remove this in production. |
26 | 26 | add_filter( |
27 | 27 | 'wp_php_error_args', |
28 | - function( $message, $error ) { |
|
28 | + function($message, $error) { |
|
29 | 29 | echo "<strong>Error type</strong> : {$error['type']}<hr>"; |
30 | 30 | echo "<strong>Message </strong> : <pre style='color: #333; font-face:monospace; font-size:8pt;'>{$error['message']}</pre><hr>"; |
31 | 31 | echo "<strong>File </strong> : {$error['file']}<hr>"; |
32 | 32 | echo "<strong>Line </strong> : {$error['line']}<hr>"; |
33 | - dd( $error, $message ); |
|
33 | + dd($error, $message); |
|
34 | 34 | }, |
35 | 35 | 2, |
36 | 36 | 10 |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | final public function __invoke(): void { |
54 | 54 | $args = func_get_args(); |
55 | - $this->handle( $args ); |
|
55 | + $this->handle($args); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param \PinkCrab\Loader\Hook_Loader $loader |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - final public function register( Hook_Loader $loader ): void { |
|
65 | - $loader->action( $this->hook, $this ); |
|
64 | + final public function register(Hook_Loader $loader): void { |
|
65 | + $loader->action($this->hook, $this); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -71,6 +71,6 @@ discard block |
||
71 | 71 | * @param mixed[] $args |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - abstract protected function handle( array $args): void; |
|
74 | + abstract protected function handle(array $args): void; |
|
75 | 75 | |
76 | 76 | } |
@@ -30,5 +30,5 @@ |
||
30 | 30 | interface Listener { |
31 | 31 | public function __invoke(): void; |
32 | 32 | public function get_hook(): string; |
33 | - public function register( Hook_Loader $loader ): void; |
|
33 | + public function register(Hook_Loader $loader): void; |
|
34 | 34 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param \PinkCrab\Loader\Hook_Loader $loader |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function set_hook_loader( Hook_Loader $loader ) { |
|
48 | + public function set_hook_loader(Hook_Loader $loader) { |
|
49 | 49 | $this->loader = $loader; |
50 | 50 | } |
51 | 51 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param \PinkCrab\Perique\Interfaces\DI_Container $container |
56 | 56 | * @return void |
57 | 57 | */ |
58 | - public function set_di_container( DI_Container $container ): void { |
|
58 | + public function set_di_container(DI_Container $container): void { |
|
59 | 59 | $this->container = $container; |
60 | 60 | } |
61 | 61 | |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | * @param object|Listener $class |
66 | 66 | * @return object |
67 | 67 | */ |
68 | - public function process( $class ) { |
|
69 | - if ( $class instanceof Listener ) { |
|
70 | - $class->register( $this->loader ); |
|
68 | + public function process($class) { |
|
69 | + if ($class instanceof Listener) { |
|
70 | + $class->register($this->loader); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | return $class; |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | * @param Queue $queue_driver The Queue Driver. |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public static function init( Queue $queue_driver ): void { |
|
39 | + public static function init(Queue $queue_driver): void { |
|
40 | 40 | $queue_driver->setup(); |
41 | 41 | |
42 | 42 | // initialize the queue driver |
43 | 43 | add_action( |
44 | 44 | 'init', |
45 | - function() use ( $queue_driver ) { |
|
45 | + function() use ($queue_driver) { |
|
46 | 46 | $queue_driver->init(); |
47 | 47 | }, |
48 | 48 | -1 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | add_filter( |
52 | 52 | Hooks::APP_INIT_SET_DI_RULES, |
53 | - function( $rules ) use ( $queue_driver ) { |
|
53 | + function($rules) use ($queue_driver) { |
|
54 | 54 | |
55 | 55 | $rules['*'] = array( |
56 | 56 | 'substitutions' => array( |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | add_action( |
67 | 67 | HOOKS::APP_INIT_POST_REGISTRATION, |
68 | - function() use ( $queue_driver ) { |
|
68 | + function() use ($queue_driver) { |
|
69 | 69 | $queue_driver->teardown(); |
70 | 70 | } |
71 | 71 | ); |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | * @param Event $event |
58 | 58 | * @return int|null |
59 | 59 | */ |
60 | - public function dispatch( Event $event) : ?int; |
|
60 | + public function dispatch(Event $event) : ?int; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Cancel next occurrence of Event |
64 | 64 | * |
65 | 65 | * @param Event $event |
66 | 66 | */ |
67 | - public function cancel_next( Event $event): void; |
|
67 | + public function cancel_next(Event $event): void; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Cancel all occurrences of Event |
71 | 71 | * |
72 | 72 | * @param Event $event |
73 | 73 | */ |
74 | - public function cancel_all( Event $event): void; |
|
74 | + public function cancel_all(Event $event): void; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Get next occurrence of Event |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param Event $event |
80 | 80 | * @return DateTimeImmutable|null |
81 | 81 | */ |
82 | - public function find_next( Event $event): ?DateTimeImmutable; |
|
82 | + public function find_next(Event $event): ?DateTimeImmutable; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Get all occurrences of Event |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param Event $event |
88 | 88 | * @return DateTimeImmutable[] |
89 | 89 | */ |
90 | - public function find_all( Event $event): array; |
|
90 | + public function find_all(Event $event): array; |
|
91 | 91 | |
92 | 92 | |
93 | 93 | /** |
@@ -96,6 +96,6 @@ discard block |
||
96 | 96 | * @param Event $event |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - public function is_scheduled( Event $event): bool; |
|
99 | + public function is_scheduled(Event $event): bool; |
|
100 | 100 | |
101 | 101 | } |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @param bool $next_only |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - public function cancel( Event $event, bool $next_only = false ): void { |
|
42 | - if ( $next_only ) { |
|
41 | + public function cancel(Event $event, bool $next_only = false): void { |
|
42 | + if ($next_only) { |
|
43 | 43 | \as_unschedule_action( |
44 | 44 | $event->get_hook(), |
45 | 45 | $event->get_data() ?? array(), |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | * @param Event $event |
62 | 62 | * @return DateTimeImmutable|null |
63 | 63 | */ |
64 | - public function find_next( Event $event ): ?DateTimeImmutable { |
|
64 | + public function find_next(Event $event): ?DateTimeImmutable { |
|
65 | 65 | $next = as_next_scheduled_action( |
66 | 66 | $event->get_hook(), |
67 | 67 | $event->get_data() ?? array(), |
68 | 68 | $event->get_group() |
69 | 69 | ); |
70 | 70 | |
71 | - return is_int( $next ) |
|
72 | - ? ( DateTimeImmutable::createFromFormat( 'U', \strval( $next ), wp_timezone() ) ?: null ) //phpcs:ignore |
|
71 | + return is_int($next) |
|
72 | + ? (DateTimeImmutable::createFromFormat('U', \strval($next), wp_timezone()) ?: null) //phpcs:ignore |
|
73 | 73 | : null; |
74 | 74 | } |
75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param Event $event |
80 | 80 | * @return array<int, DateTimeImmutable> |
81 | 81 | */ |
82 | - public function find_all( Event $event ): array { |
|
82 | + public function find_all(Event $event): array { |
|
83 | 83 | $events = as_get_scheduled_actions( |
84 | 84 | array( |
85 | 85 | 'hook' => $event->get_hook(), |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | 'status' => \ActionScheduler_Store::STATUS_PENDING, |
89 | 89 | 'orderby' => 'date', |
90 | 90 | 'per_page' => -1, |
91 | - 'date' => DateTimeImmutable::createFromFormat( 'U', 'now', wp_timezone() ), |
|
91 | + 'date' => DateTimeImmutable::createFromFormat('U', 'now', wp_timezone()), |
|
92 | 92 | 'date_compare' => '>', |
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | |
96 | 96 | return array_reduce( |
97 | 97 | $events, |
98 | - function ( array $carry, \ActionScheduler_Action $event ): array { |
|
98 | + function(array $carry, \ActionScheduler_Action $event): array { |
|
99 | 99 | /** @var ActionScheduler_SimpleSchedule */ |
100 | 100 | $schedule = $event->get_schedule(); |
101 | 101 | |
102 | 102 | // Get the date from schedule, if valid add to array. |
103 | 103 | $date = $schedule->get_date(); |
104 | - if ( $date instanceof \DateTime ) { |
|
105 | - $carry[] = DateTimeImmutable::createFromMutable( $date ); |
|
104 | + if ($date instanceof \DateTime) { |
|
105 | + $carry[] = DateTimeImmutable::createFromMutable($date); |
|
106 | 106 | } |
107 | 107 | return $carry; |
108 | 108 | }, |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @param \PinkCrab\Queue\Event\Event $event |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public function exists( Event $event ): bool { |
|
119 | + public function exists(Event $event): bool { |
|
120 | 120 | return as_has_scheduled_action( |
121 | 121 | $event->get_hook(), |
122 | 122 | $event->get_data() ?? array(), |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | * @param Event $event |
40 | 40 | * @return int|null Returns the event id. |
41 | 41 | */ |
42 | - public function dispatch( Event $event ): ?int { |
|
42 | + public function dispatch(Event $event): ?int { |
|
43 | 43 | // @phpstan-ignore-next-line |
44 | - $queue_id = \call_user_func( array( $this, $this->get_dispatch_type( $event ) ), $event ); |
|
45 | - return \is_int( $queue_id ) ? $queue_id : null; |
|
44 | + $queue_id = \call_user_func(array($this, $this->get_dispatch_type($event)), $event); |
|
45 | + return \is_int($queue_id) ? $queue_id : null; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -51,33 +51,33 @@ discard block |
||
51 | 51 | * @param Event $event |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - private function get_dispatch_type( Event $event ): string { |
|
54 | + private function get_dispatch_type(Event $event): string { |
|
55 | 55 | // If the event is async or there is no delay or interval. |
56 | - if ( $event instanceof Async_Event |
|
57 | - || ( is_null( $event->delayed_until() ) && is_null( $event->interval() ) ) |
|
56 | + if ($event instanceof Async_Event |
|
57 | + || (is_null($event->delayed_until()) && is_null($event->interval())) |
|
58 | 58 | ) { |
59 | 59 | // Return async. |
60 | 60 | return 'dispatch_async'; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // If the event is delayed or has no interval. |
64 | - if ( $event instanceof Delayed_Event |
|
65 | - || ( $event->delayed_until() instanceof DateTimeImmutable && is_null( $event->interval() ) ) |
|
64 | + if ($event instanceof Delayed_Event |
|
65 | + || ($event->delayed_until() instanceof DateTimeImmutable && is_null($event->interval())) |
|
66 | 66 | ) { |
67 | 67 | // Return delayed. |
68 | 68 | return 'dispatch_at'; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // If the event is a recurring event and has an interval. |
72 | - if ( $event instanceof Recurring_Event |
|
73 | - || ( is_int( $event->interval() ) && $event->interval() > 0 ) |
|
72 | + if ($event instanceof Recurring_Event |
|
73 | + || (is_int($event->interval()) && $event->interval() > 0) |
|
74 | 74 | ) { |
75 | 75 | // Return recurring. |
76 | 76 | return 'dispatch_recurring'; |
77 | 77 | } |
78 | 78 | |
79 | 79 | // If we get to the end and none has passed, throw exception. |
80 | - throw new \Exception( 'Unable to determine dispatch type.' ); |
|
80 | + throw new \Exception('Unable to determine dispatch type.'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param Event $event |
87 | 87 | * @return int Returns the event id. |
88 | 88 | */ |
89 | - private function dispatch_async( Event $event ): int { |
|
89 | + private function dispatch_async(Event $event): int { |
|
90 | 90 | return \as_enqueue_async_action( |
91 | 91 | $event->get_hook(), |
92 | 92 | $event->get_data() ?? array(), |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @param Event $event |
102 | 102 | * @return int Returns the event id. |
103 | 103 | */ |
104 | - private function dispatch_at( Event $event ): int { |
|
105 | - if ( ! $event->delayed_until() instanceof DateTimeImmutable ) { |
|
106 | - throw new \InvalidArgumentException( 'Event must have a delayed_until date/time.' ); |
|
104 | + private function dispatch_at(Event $event): int { |
|
105 | + if ( ! $event->delayed_until() instanceof DateTimeImmutable) { |
|
106 | + throw new \InvalidArgumentException('Event must have a delayed_until date/time.'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** @var DateTimeImmutable */ |
110 | 110 | $delayed_until = $event->delayed_until(); |
111 | 111 | |
112 | 112 | return as_schedule_single_action( |
113 | - (int) $delayed_until->setTimezone( wp_timezone() )->format( 'U' ), |
|
113 | + (int) $delayed_until->setTimezone(wp_timezone())->format('U'), |
|
114 | 114 | $event->get_hook(), |
115 | 115 | $event->get_data() ?? array(), |
116 | 116 | $event->get_group(), |
@@ -124,18 +124,18 @@ discard block |
||
124 | 124 | * @param Event $event |
125 | 125 | * @return int Returns the event id. |
126 | 126 | */ |
127 | - private function dispatch_recurring( Event $event ): int { |
|
128 | - if ( $event->interval() === null ) { |
|
129 | - throw new \InvalidArgumentException( 'Event must have an for it to be recurring.' ); |
|
127 | + private function dispatch_recurring(Event $event): int { |
|
128 | + if ($event->interval() === null) { |
|
129 | + throw new \InvalidArgumentException('Event must have an for it to be recurring.'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** @var DateTimeImmutable */ |
133 | 133 | $delayed_until = $event->delayed_until() instanceof DateTimeImmutable |
134 | - ? $event->delayed_until()->setTimezone( wp_timezone() ) |
|
135 | - : DateTimeImmutable::createFromFormat( 'U', '0', wp_timezone() ); |
|
134 | + ? $event->delayed_until()->setTimezone(wp_timezone()) |
|
135 | + : DateTimeImmutable::createFromFormat('U', '0', wp_timezone()); |
|
136 | 136 | |
137 | 137 | return as_schedule_recurring_action( |
138 | - (int) $delayed_until->format( 'U' ), |
|
138 | + (int) $delayed_until->format('U'), |
|
139 | 139 | $event->interval(), |
140 | 140 | $event->get_hook(), |
141 | 141 | $event->get_data() ?? array(), |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** @var bool */ |
47 | 47 | private static $included = false; |
48 | 48 | |
49 | - public function __construct( Action_Scheduler_Dispatcher $dispatcher, Action_Scheduler_Queue_Manager $queue_manager ) { |
|
49 | + public function __construct(Action_Scheduler_Dispatcher $dispatcher, Action_Scheduler_Queue_Manager $queue_manager) { |
|
50 | 50 | $this->dispatcher = $dispatcher; |
51 | 51 | $this->queue_manager = $queue_manager; |
52 | 52 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function setup(): void { |
74 | 74 | |
75 | 75 | // If the lib has already been included, bail. |
76 | - if ( self::$included ) { |
|
76 | + if (self::$included) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $path = join( |
82 | 82 | \DIRECTORY_SEPARATOR, |
83 | 83 | array( |
84 | - dirname( __FILE__, 4 ), |
|
84 | + dirname(__FILE__, 4), |
|
85 | 85 | 'lib', |
86 | 86 | 'action-scheduler', |
87 | 87 | 'action-scheduler.php', |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | ); |
90 | 90 | |
91 | 91 | // Filter the path to the action-scheduler path. |
92 | - $path = apply_filters( 'pinkcrab_queue_action_scheduler_path', $path ); |
|
92 | + $path = apply_filters('pinkcrab_queue_action_scheduler_path', $path); |
|
93 | 93 | |
94 | 94 | // Check if the file exists. |
95 | - if ( ! file_exists( $path ) ) { |
|
96 | - throw new \RuntimeException( 'Action Scheduler is not installed.' ); |
|
95 | + if ( ! file_exists($path)) { |
|
96 | + throw new \RuntimeException('Action Scheduler is not installed.'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Include the Action Scheduler plugin. |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @param Event $event |
130 | 130 | */ |
131 | - public function dispatch( Event $event ): ?int { |
|
132 | - $result = $this->dispatcher->dispatch( $event ); |
|
133 | - return \is_int( $result ) ? $result : null; |
|
131 | + public function dispatch(Event $event): ?int { |
|
132 | + $result = $this->dispatcher->dispatch($event); |
|
133 | + return \is_int($result) ? $result : null; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param Event $event |
140 | 140 | */ |
141 | - public function cancel_next( Event $event ): void { |
|
142 | - $this->queue_manager->cancel( $event, true ); |
|
141 | + public function cancel_next(Event $event): void { |
|
142 | + $this->queue_manager->cancel($event, true); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @param Event $event |
149 | 149 | */ |
150 | - public function cancel_all( Event $event ): void { |
|
151 | - $this->queue_manager->cancel( $event, false ); |
|
150 | + public function cancel_all(Event $event): void { |
|
151 | + $this->queue_manager->cancel($event, false); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @param Event $event |
158 | 158 | * @return DateTimeImmutable|null |
159 | 159 | */ |
160 | - public function find_next( Event $event ): ?DateTimeImmutable { |
|
161 | - return $this->queue_manager->find_next( $event ); |
|
160 | + public function find_next(Event $event): ?DateTimeImmutable { |
|
161 | + return $this->queue_manager->find_next($event); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @param Event $event |
168 | 168 | * @return DateTimeImmutable[] |
169 | 169 | */ |
170 | - public function find_all( Event $event ): array { |
|
171 | - return $this->queue_manager->find_all( $event ); |
|
170 | + public function find_all(Event $event): array { |
|
171 | + return $this->queue_manager->find_all($event); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param Event $event |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - public function is_scheduled( Event $event ): bool { |
|
182 | - return $this->queue_manager->exists( $event ); |
|
181 | + public function is_scheduled(Event $event): bool { |
|
182 | + return $this->queue_manager->exists($event); |
|
183 | 183 | } |
184 | 184 | } |