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