Completed
Branch BUG-10738-inconsistency-in-ses... (860590)
by
unknown
57:39 queued 45:30
created

DomainBase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 132
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 1
A pluginFile() 0 5 1
A pluginBasename() 0 5 1
A pluginPath() 0 5 1
A pluginUrl() 0 5 1
A version() 0 5 1
A verifyInitialized() 0 15 2
1
<?php
2
3
namespace EventEspresso\core\domain;
4
5
use DomainException;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed');
8
9
10
/**
11
 * DomainBase Class
12
 * A container for all domain data related to the plugin
13
 *
14
 * @package EventEspresso\core\domain
15
 * @author  Darren Ethier
16
 * @since   4.9.38
17
 */
18
abstract class DomainBase
19
{
20
21
    /**
22
     * Equivalent to `__FILE__` for main plugin file.
23
     *
24
     * @var string
25
     */
26
    private static $plugin_file = '';
27
28
    /**
29
     * String indicating version for plugin
30
     *
31
     * @var string
32
     */
33
    private static $version = '';
34
35
    /**
36
     * @var string $plugin_basename
37
     */
38
    private static $plugin_basename = '';
39
40
    /**
41
     * @var string $plugin_path
42
     */
43
    private static $plugin_path = '';
44
45
    /**
46
     * @var string $plugin_url
47
     */
48
    private static $plugin_url = '';
49
50
51
52
    /**
53
     * Initializes internal static properties.
54
     *
55
     * @param string $plugin_file
56
     * @param string $version
57
     */
58
    public static function init($plugin_file, $version)
59
    {
60
        self::$plugin_file = $plugin_file;
61
        self::$version = $version;
62
        self::$plugin_basename = plugin_basename($plugin_file);
63
        self::$plugin_path = plugin_dir_path($plugin_file);
64
        self::$plugin_url = plugin_dir_url($plugin_file);
65
    }
66
67
68
69
    /**
70
     * @return string
71
     * @throws DomainException
72
     */
73
    public static function pluginFile()
74
    {
75
        self::verifyInitialized(__METHOD__);
76
        return self::$plugin_file;
77
    }
78
79
80
81
    /**
82
     * @return string
83
     * @throws DomainException
84
     */
85
    public static function pluginBasename()
86
    {
87
        self::verifyInitialized(__METHOD__);
88
        return self::$plugin_basename;
89
    }
90
91
92
93
    /**
94
     * @return string
95
     * @throws DomainException
96
     */
97
    public static function pluginPath()
98
    {
99
        self::verifyInitialized(__METHOD__);
100
        return self::$plugin_path;
101
    }
102
103
104
105
    /**
106
     * @return string
107
     * @throws DomainException
108
     */
109
    public static function pluginUrl()
110
    {
111
        self::verifyInitialized(__METHOD__);
112
        return self::$plugin_url;
113
    }
114
115
116
117
    /**
118
     * @return string
119
     * @throws DomainException
120
     */
121
    public static function version()
122
    {
123
        self::verifyInitialized(__METHOD__);
124
        return self::$version;
125
    }
126
127
128
129
    /**
130
     * @param string $method
131
     * @throws DomainException
132
     */
133
    private static function verifyInitialized($method)
134
    {
135
        if (self::$plugin_file === '') {
136
            throw new DomainException(
137
                sprintf(
138
                    esc_html__(
139
                        '%1$s needs to be called before %2$s can return a value.',
140
                        'event_espresso'
141
                    ),
142
                    get_called_class() . '::init()',
143
                    "{$method}()"
144
                )
145
            );
146
        }
147
    }
148
149
}
150