Completed
Push — develop ( 39675e...5a1eb7 )
by David
02:50
created

Abstract_Sync_Object_Adapter::get_meta()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Dataset;
4
5
use Wordlift\Jsonld\Jsonld_Service;
6
use Wordlift\Object_Type_Enum;
7
8
abstract class Abstract_Sync_Object_Adapter implements Sync_Object_Adapter {
9
10
	private $object_id;
11
12
	private $type;
13
14
	private $get_meta;
15
16
	private $update_meta;
17
18
	private static $meta_name = array(
19
		Object_Type_Enum::POST => 'post',
20
		Object_Type_Enum::TERM => 'term',
21
		Object_Type_Enum::USER => 'user',
22
	);
23
24
	/**
25
	 * Sync_Object_Adapter constructor.
26
	 *
27
	 * @param int $type One of Object_Type_Enum.
28
	 * @param int $object_id A post or term id.
29
	 * @param Jsonld_Service
30
	 *
31
	 * @throws \Exception
32
	 */
33
	function __construct( $type, $object_id ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
35
		$this->type      = filter_var( $type, FILTER_VALIDATE_INT );
36
		$this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
37
38
		if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) {
39
			throw new \Exception( 'Invalid $type.' );
40
		}
41
		if ( null === $this->object_id ) {
42
			throw new \Exception( 'Invalid $object.' );
43
		}
44
45
		$this->get_meta    = sprintf( 'get_%s_meta', self::$meta_name[ $this->type ] );
46
		$this->update_meta = sprintf( 'update_%s_meta', self::$meta_name[ $this->type ] );
47
48
	}
49
50
	function get_meta( $meta_key, $single ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
51
52
		return call_user_func( $this->get_meta, $this->object_id, $meta_key, $single );
53
	}
54
55
	function update_meta( $meta_key, $meta_value ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
57
		call_user_func( $this->update_meta, $this->object_id, $meta_key, $meta_value );
58
59
	}
60
61
}
62