Completed
Pull Request — develop (#1080)
by Naveen
03:17
created

Data_Source_Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get_data() 0 10 3
A get_instance() 0 7 2
1
<?php
2
/**
3
 * @since      3.27.0
4
 * @package    Wordlift
5
 * @subpackage Wordlift/Mappings/Data_Source
6
 */
7
8
namespace Wordlift\Mappings\Data_Source;
9
10
use Wordlift\Mappings\Jsonld_Converter;
11
12
class Data_Source_Factory {
13
14
	private static $instance = null;
15
16
	private $data_sources = array();
17
18
	public function __construct() {
19
		$this->data_sources = array(
20
			'acf'  => new Acf_Data_Source(),
21
			'meta' => new Meta_Data_Source()
22
		);
23
	}
24
25
	public function get_data( $post_id, $property_data ) {
26
		switch ( $property_data['field_type'] ) {
27
			case Jsonld_Converter::FIELD_TYPE_ACF:
28
				return $this->data_sources['acf']->get_data( $post_id, $property_data );
29
			case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD:
30
				return $this->data_sources['meta']->get_data( $post_id, $property_data );
31
			default:
32
				return $property_data['field_name'];
33
		}
34
	}
35
36
37
	/**
38
	 * @return Data_Source_Factory
39
	 */
40
	public static function get_instance() {
41
		if ( self::$instance === null ) {
42
			self::$instance = new Data_Source_Factory();
43
		}
44
45
		return self::$instance;
46
	}
47
48
}
49