Passed
Push — master ( 39e959...b4c49f )
by Anton
05:37 queued 02:55
created

Extension::isInited()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Extend
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Extend\Utils {
11
12
	abstract class Extension {
13
14
		protected static $loader = null;
15
16
		/**
17
		 * Check if an item name is valid
18
		 */
19
20
		public static function isValid(string $name) : bool {
21
22
			return (preg_match(static::$regex_name, $name) ? true : false);
23
		}
24
25
		/**
26
 		 * Validate an item name
27
 		 *
28
 		 * @return string|false : the name or false on failure
29
 		 */
30
31
		public static function validate(string $name) {
32
33
			return (preg_match(static::$regex_name, $name) ? $name : false);
34
		}
35
36
		/**
37
		 * Check if the extension is inited
38
		 */
39
40
		public static function isInited() {
41
42
			return (null !== static::$loader);
43
		}
44
45
		/**
46
		 * Static overloader
47
		 */
48
49
		public static function __callStatic($name, $arguments) {
50
51
			if (null !== static::$loader) return static::$loader->$name(...$arguments);
52
53
			throw new \BadMethodCallException('Call to undefined method ' . get_called_class() . '::' . $name . '()');
54
		}
55
	}
56
}
57