Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
4 / 6
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Request
66.67% covered (warning)
66.67%
4 / 6
50.00% covered (danger)
50.00%
2 / 4
10.37
0.00% covered (danger)
0.00%
0 / 1
 get_local_base_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 get_production_base_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 get_base_url
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 get_endpoint
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_md5_hash
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3namespace NewfoldLabs\WP\Module\Data\WonderBlocks\Requests;
4
5/**
6 * Base class for WonderBlock Requests.
7 */
8abstract class Request {
9    /**
10     * The production base URL.
11     *
12     * @var string
13     */
14    protected static $production_base_url = 'https://patterns.hiive.cloud';
15
16    /**
17     * The local base URL.
18     *
19     * @var string
20     */
21    protected static $local_base_url = 'http://localhost:8888';
22
23    /**
24     * The endpoint to request.
25     *
26     * @var string
27     */
28    protected $endpoint;
29
30    /**
31     * Get the local base URL.
32     *
33     * @return string
34     */
35    protected static function get_local_base_url() {
36        return defined( 'NFD_WB_LOCAL_BASE_URL' ) ? NFD_WB_LOCAL_BASE_URL : self::$local_base_url;
37    }
38
39    /**
40     * Get the production base URL.
41     *
42     * @return string
43     */
44    protected static function get_production_base_url() {
45        return defined( 'NFD_WB_PRODUCTION_BASE_URL' ) ? NFD_WB_PRODUCTION_BASE_URL : self::$production_base_url;
46    }
47
48    /**
49     * Get the base URL
50     */
51    public function get_base_url(): string {
52        if ( defined( 'NFD_DATA_WB_DEV_MODE' ) && constant( 'NFD_DATA_WB_DEV_MODE' ) ) {
53            return self::get_local_base_url();
54        }
55
56        return self::get_production_base_url();
57    }
58
59    /**
60     * Get the request endpoint.
61     */
62    public function get_endpoint(): string {
63        return $this->endpoint;
64    }
65
66    /**
67     * This function should return a MD5 hashed string of the request parameters that can uniquely identify it.
68     */
69    abstract public function get_md5_hash(): string;
70}