Completed
Push — master ( 7b30a8...0b84fa )
by Marin
02:35
created

Datastore   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 4
c 6
b 1
f 1
lcom 0
cbo 1
dl 0
loc 44
ccs 0
cts 13
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
init() 0 1 ?
A factory() 0 13 2
A make() 0 3 1
A __construct() 0 3 1
1
<?php 
2
3
namespace Carbon_Fields\Datastore;
4
5
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
6
7
/**
8
 * Base datastore.
9
 * Defines the key datastore methods and their default implementations.
10
 */
11
abstract class Datastore implements Datastore_Interface {
12
	/**
13
	 * Initialize the datastore.
14
	 **/
15
	public function __construct() {
16
		$this->init();
17
	}
18
19
	/**
20
	 * Initialization tasks for concrete datastores.
21
	 *
22
	 * @abstract
23
	 **/
24
	abstract public function init();
25
26
	/**
27
	 * Create a new datastore of type $type.
28
	 *
29
	 * @param string $type
30
	 * @return Datastore $datastore
31
	 **/
32
	public static function factory( $type ) {
33
		$type = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $type ) ) );
34
35
		$class = __NAMESPACE__ . '\\' . $type . '_Datastore';
36
37
		if ( ! class_exists( $class ) ) {
38
			Incorrect_Syntax_Exception::raise( 'Unknown data store type "' . $type . '".' );
39
		}
40
41
		$field = new $class();
42
43
		return $field;
44
	}
45
46
	/**
47
	 * An alias of factory().
48
	 *
49
	 * @see Datastore::factory()
50
	 **/
51
	public static function make( $type ) {
52
		return self::factory( $type );
53
	}
54
}
55