Completed
Push — master ( 349ff5...40080a )
by Jean-Christophe
03:11
created

ListView::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace Ajax\semantic\widgets;
4
5
use Ajax\common\Widget;
6
use Ajax\JsUtils;
7
use Ajax\semantic\html\collections\HtmlTable;
8
9
class ListView extends Widget {
10
11
12
	public function run(JsUtils $js){
13
		parent::run($js);
14
	}
15
16
	public function __construct($identifier,$model,$modelInstance=NULL) {
17
		parent::__construct($identifier, $model,$modelInstance);
0 ignored issues
show
Unused Code introduced by
The call to Widget::__construct() has too many arguments starting with $modelInstance.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
18
		$this->_instanceViewer=new InstanceViewer();
0 ignored issues
show
Bug introduced by
The property _instanceViewer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
	}
20
21
	public function compile(JsUtils $js=NULL,&$view=NULL){
22
		$this->_instanceViewer->setInstance($this->_model);
0 ignored issues
show
Bug introduced by
The property _model does not seem to exist. Did you mean _modelInstance?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
23
		$captions=$this->_instanceViewer->getCaptions();
24
		$table=new HtmlTable($this->identifier,0,\sizeof($captions));
25
		$table->setHeaderValues($captions);
26
		$table->fromDatabaseObjects($this->_modelInstance, function($instance){
27
			$this->_instanceViewer->setInstance($instance);
28
			return $this->_instanceViewer->getValues();
29
		});
30
		$this->content=$table;
31
		return parent::compile($js,$view);
32
	}
33
34
	public function getInstanceViewer() {
35
		return $this->_instanceViewer;
36
	}
37
38
	public function setInstanceViewer($_instanceViewer) {
39
		$this->_instanceViewer=$_instanceViewer;
40
		return $this;
41
	}
42
43
	public function setCaptions($captions){
44
		$this->_instanceViewer->setCaptions($captions);
45
		return $this;
46
	}
47
48
	public function setFields($fields){
49
		$this->_instanceViewer->setVisibleProperties($fields);
50
		return $this;
51
	}
52
53
	public function setValueFunction($index,$callback){
54
		$this->_instanceViewer->setValueFunction($index, $callback);
55
		return $this;
56
	}
57
58
}