Completed
Push — master ( 226003...873ec4 )
by J.D.
03:07
created

WordPoints_Entity_Attr::get_field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Entity attribute class.
5
 *
6
 * @package wordpoints-hooks-api
7
 * @since 1.0.0
8
 */
9
10
/**
11
 * Represents an Entity attribute.
12
 *
13
 * Using a Post as an example type of entity, an example of an attribute would be the
14
 * title.
15
 *
16
 * Each attribute is represented by a child of this class.
17
 *
18
 * @since 1.0.0
19
 */
20
abstract class WordPoints_Entity_Attr
21
	extends WordPoints_Entityish
22
	implements WordPoints_Entity_ChildI {
23
24
	/**
25
	 * The data type of the values of this attribute.
26
	 *
27
	 * @since 1.0.0
28
	 *
29
	 * @var string
30
	 */
31
	protected $data_type;
32
33
	/**
34
	 * Get the value of this attribute from an entity.
35
	 *
36
	 * @since 1.0.0
37
	 *
38
	 * @param WordPoints_Entity $entity The entity.
39
	 *
40
	 * @return mixed The attribute value.
41
	 */
42
	abstract protected function get_attr_value_from_entity( WordPoints_Entity $entity );
43
44
	/**
45
	 * Get the data type of this attribute's values.
46
	 *
47
	 * @since 1.0.0
48
	 *
49
	 * @return string The data type of this attribute's values.
50
	 */
51
	public function get_data_type() {
52
		return $this->data_type;
53
	}
54
55
	/**
56
	 * Set the value of this attribute from an entity.
57
	 *
58
	 * This class can represent either a type of attribute generically (e.g., Post
59
	 * title) or a specific value of that attribute (the title of a specific Post).
60
	 * This method is used to set a specific value for the attribute this object
61
	 * should represent.
62
	 *
63
	 * @since 1.0.0
64
	 *
65
	 * @param WordPoints_Entity $entity An entity object.
66
	 *
67
	 * @return bool Whether the value was set correctly.
68
	 */
69
	public function set_the_value_from_entity( WordPoints_Entity $entity ) {
70
71
		$this->the_value = $this->get_attr_value_from_entity( $entity );
72
73
		return true;
74
	}
75
}
76
77
// EOF
78