Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Activator
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 activate
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 prepare_cache
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * Fired during plugin activation
4 *
5 * @package brianhenryie/bh-wc-postcode-address-autofill
6 */
7
8namespace BrianHenryIE\WC_Postcode_Address_Autofill\WP_Includes;
9
10use BrianHenryIE\WC_Postcode_Address_Autofill\API_Interface;
11
12/**
13 * Fired during plugin activation.
14 *
15 * This class defines all code necessary to run during the plugin's activation.
16 */
17class Activator {
18
19    /**
20     * Load the postcode data for the store's country into cache.
21     */
22    public static function activate(): void {
23        if ( did_action( 'woocommerce_loaded' ) ) {
24            self::prepare_cache();
25        } else {
26            add_action( 'woocommerce_loaded', array( __CLASS__, 'prepare_cache' ) );
27        }
28    }
29
30    /**
31     * Load the postcode data for the store's base country into cache.
32     */
33    public static function prepare_cache(): void {
34
35        if ( ! isset( $GLOBALS['bh_wc_postcode_address_autofill'] )
36            || ! $GLOBALS['bh_wc_postcode_address_autofill'] instanceof API_Interface ) {
37            return;
38        }
39
40        $api = $GLOBALS['bh_wc_postcode_address_autofill'];
41
42        $store_country = wc_get_base_location()['country'];
43
44        $api->get_locations_for_postcode( $store_country, '' );
45    }
46}