Completed
Push — master ( e7d63d...93c42a )
by Marin
02:17
created

Carbon_Breadcrumb_Item_Term   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setup_title() 0 4 1
A setup_link() 0 4 1
A setup() 0 17 3
1
<?php
2
/**
3
 * Breadcrumb item class for taxonomy terms.
4
 *
5
 * Used for breadcrumb items that represent a term of any taxonomy.
6
 */
7
class Carbon_Breadcrumb_Item_Term extends Carbon_Breadcrumb_Item_DB_Object {
8
9
	/**
10
	 * Term object.
11
	 *
12
	 * @access public
13
	 * @var object
14
	 */
15
	public $term_object;
16
17
	/**
18
	 * Configure the title and link URL by using the specified term ID.
19
	 *
20
	 * @access public
21
	 */
22 3
	public function setup() {
23
		// in order to continue, taxonomy term ID must be specified
24 3
		if ( ! $this->get_id() ) {
25 1
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have term ID specified.' );
26
		}
27
28
		// in order to continue, taxonomy must be specified
29 2
		if ( ! $this->get_subtype() ) {
30 1
			throw new Carbon_Breadcrumb_Exception( 'The term breadcrumb items must have taxonomy specified.' );
31
		}
32
33
		// retrieve term object
34 1
		$subtype = $this->get_subtype();
35 1
		$this->term_object = get_term_by( 'id', $this->get_id(), $subtype );
36
37 1
		parent::setup();
38 1
	}
39
40
	/**
41
	 * Setup the title of this item.
42
	 *
43
	 * @access public
44
	 */
45 1
	public function setup_title() {
46 1
		$title = apply_filters( 'the_title', $this->term_object->name );
47 1
		$this->set_title( $title );
48 1
	}
49
50
	/**
51
	 * Setup the link of this item.
52
	 *
53
	 * @access public
54
	 */
55 1
	public function setup_link() {
56 1
		$link = get_term_link( $this->term_object->term_id, $this->term_object->taxonomy );
57 1
		$this->set_link( $link );
58 1
	}
59
60
}