Completed
Push — master ( 5f2e51...f2779d )
by Jean-Christophe
03:46
created

InstanceViewerCaption   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCaption() 0 8 3
A getCaptions() 0 16 4
A setCaptions() 0 4 1
1
<?php
2
namespace Ajax\semantic\widgets\base;
3
use Ajax\semantic\widgets\base\InstanceViewer;
4
5
class InstanceViewerCaption extends InstanceViewer {
6
	protected $captions;
7
8
	public function __construct($instance=NULL,$captions=NULL){
9
		parent::__construct($instance);
10
		$this->setCaptions($captions);
11
	}
12
13
	public function getCaption($index){
14
		if($this->properties[$index] instanceof \ReflectionProperty)
15
			return $this->properties[$index]->getName();
16
		elseif(\is_callable($this->properties[$index]))
17
			return "";
18
		else
19
			return $this->properties[$index];
20
	}
21
22
	public function getCaptions(){
23
		if(isset($this->captions)){
24
			$result= $this->captions;
25
			for($i=\sizeof($result);$i<$this->count();$i++){
26
				$result[]="";
27
			}
28
			return $result;
29
		}
30
		$captions=[];
31
		$index=0;
32
		$count=$this->count();
33
		while($index<$count){
34
			$captions[]=$this->getCaption($index++);
35
		}
36
		return $captions;
37
	}
38
39
	public function setCaptions($captions) {
40
		$this->captions=$captions;
41
		return $this;
42
	}
43
}