Completed
Push — master ( e47c17...035b95 )
by
unknown
04:49
created

autoload.php ➔ SimpleCalendar_Autoload()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
/**
3
 * Autoloader
4
 *
5
 * @package SimpleCalendar
6
 */
7
8
if ( ! defined( 'ABSPATH' ) ) {
9
	exit;
10
}
11
12
if ( ! function_exists( 'SimpleCalendar_Autoload' ) ) {
13
14
	/**
15
	 * Plugin autoloader.
16
	 *
17
	 * Pattern (with or without <Subnamespace>):
18
	 *  <Namespace>/<Subnamespace>.../Class_Name (or Classname)
19
	 *  'includes/subdir.../class-name.php' or '...classname.php'
20
	 *
21
	 * @since 3.0.0
22
	 *
23
	 * @param $class
24
	 */
25
	function SimpleCalendar_Autoload( $class ) {
26
27
		// Do not load unless in plugin domain.
28
		$namespace = 'SimpleCalendar';
29
		if ( strpos( $class, $namespace ) !== 0 ) {
0 ignored issues
show
introduced by
Found "!== 0". Use Yoda Condition checks, you must
Loading history...
30
			return;
31
		}
32
33
		// Converts Class_Name (class convention) to class-name (file convention).
34
		$class_name = implode( '-', array_map( 'lcfirst', explode( '_', strtolower( $class ) ) ) );
35
36
		// Remove the root namespace.
37
		$unprefixed = substr( $class_name, strlen( $namespace ) );
38
39
		// Build the file path.
40
		$file_path = str_replace( '\\', DIRECTORY_SEPARATOR, $unprefixed );
41
		$file      = dirname( __FILE__ ) . '/' . $file_path . '.php';
42
43
		if ( file_exists( $file ) ) {
44
			require $file;
45
		}
46
47
	}
48
49
	// Register the autoloader.
50
	spl_autoload_register( 'SimpleCalendar_Autoload' );
51
52
}
53