Carbon_Breadcrumb_Item   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 228
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 1
dl 0
loc 228
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 8 1
A __construct() 0 3 1
A get_title() 0 3 1
A set_title() 0 3 1
A get_link() 0 3 1
A set_link() 0 3 1
A get_attributes() 0 3 1
A set_attributes() 0 3 1
A get_priority() 0 3 1
A set_priority() 0 3 1
A get_type() 0 3 1
A set_type() 0 3 1
A get_subtype() 0 3 1
A set_subtype() 0 3 1
setup() 0 1 ?
1
<?php
2
/**
3
 * Abstract breadcrumb item
4
 *
5
 * @package carbon-breadcrumbs
6
 */
7
8
/**
9
 * Abstract breadcrumb item class.
10
 *
11
 * Used as a base for all breadcrumb item types.
12
 */
13
abstract class Carbon_Breadcrumb_Item extends Carbon_Breadcrumb_Factory {
14
15
	/**
16
	 * Breadcrumb item title.
17
	 *
18
	 * @access protected
19
	 * @var string
20
	 */
21
	protected $title;
22
23
	/**
24
	 * Breadcrumb item link URL.
25
	 *
26
	 * @access protected
27
	 * @var string
28
	 */
29
	protected $link;
30
31
	/**
32
	 * Breadcrumb item link additional attributes.
33
	 *
34
	 * @access protected
35
	 * @var array
36
	 */
37
	protected $attributes = array(
38
		'target' => '_self',
39
	);
40
41
	/**
42
	 * Breadcrumb item priority.
43
	 *
44
	 * @access protected
45
	 * @var int
46
	 */
47
	protected $priority = 1000;
48
49
	/**
50
	 * Breadcrumb item type.
51
	 *
52
	 * @access protected
53
	 * @var string
54
	 */
55
	protected $type = '';
56
57
	/**
58
	 * Breadcrumb item subtype.
59
	 *
60
	 * @access protected
61
	 * @var string
62
	 */
63
	protected $subtype = '';
64
65
	/**
66
	 * Build a new breadcrumb item of the selected type.
67
	 *
68
	 * @static
69
	 * @access public
70
	 *
71
	 * @param string $type Type of the breadcrumb item.
72
	 * @param int    $priority Priority of this breadcrumb item.
73
	 * @return Carbon_Breadcrumb_Item $item The new breadcrumb item.
74
	 */
75
	public static function factory( $type = 'custom', $priority = 1000 ) {
76
		$class = self::verify_class_name( __CLASS__ . '_' . $type, 'Unexisting breadcrumb item type: "' . $type . '".' );
77
78
		$item = new $class( $priority );
79
		$item->set_type( $type );
80
81
		return $item;
82
	}
83
84
	/**
85
	 * Constructor.
86
	 *
87
	 * Creates and configures a new breadcrumb item with the provided settings.
88
	 *
89
	 * @access public
90
	 *
91
	 * @param int $priority Priority of this breadcrumb item.
92
	 */
93
	public function __construct( $priority = 1000 ) {
94
		$this->set_priority( $priority );
95
	}
96
97
	/**
98
	 * Retrieve the breadcrumb item title.
99
	 *
100
	 * @access public
101
	 *
102
	 * @return string $title The title of this breadcrumb item.
103
	 */
104
	public function get_title() {
105
		return $this->title;
106
	}
107
108
	/**
109
	 * Modify the title of this breadcrumb item.
110
	 *
111
	 * @access public
112
	 *
113
	 * @param string $title The new title.
114
	 */
115
	public function set_title( $title ) {
116
		$this->title = $title;
117
	}
118
119
	/**
120
	 * Retrieve the breadcrumb item link URL.
121
	 *
122
	 * @access public
123
	 *
124
	 * @return string $link The link URL of this breadcrumb item.
125
	 */
126
	public function get_link() {
127
		return $this->link;
128
	}
129
130
	/**
131
	 * Modify the link URL of this breadcrumb item.
132
	 *
133
	 * @access public
134
	 *
135
	 * @param string $link The new link URL.
136
	 */
137
	public function set_link( $link = '' ) {
138
		$this->link = $link;
139
	}
140
141
	/**
142
	 * Retrieve the breadcrumb item link attributes.
143
	 *
144
	 * @access public
145
	 *
146
	 * @return array $attributes The link attributes of this breadcrumb item.
147
	 */
148
	public function get_attributes() {
149
		return $this->attributes;
150
	}
151
152
	/**
153
	 * Modify the link attributes of this breadcrumb item.
154
	 *
155
	 * @access public
156
	 *
157
	 * @param array $attributes The new link attributes.
158
	 */
159
	public function set_attributes( $attributes = array() ) {
160
		$this->attributes = $attributes;
161
	}
162
163
	/**
164
	 * Retrieve the breadcrumb item priority.
165
	 *
166
	 * @access public
167
	 *
168
	 * @return int $priority The priority of this breadcrumb item.
169
	 */
170
	public function get_priority() {
171
		return $this->priority;
172
	}
173
174
	/**
175
	 * Modify the priority of this breadcrumb item.
176
	 *
177
	 * @access public
178
	 *
179
	 * @param int $priority The new priority.
180
	 */
181
	public function set_priority( $priority ) {
182
		$this->priority = $priority;
183
	}
184
185
	/**
186
	 * Retrieve the type of this breadcrumb item.
187
	 *
188
	 * @access public
189
	 *
190
	 * @return string $type The type of this breadcrumb item.
191
	 */
192
	public function get_type() {
193
		return $this->type;
194
	}
195
196
	/**
197
	 * Modify the type of this breadcrumb item.
198
	 *
199
	 * @access public
200
	 *
201
	 * @param string $type The new breadcrumb item type.
202
	 */
203
	public function set_type( $type ) {
204
		$this->type = $type;
205
	}
206
207
	/**
208
	 * Retrieve the subtype of this breadcrumb item.
209
	 *
210
	 * @access public
211
	 *
212
	 * @return string $subtype The subtype of this breadcrumb item.
213
	 */
214
	public function get_subtype() {
215
		return $this->subtype;
216
	}
217
218
	/**
219
	 * Modify the subtype of this breadcrumb item.
220
	 *
221
	 * @access public
222
	 *
223
	 * @param string $subtype The new breadcrumb item subtype.
224
	 */
225
	public function set_subtype( $subtype ) {
226
		$this->subtype = $subtype;
227
	}
228
229
	/**
230
	 * Setup this breadcrumb item.
231
	 *
232
	 * This method can be used to automatically set this item's title, link
233
	 * and other settings in the child class.
234
	 *
235
	 * @abstract
236
	 * @access public
237
	 */
238
	abstract public function setup();
239
240
}
241