Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
70.37% covered (warning)
70.37%
19 / 27
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Environment
70.37% covered (warning)
70.37%
19 / 27
0.00% covered (danger)
0.00%
0 / 8
34.59
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
 hasPlayerInlineScriptTag
80.00% covered (success)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
 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     * Use the inline player script.
85     *
86     * Override with BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG in wp-config.php.
87     *
88     * @since  5.2.0
89     * @var    bool
90     */
91    public const BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG = false;
92
93    /**
94     * Auto-sync settings.
95     *
96     * @since  5.2.0
97     * @var    bool
98     */
99    public const BEYONDWORDS_AUTO_SYNC_SETTINGS = true;
100
101    /**
102     * @return string
103     */
104    public static function getApiUrl()
105    {
106        if (defined('BEYONDWORDS_API_URL') && strlen(BEYONDWORDS_API_URL)) {
107            return BEYONDWORDS_API_URL;
108        }
109
110        return static::BEYONDWORDS_API_URL;
111    }
112
113    /**
114     * @return string
115     */
116    public static function getBackendUrl()
117    {
118        if (defined('BEYONDWORDS_BACKEND_URL') && strlen(BEYONDWORDS_BACKEND_URL)) {
119            return BEYONDWORDS_BACKEND_URL;
120        }
121
122        return static::BEYONDWORDS_BACKEND_URL;
123    }
124
125    /**
126     * @return string
127     */
128    public static function getJsSdkUrl()
129    {
130        if (defined('BEYONDWORDS_JS_SDK_URL') && strlen(BEYONDWORDS_JS_SDK_URL)) {
131            return BEYONDWORDS_JS_SDK_URL;
132        }
133
134        return static::BEYONDWORDS_JS_SDK_URL;
135    }
136
137    /**
138     * @return string
139     */
140    public static function getAmpPlayerUrl()
141    {
142        if (defined('BEYONDWORDS_AMP_PLAYER_URL') && strlen(BEYONDWORDS_AMP_PLAYER_URL)) {
143            return BEYONDWORDS_AMP_PLAYER_URL;
144        }
145
146        return static::BEYONDWORDS_AMP_PLAYER_URL;
147    }
148
149    /**
150     * @return string
151     */
152    public static function getAmpImgUrl()
153    {
154        if (defined('BEYONDWORDS_AMP_IMG_URL') && strlen(BEYONDWORDS_AMP_IMG_URL)) {
155            return BEYONDWORDS_AMP_IMG_URL;
156        }
157
158        return static::BEYONDWORDS_AMP_IMG_URL;
159    }
160
161    /**
162     * @return string
163     */
164    public static function getDashboardUrl()
165    {
166        if (defined('BEYONDWORDS_DASHBOARD_URL') && strlen(BEYONDWORDS_DASHBOARD_URL)) {
167            return BEYONDWORDS_DASHBOARD_URL;
168        }
169
170        return static::BEYONDWORDS_DASHBOARD_URL;
171    }
172
173    /**
174     * @return bool
175     */
176    public static function hasPlayerInlineScriptTag()
177    {
178        $value = static::BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG;
179
180        if (defined('BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG')) {
181            $value = (bool) BEYONDWORDS_PLAYER_INLINE_SCRIPT_TAG;
182        }
183
184        /**
185         * Filters whether the inline player script tag should be loaded.
186         */
187        $value = apply_filters('beyondwords_player_inline_script_tag', $value);
188
189        return $value;
190    }
191
192    /**
193     * @return bool
194     */
195    public static function hasAutoSyncSettings()
196    {
197        $value = static::BEYONDWORDS_AUTO_SYNC_SETTINGS;
198
199        if (defined('BEYONDWORDS_AUTO_SYNC_SETTINGS')) {
200            $value = (bool) BEYONDWORDS_AUTO_SYNC_SETTINGS;
201        }
202
203        return $value;
204    }
205}