Datastore   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
init() 0 1 ?
A __construct() 0 3 1
A get_object_id() 0 3 1
A set_object_id() 0 3 1
A factory() 0 12 2
A make() 0 3 1
1
<?php
2
3
namespace Carbon_Fields\Datastore;
4
5
use Carbon_Fields\Helper\Helper;
6
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
7
8
/**
9
 * Base datastore.
10
 * Defines the key datastore methods and their default implementations.
11
 */
12
abstract class Datastore implements Datastore_Interface {
13
14
	/**
15
	 * The related object id
16
	 *
17
	 * @var integer
18
	 */
19
	protected $object_id = 0;
20
21
	/**
22
	 * Initialize the datastore.
23
	 */
24
	public function __construct() {
25
		$this->init();
26
	}
27
28
	/**
29
	 * Initialization tasks for concrete datastores.
30
	 *
31
	 * @abstract
32
	 */
33
	abstract public function init();
34
35
	/**
36
	 * Get the related object id
37
	 *
38
	 * @return integer
39
	 */
40
	public function get_object_id() {
41
		return $this->object_id;
42
	}
43
44
	/**
45
	 * Set the related object id
46
	 *
47
	 * @param  integer $object_id
48
	 */
49
	public function set_object_id( $object_id ) {
50
		$this->object_id = $object_id;
51
	}
52
53
	/**
54
	 * Create a new datastore of type $raw_type.
55
	 *
56
	 * @param string $raw_type
57
	 * @return Datastore_Interface
58
	 */
59
	public static function factory( $raw_type ) {
60
		$type = Helper::normalize_type( $raw_type );
61
		$class = Helper::type_to_class( $type, __NAMESPACE__, '_Datastore' );
62
		if ( ! class_exists( $class ) ) {
63
			Incorrect_Syntax_Exception::raise( 'Unknown datastore type "' . $raw_type . '".' );
64
			return null;
65
		}
66
67
		$datastore = new $class();
68
69
		return $datastore;
70
	}
71
72
	/**
73
	 * An alias of factory().
74
	 *
75
	 * @see    Datastore::factory()
76
	 * @return Datastore_Interface
77
	 */
78
	public static function make() {
79
		return call_user_func_array( array( get_class(), 'factory' ), func_get_args() );
80
	}
81
}
82