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 WC_Webhook 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 WC_Webhook, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class WC_Webhook extends WC_Legacy_Webhook { |
||
22 | |||
23 | /** |
||
24 | * Stores webhook data. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $data = array( |
||
29 | 'date_created' => null, |
||
30 | 'date_modified' => null, |
||
31 | 'status' => 'disabled', |
||
32 | 'delivery_url' => '', |
||
33 | 'secret' => '', |
||
34 | 'name' => '', |
||
35 | 'topic' => '', |
||
36 | 'hooks' => '', |
||
37 | 'resource' => '', |
||
38 | 'event' => '', |
||
39 | 'failure_count' => 0, |
||
40 | 'user_id' => 0, |
||
41 | 'api_version' => 3, |
||
42 | 'pending_delivery' => false, |
||
43 | ); |
||
44 | |||
45 | /** |
||
46 | * Load webhook data based on how WC_Webhook is called. |
||
47 | * |
||
48 | * @param WC_Webhook|int $data Webhook ID or data. |
||
49 | * @throws Exception If webhook cannot be read/found and $data is set. |
||
50 | */ |
||
51 | 26 | public function __construct( $data = 0 ) { |
|
74 | |||
75 | /** |
||
76 | * Enqueue the hooks associated with the webhook. |
||
77 | * |
||
78 | * @since 2.2.0 |
||
79 | */ |
||
80 | 8 | public function enqueue() { |
|
90 | |||
91 | /** |
||
92 | * Process the webhook for delivery by verifying that it should be delivered. |
||
93 | * and scheduling the delivery (in the background by default, or immediately). |
||
94 | * |
||
95 | * @since 2.2.0 |
||
96 | * @param mixed $arg The first argument provided from the associated hooks. |
||
97 | * @return mixed $arg Returns the argument in case the webhook was hooked into a filter. |
||
98 | */ |
||
99 | public function process( $arg ) { |
||
100 | |||
101 | // Verify that webhook should be processed for delivery. |
||
102 | if ( ! $this->should_deliver( $arg ) ) { |
||
103 | return; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Process webhook delivery. |
||
108 | * |
||
109 | * @since 3.3.0 |
||
110 | * @hooked wc_webhook_process_delivery - 10 |
||
111 | */ |
||
112 | do_action( 'woocommerce_webhook_process_delivery', $this, $arg ); |
||
113 | |||
114 | return $arg; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Helper to check if the webhook should be delivered, as some hooks. |
||
119 | * (like `wp_trash_post`) will fire for every post type, not just ours. |
||
120 | * |
||
121 | * @since 2.2.0 |
||
122 | * @param mixed $arg First hook argument. |
||
123 | * @return bool True if webhook should be delivered, false otherwise. |
||
124 | */ |
||
125 | private function should_deliver( $arg ) { |
||
126 | $should_deliver = $this->is_active() && $this->is_valid_topic() && $this->is_valid_action( $arg ) && $this->is_valid_resource( $arg ); |
||
127 | |||
128 | /** |
||
129 | * Let other plugins intercept deliver for some messages queue like rabbit/zeromq. |
||
130 | * |
||
131 | * @param bool $should_deliver True if the webhook should be sent, or false to not send it. |
||
132 | * @param WC_Webhook $this The current webhook class. |
||
133 | * @param mixed $arg First hook argument. |
||
134 | */ |
||
135 | return apply_filters( 'woocommerce_webhook_should_deliver', $should_deliver, $this, $arg ); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Returns if webhook is active. |
||
140 | * |
||
141 | * @since 3.6.0 |
||
142 | * @return bool True if validation passes. |
||
143 | */ |
||
144 | private function is_active() { |
||
147 | |||
148 | /** |
||
149 | * Returns if topic is valid. |
||
150 | * |
||
151 | * @since 3.6.0 |
||
152 | * @return bool True if validation passes. |
||
153 | */ |
||
154 | private function is_valid_topic() { |
||
155 | return wc_is_webhook_valid_topic( $this->get_topic() ); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Validates the criteria for certain actions. |
||
160 | * |
||
161 | * @since 3.6.0 |
||
162 | * @param mixed $arg First hook argument. |
||
163 | * @return bool True if validation passes. |
||
164 | */ |
||
165 | private function is_valid_action( $arg ) { |
||
166 | $current_action = current_action(); |
||
167 | $return = true; |
||
168 | |||
169 | switch ( $current_action ) { |
||
170 | case 'delete_post': |
||
171 | case 'wp_trash_post': |
||
172 | case 'untrashed_post': |
||
173 | $return = $this->is_valid_post_action( $arg ); |
||
174 | break; |
||
175 | case 'delete_user': |
||
176 | $return = $this->is_valid_user_action( $arg ); |
||
177 | break; |
||
178 | } |
||
179 | |||
180 | if ( 0 === strpos( $current_action, 'woocommerce_process_shop' ) || 0 === strpos( $current_action, 'woocommerce_process_product' ) ) { |
||
181 | $return = $this->is_valid_processing_action( $arg ); |
||
182 | } |
||
183 | |||
184 | return $return; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Validates post actions. |
||
189 | * |
||
190 | * @since 3.6.0 |
||
191 | * @param mixed $arg First hook argument. |
||
192 | * @return bool True if validation passes. |
||
193 | */ |
||
194 | private function is_valid_post_action( $arg ) { |
||
195 | // Only deliver deleted/restored event for coupons, orders, and products. |
||
196 | if ( isset( $GLOBALS['post_type'] ) && ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ), true ) ) { |
||
197 | return false; |
||
198 | } |
||
199 | |||
200 | // Check if is delivering for the correct resource. |
||
201 | if ( isset( $GLOBALS['post_type'] ) && str_replace( 'shop_', '', $GLOBALS['post_type'] ) !== $this->get_resource() ) { |
||
202 | return false; |
||
203 | } |
||
204 | return true; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Validates user actions. |
||
209 | * |
||
210 | * @since 3.6.0 |
||
211 | * @param mixed $arg First hook argument. |
||
212 | * @return bool True if validation passes. |
||
213 | */ |
||
214 | private function is_valid_user_action( $arg ) { |
||
224 | |||
225 | /** |
||
226 | * Validates WC processing actions. |
||
227 | * |
||
228 | * @since 3.6.0 |
||
229 | * @param mixed $arg First hook argument. |
||
230 | * @return bool True if validation passes. |
||
231 | */ |
||
232 | private function is_valid_processing_action( $arg ) { |
||
251 | |||
252 | /** |
||
253 | * Checks the resource for this webhook is valid e.g. valid post status. |
||
254 | * |
||
255 | * @since 3.6.0 |
||
256 | * @param mixed $arg First hook argument. |
||
257 | * @return bool True if validation passes. |
||
258 | */ |
||
259 | private function is_valid_resource( $arg ) { |
||
282 | |||
283 | /** |
||
284 | * Deliver the webhook payload using wp_safe_remote_request(). |
||
285 | * |
||
286 | * @since 2.2.0 |
||
287 | * @param mixed $arg First hook argument. |
||
288 | */ |
||
289 | public function deliver( $arg ) { |
||
329 | |||
330 | /** |
||
331 | * Get Legacy API payload. |
||
332 | * |
||
333 | * @since 3.0.0 |
||
334 | * @param string $resource Resource type. |
||
335 | * @param int $resource_id Resource ID. |
||
336 | * @param string $event Event type. |
||
337 | * @return array |
||
338 | */ |
||
339 | private function get_legacy_api_payload( $resource, $resource_id, $event ) { |
||
340 | // Include & load API classes. |
||
341 | WC()->api->includes(); |
||
342 | WC()->api->register_resources( new WC_API_Server( '/' ) ); |
||
343 | |||
344 | switch ( $resource ) { |
||
345 | case 'coupon': |
||
346 | $payload = WC()->api->WC_API_Coupons->get_coupon( $resource_id ); |
||
347 | break; |
||
348 | |||
349 | case 'customer': |
||
350 | $payload = WC()->api->WC_API_Customers->get_customer( $resource_id ); |
||
351 | break; |
||
352 | |||
353 | case 'order': |
||
354 | $payload = WC()->api->WC_API_Orders->get_order( $resource_id, null, apply_filters( 'woocommerce_webhook_order_payload_filters', array() ) ); |
||
355 | break; |
||
356 | |||
357 | case 'product': |
||
358 | // Bulk and quick edit action hooks return a product object instead of an ID. |
||
359 | if ( 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) { |
||
360 | $resource_id = $resource_id->get_id(); |
||
|
|||
361 | } |
||
362 | $payload = WC()->api->WC_API_Products->get_product( $resource_id ); |
||
363 | break; |
||
364 | |||
365 | // Custom topics include the first hook argument. |
||
366 | case 'action': |
||
367 | $payload = array( |
||
368 | 'action' => current( $this->get_hooks() ), |
||
369 | 'arg' => $resource_id, |
||
370 | ); |
||
371 | break; |
||
372 | |||
373 | default: |
||
374 | $payload = array(); |
||
375 | break; |
||
376 | } |
||
377 | |||
378 | return $payload; |
||
379 | } |
||
380 | |||
381 | /** |
||
382 | * Get WP API integration payload. |
||
383 | * |
||
384 | * @since 3.0.0 |
||
385 | * @param string $resource Resource type. |
||
386 | * @param int $resource_id Resource ID. |
||
387 | * @param string $event Event type. |
||
388 | * @return array |
||
389 | */ |
||
390 | private function get_wp_api_payload( $resource, $resource_id, $event ) { |
||
391 | $rest_api_versions = wc_get_webhook_rest_api_versions(); |
||
392 | $version_suffix = end( $rest_api_versions ) !== $this->get_api_version() ? strtoupper( str_replace( 'wp_api', '', $this->get_api_version() ) ) : ''; |
||
393 | |||
394 | // Load REST API endpoints to generate payload. |
||
395 | if ( ! did_action( 'rest_api_init' ) ) { |
||
396 | WC()->api->rest_api_includes(); |
||
397 | } |
||
398 | |||
399 | switch ( $resource ) { |
||
400 | case 'coupon': |
||
401 | case 'customer': |
||
402 | case 'order': |
||
403 | case 'product': |
||
404 | $class = 'WC_REST_' . ucfirst( $resource ) . 's' . $version_suffix . '_Controller'; |
||
405 | $request = new WP_REST_Request( 'GET' ); |
||
406 | $controller = new $class(); |
||
407 | |||
408 | // Bulk and quick edit action hooks return a product object instead of an ID. |
||
409 | if ( 'product' === $resource && 'updated' === $event && is_a( $resource_id, 'WC_Product' ) ) { |
||
410 | $resource_id = $resource_id->get_id(); |
||
411 | } |
||
412 | |||
413 | $request->set_param( 'id', $resource_id ); |
||
414 | $result = $controller->get_item( $request ); |
||
415 | $payload = isset( $result->data ) ? $result->data : array(); |
||
416 | break; |
||
417 | |||
418 | // Custom topics include the first hook argument. |
||
419 | case 'action': |
||
420 | $payload = array( |
||
421 | 'action' => current( $this->get_hooks() ), |
||
422 | 'arg' => $resource_id, |
||
423 | ); |
||
424 | break; |
||
425 | |||
426 | default: |
||
427 | $payload = array(); |
||
428 | break; |
||
429 | } |
||
430 | |||
431 | return $payload; |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * Build the payload data for the webhook. |
||
436 | * |
||
437 | * @since 2.2.0 |
||
438 | * @param mixed $resource_id First hook argument, typically the resource ID. |
||
439 | * @return mixed Payload data. |
||
440 | */ |
||
441 | public function build_payload( $resource_id ) { |
||
469 | |||
470 | /** |
||
471 | * Generate a base64-encoded HMAC-SHA256 signature of the payload body so the. |
||
472 | * recipient can verify the authenticity of the webhook. Note that the signature. |
||
473 | * is calculated after the body has already been encoded (JSON by default). |
||
474 | * |
||
475 | * @since 2.2.0 |
||
476 | * @param string $payload Payload data to hash. |
||
477 | * @return string |
||
478 | */ |
||
479 | 1 | public function generate_signature( $payload ) { |
|
484 | |||
485 | /** |
||
486 | * Generate a new unique hash as a delivery id based on current time and wehbook id. |
||
487 | * Return the hash for inclusion in the webhook request. |
||
488 | * |
||
489 | * @since 2.2.0 |
||
490 | * @return string |
||
491 | */ |
||
492 | public function get_new_delivery_id() { |
||
496 | |||
497 | /** |
||
498 | * Log the delivery request/response. |
||
499 | * |
||
500 | * @since 2.2.0 |
||
501 | * @param string $delivery_id Previously created hash. |
||
502 | * @param array $request Request data. |
||
503 | * @param array|WP_Error $response Response data. |
||
504 | * @param float $duration Request duration. |
||
505 | */ |
||
506 | public function log_delivery( $delivery_id, $request, $response, $duration ) { |
||
568 | |||
569 | /** |
||
570 | * Track consecutive delivery failures and automatically disable the webhook. |
||
571 | * if more than 5 consecutive failures occur. A failure is defined as a. |
||
572 | * non-2xx response. |
||
573 | * |
||
574 | * @since 2.2.0 |
||
575 | */ |
||
576 | private function failed_delivery() { |
||
589 | |||
590 | /** |
||
591 | * Get the delivery logs for this webhook. |
||
592 | * |
||
593 | * @since 3.3.0 |
||
594 | * @return string |
||
595 | */ |
||
596 | public function get_delivery_logs() { |
||
599 | |||
600 | /** |
||
601 | * Get the delivery log specified by the ID. The delivery log includes: |
||
602 | * |
||
603 | * + duration |
||
604 | * + summary |
||
605 | * + request method/url |
||
606 | * + request headers/body |
||
607 | * + response code/message/headers/body |
||
608 | * |
||
609 | * @since 2.2 |
||
610 | * @deprecated 3.3.0 |
||
611 | * @param int $delivery_id Delivery ID. |
||
612 | * @return void |
||
613 | */ |
||
614 | public function get_delivery_log( $delivery_id ) { |
||
617 | |||
618 | /** |
||
619 | * Send a test ping to the delivery URL, sent when the webhook is first created. |
||
620 | * |
||
621 | * @since 2.2.0 |
||
622 | * @return bool|WP_Error |
||
623 | */ |
||
624 | public function deliver_ping() { |
||
648 | |||
649 | /* |
||
650 | |-------------------------------------------------------------------------- |
||
651 | | Getters |
||
652 | |-------------------------------------------------------------------------- |
||
653 | */ |
||
654 | |||
655 | /** |
||
656 | * Get the friendly name for the webhook. |
||
657 | * |
||
658 | * @since 2.2.0 |
||
659 | * @param string $context What the value is for. |
||
660 | * Valid values are 'view' and 'edit'. |
||
661 | * @return string |
||
662 | */ |
||
663 | 10 | public function get_name( $context = 'view' ) { |
|
666 | |||
667 | /** |
||
668 | * Get the webhook status. |
||
669 | * |
||
670 | * - 'active' - delivers payload. |
||
671 | * - 'paused' - does not deliver payload, paused by admin. |
||
672 | * - 'disabled' - does not delivery payload, paused automatically due to consecutive failures. |
||
673 | * |
||
674 | * @since 2.2.0 |
||
675 | * @param string $context What the value is for. |
||
676 | * Valid values are 'view' and 'edit'. |
||
677 | * @return string status |
||
678 | */ |
||
679 | 11 | public function get_status( $context = 'view' ) { |
|
682 | |||
683 | /** |
||
684 | * Get webhopk created date. |
||
685 | * |
||
686 | * @since 3.2.0 |
||
687 | * @param string $context What the value is for. |
||
688 | * Valid values are 'view' and 'edit'. |
||
689 | * @return WC_DateTime|null Object if the date is set or null if there is no date. |
||
690 | */ |
||
691 | 1 | public function get_date_created( $context = 'view' ) { |
|
694 | |||
695 | /** |
||
696 | * Get webhopk modified date. |
||
697 | * |
||
698 | * @since 3.2.0 |
||
699 | * @param string $context What the value is for. |
||
700 | * Valid values are 'view' and 'edit'. |
||
701 | * @return WC_DateTime|null Object if the date is set or null if there is no date. |
||
702 | */ |
||
703 | 1 | public function get_date_modified( $context = 'view' ) { |
|
706 | |||
707 | /** |
||
708 | * Get the secret used for generating the HMAC-SHA256 signature. |
||
709 | * |
||
710 | * @since 2.2.0 |
||
711 | * @param string $context What the value is for. |
||
712 | * Valid values are 'view' and 'edit'. |
||
713 | * @return string |
||
714 | */ |
||
715 | 11 | public function get_secret( $context = 'view' ) { |
|
718 | |||
719 | /** |
||
720 | * Get the webhook topic, e.g. `order.created`. |
||
721 | * |
||
722 | * @since 2.2.0 |
||
723 | * @param string $context What the value is for. |
||
724 | * Valid values are 'view' and 'edit'. |
||
725 | * @return string |
||
726 | */ |
||
727 | 13 | public function get_topic( $context = 'view' ) { |
|
730 | |||
731 | /** |
||
732 | * Get the delivery URL. |
||
733 | * |
||
734 | * @since 2.2.0 |
||
735 | * @param string $context What the value is for. |
||
736 | * Valid values are 'view' and 'edit'. |
||
737 | * @return string |
||
738 | */ |
||
739 | 10 | public function get_delivery_url( $context = 'view' ) { |
|
742 | |||
743 | /** |
||
744 | * Get the user ID for this webhook. |
||
745 | * |
||
746 | * @since 2.2.0 |
||
747 | * @param string $context What the value is for. |
||
748 | * Valid values are 'view' and 'edit'. |
||
749 | * @return int |
||
750 | */ |
||
751 | 10 | public function get_user_id( $context = 'view' ) { |
|
754 | |||
755 | /** |
||
756 | * API version. |
||
757 | * |
||
758 | * @since 3.0.0 |
||
759 | * @param string $context What the value is for. |
||
760 | * Valid values are 'view' and 'edit'. |
||
761 | * @return string |
||
762 | */ |
||
763 | 10 | public function get_api_version( $context = 'view' ) { |
|
764 | 10 | $version = $this->get_prop( 'api_version', $context ); |
|
765 | |||
766 | 10 | return 0 < $version ? 'wp_api_v' . $version : 'legacy_v3'; |
|
767 | } |
||
768 | |||
769 | /** |
||
770 | * Get the failure count. |
||
771 | * |
||
772 | * @since 2.2.0 |
||
773 | * @param string $context What the value is for. |
||
774 | * Valid values are 'view' and 'edit'. |
||
775 | * @return int |
||
776 | */ |
||
777 | 10 | public function get_failure_count( $context = 'view' ) { |
|
780 | |||
781 | /** |
||
782 | * Get pending delivery. |
||
783 | * |
||
784 | * @since 3.2.0 |
||
785 | * @param string $context What the value is for. |
||
786 | * Valid values are 'view' and 'edit'. |
||
787 | * @return bool |
||
788 | */ |
||
789 | 10 | public function get_pending_delivery( $context = 'view' ) { |
|
792 | |||
793 | /* |
||
794 | |-------------------------------------------------------------------------- |
||
795 | | Setters |
||
796 | |-------------------------------------------------------------------------- |
||
797 | */ |
||
798 | |||
799 | /** |
||
800 | * Set webhook name. |
||
801 | * |
||
802 | * @since 3.2.0 |
||
803 | * @param string $name Webhook name. |
||
804 | */ |
||
805 | 9 | public function set_name( $name ) { |
|
808 | |||
809 | /** |
||
810 | * Set webhook created date. |
||
811 | * |
||
812 | * @since 3.2.0 |
||
813 | * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. |
||
814 | * If the DateTime string has no timezone or offset, |
||
815 | * WordPress site timezone will be assumed. |
||
816 | * Null if their is no date. |
||
817 | */ |
||
818 | 10 | public function set_date_created( $date = null ) { |
|
821 | |||
822 | /** |
||
823 | * Set webhook modified date. |
||
824 | * |
||
825 | * @since 3.2.0 |
||
826 | * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. |
||
827 | * If the DateTime string has no timezone or offset, |
||
828 | * WordPress site timezone will be assumed. |
||
829 | * Null if their is no date. |
||
830 | */ |
||
831 | 1 | public function set_date_modified( $date = null ) { |
|
834 | |||
835 | /** |
||
836 | * Set status. |
||
837 | * |
||
838 | * @since 3.2.0 |
||
839 | * @param string $status Status. |
||
840 | */ |
||
841 | 10 | public function set_status( $status ) { |
|
848 | |||
849 | /** |
||
850 | * Set the secret used for generating the HMAC-SHA256 signature. |
||
851 | * |
||
852 | * @since 2.2.0 |
||
853 | * @param string $secret Secret. |
||
854 | */ |
||
855 | 9 | public function set_secret( $secret ) { |
|
858 | |||
859 | /** |
||
860 | * Set the webhook topic and associated hooks. |
||
861 | * The topic resource & event are also saved separately. |
||
862 | * |
||
863 | * @since 2.2.0 |
||
864 | * @param string $topic Webhook topic. |
||
865 | */ |
||
866 | 12 | public function set_topic( $topic ) { |
|
875 | |||
876 | /** |
||
877 | * Set the delivery URL. |
||
878 | * |
||
879 | * @since 2.2.0 |
||
880 | * @param string $url Delivery URL. |
||
881 | */ |
||
882 | 9 | public function set_delivery_url( $url ) { |
|
885 | |||
886 | /** |
||
887 | * Set user ID. |
||
888 | * |
||
889 | * @since 3.2.0 |
||
890 | * @param int $user_id User ID. |
||
891 | */ |
||
892 | 9 | public function set_user_id( $user_id ) { |
|
895 | |||
896 | /** |
||
897 | * Set API version. |
||
898 | * |
||
899 | * @since 3.0.0 |
||
900 | * @param int|string $version REST API version. |
||
901 | */ |
||
902 | 9 | public function set_api_version( $version ) { |
|
903 | 9 | if ( ! is_numeric( $version ) ) { |
|
904 | 1 | $version = $this->data_store->get_api_version_number( $version ); |
|
905 | } |
||
906 | |||
907 | 9 | $this->set_prop( 'api_version', (int) $version ); |
|
908 | } |
||
909 | |||
910 | /** |
||
911 | * Set pending delivery. |
||
912 | * |
||
913 | * @since 3.2.0 |
||
914 | * @param bool $pending_delivery Set true if is pending for delivery. |
||
915 | */ |
||
916 | 10 | public function set_pending_delivery( $pending_delivery ) { |
|
919 | |||
920 | /** |
||
921 | * Set failure count. |
||
922 | * |
||
923 | * @since 3.2.0 |
||
924 | * @param bool $failure_count Total of failures. |
||
925 | */ |
||
926 | 9 | public function set_failure_count( $failure_count ) { |
|
929 | |||
930 | /* |
||
931 | |-------------------------------------------------------------------------- |
||
932 | | Non-CRUD Getters |
||
933 | |-------------------------------------------------------------------------- |
||
934 | */ |
||
935 | |||
936 | /** |
||
937 | * Get the associated hook names for a topic. |
||
938 | * |
||
939 | * @since 2.2.0 |
||
940 | * @param string $topic Topic name. |
||
941 | * @return array |
||
942 | */ |
||
943 | 1 | private function get_topic_hooks( $topic ) { |
|
1006 | |||
1007 | /** |
||
1008 | * Get the hook names for the webhook. |
||
1009 | * |
||
1010 | * @since 2.2.0 |
||
1011 | * @return array |
||
1012 | */ |
||
1013 | 9 | public function get_hooks() { |
|
1022 | |||
1023 | /** |
||
1024 | * Get the resource for the webhook, e.g. `order`. |
||
1025 | * |
||
1026 | * @since 2.2.0 |
||
1027 | * @return string |
||
1028 | */ |
||
1029 | 10 | public function get_resource() { |
|
1034 | |||
1035 | /** |
||
1036 | * Get the event for the webhook, e.g. `created`. |
||
1037 | * |
||
1038 | * @since 2.2.0 |
||
1039 | * @return string |
||
1040 | */ |
||
1041 | 9 | public function get_event() { |
|
1046 | |||
1047 | /** |
||
1048 | * Get the webhook i18n status. |
||
1049 | * |
||
1050 | * @return string |
||
1051 | */ |
||
1052 | 1 | public function get_i18n_status() { |
|
1058 | } |
||
1059 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.