Completed
Push — master ( b6760c...d0c54a )
by J.D.
03:04
created

get_title()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
/**
4
 * Dynamic entity relationship class.
5
 *
6
 * @package wordpoints-hooks-api
7
 * @since 1.0.0
8
 */
9
10
/**
11
 * Represents the relationship between dynamic entities.
12
 *
13
 * @since 1.0.0
14
 */
15
abstract class WordPoints_Entity_Relationship_Dynamic extends WordPoints_Entity_Relationship {
16
17
	/**
18
	 * @since 1.0.0
19
	 */
20
	public function __construct( $slug ) {
21
22
		parent::__construct( $slug );
23
24
		$parts = explode( '\\', $this->slug, 2 );
25
26
		if ( isset( $parts[1] ) ) {
27
28
			$parsed = $this->parse_slug( $this->related_entity_slug );
29
30
			$this->primary_entity_slug = "{$this->primary_entity_slug}\\{$parts[1]}";
31
			$this->related_entity_slug = "{$parsed['slug']}\\{$parts[1]}";
32
33
			if ( $parsed['is_array'] ) {
34
				$this->related_entity_slug .= '{}';
35
			}
36
		}
37
	}
38
39
	/**
40
	 * @since 1.0.0
41
	 */
42
	public function get_title() {
43
44
		$parsed = $this->parse_slug( $this->related_entity_slug );
45
46
		$entity = wordpoints_entities()->get( $parsed['slug'] );
47
48
		if ( $entity instanceof WordPoints_Entity ) {
49
			return $entity->get_title();
50
		} else {
51
			return $this->related_entity_slug;
52
		}
53
	}
54
}
55
56
// EOF
57