Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
68.18% covered (warning)
68.18%
15 / 22
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Environment
68.18% covered (warning)
68.18%
15 / 22
0.00% covered (danger)
0.00%
0 / 7
32.89
0.00% covered (danger)
0.00%
0 / 1
 getApiUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 getBackendUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 getJsSdkUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 getAmpPlayerUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 getAmpImgUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 getDashboardUrl
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
3.33
 hasAutoSyncSettings
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
1<?php
2
3declare(strict_types=1);
4
5/**
6 * BeyondWords Environment.
7 *
8 * @package Beyondwords\Wordpress
9 * @author  Stuart McAlpine <stu@beyondwords.io>
10 * @since   3.0.0
11 */
12
13namespace Beyondwords\Wordpress\Core;
14
15/**
16 * Environment
17 *
18 * @since 3.0.0
19 */
20class Environment
21{
22    /**
23     * The BeyondWords API URL.
24     *
25     * Override with BEYONDWORDS_API_URL in wp-config.php.
26     *
27     * @since  3.0.0
28     * @var    string
29     */
30    public const BEYONDWORDS_API_URL = 'https://api.beyondwords.io/v1';
31
32    /**
33     * The BeyondWords Backend URL.
34     *
35     * Override with BEYONDWORDS_BACKEND_URL in wp-config.php.
36     *
37     * @since  3.0.0
38     * @var    string
39     */
40    public const BEYONDWORDS_BACKEND_URL = '';
41
42    /**
43     * The BeyondWords JS SDK URL.
44     *
45     * Override with BEYONDWORDS_JS_SDK_URL in wp-config.php.
46     *
47     * @since  3.0.0
48     * @var    string
49     */
50    public const BEYONDWORDS_JS_SDK_URL = 'https://proxy.beyondwords.io/npm/@beyondwords/player@latest/dist/umd.js'; // phpcs:ignore Generic.Files.LineLength.TooLong
51
52    /**
53     * The BeyondWords AMP Player URL.
54     *
55     * Override with BEYONDWORDS_AMP_PLAYER_URL in wp-config.php.
56     *
57     * @since  3.0.0
58     * @var    string
59     */
60    public const BEYONDWORDS_AMP_PLAYER_URL = 'https://audio.beyondwords.io/amp/%d?podcast_id=%s';
61
62    /**
63     * The BeyondWords AMP image URL.
64     *
65     * Override with BEYONDWORDS_AMP_IMG_URL in wp-config.php.
66     *
67     * @since  3.0.0 Introduced
68     * @since  5.3.0 Update asset URL to Azure Storage
69     * @var    string
70     */
71    public const BEYONDWORDS_AMP_IMG_URL = 'https://beyondwords-cdn-b7fyckdeejejb6dj.a03.azurefd.net/assets/logo.svg';
72
73    /**
74     * The BeyondWords dashboard URL.
75     *
76     * Override with BEYONDWORDS_DASHBOARD_URL in wp-config.php.
77     *
78     * @since  3.0.0
79     * @var    string
80     */
81    public const BEYONDWORDS_DASHBOARD_URL = 'https://dash.beyondwords.io';
82
83    /**
84     * Auto-sync settings.
85     *
86     * @since  5.2.0
87     * @var    bool
88     */
89    public const BEYONDWORDS_AUTO_SYNC_SETTINGS = true;
90
91    public static function getApiUrl(): string
92    {
93        if (defined('BEYONDWORDS_API_URL') && strlen(BEYONDWORDS_API_URL)) {
94            return BEYONDWORDS_API_URL;
95        }
96
97        return static::BEYONDWORDS_API_URL;
98    }
99
100    public static function getBackendUrl(): string
101    {
102        if (defined('BEYONDWORDS_BACKEND_URL') && strlen(BEYONDWORDS_BACKEND_URL)) {
103            return BEYONDWORDS_BACKEND_URL;
104        }
105
106        return static::BEYONDWORDS_BACKEND_URL;
107    }
108
109    public static function getJsSdkUrl(): string
110    {
111        if (defined('BEYONDWORDS_JS_SDK_URL') && strlen(BEYONDWORDS_JS_SDK_URL)) {
112            return BEYONDWORDS_JS_SDK_URL;
113        }
114
115        return static::BEYONDWORDS_JS_SDK_URL;
116    }
117
118    public static function getAmpPlayerUrl(): string
119    {
120        if (defined('BEYONDWORDS_AMP_PLAYER_URL') && strlen(BEYONDWORDS_AMP_PLAYER_URL)) {
121            return BEYONDWORDS_AMP_PLAYER_URL;
122        }
123
124        return static::BEYONDWORDS_AMP_PLAYER_URL;
125    }
126
127    public static function getAmpImgUrl(): string
128    {
129        if (defined('BEYONDWORDS_AMP_IMG_URL') && strlen(BEYONDWORDS_AMP_IMG_URL)) {
130            return BEYONDWORDS_AMP_IMG_URL;
131        }
132
133        return static::BEYONDWORDS_AMP_IMG_URL;
134    }
135
136    public static function getDashboardUrl(): string
137    {
138        if (defined('BEYONDWORDS_DASHBOARD_URL') && strlen(BEYONDWORDS_DASHBOARD_URL)) {
139            return BEYONDWORDS_DASHBOARD_URL;
140        }
141
142        return static::BEYONDWORDS_DASHBOARD_URL;
143    }
144
145    public static function hasAutoSyncSettings(): bool
146    {
147        $value = static::BEYONDWORDS_AUTO_SYNC_SETTINGS;
148
149        if (defined('BEYONDWORDS_AUTO_SYNC_SETTINGS')) {
150            $value = (bool) BEYONDWORDS_AUTO_SYNC_SETTINGS;
151        }
152
153        return $value;
154    }
155}