Completed
Push — master ( bb3350...c8eebb )
by Jean-Christophe
03:32
created

HtmlTab::forwardPanel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 6
1
<?php
2
namespace Ajax\semantic\html\modules;
3
4
use Ajax\semantic\html\base\HtmlSemCollection;
5
use Ajax\semantic\html\elements\HtmlSegment;
6
use Ajax\semantic\html\collections\menus\HtmlMenu;
7
use Ajax\semantic\html\base\constants\Side;
8
use Ajax\JsUtils;
9
10
class HtmlTab extends HtmlSemCollection{
11
	protected $params=array();
12
13
	public function __construct( $identifier, $tabs=array()){
14
		parent::__construct( $identifier, "div", "");
15
		$menu=new HtmlMenu("menu".$this->identifier);
16
		$menu->asTab(false)->setAttachment(NULL,Side::TOP);
0 ignored issues
show
Documentation introduced by
NULL is of type null, but the function expects a object<Ajax\semantic\htm...e\HtmlSemDoubleElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
		$this->content["menu"]=$menu;
18
		$this->addItems($tabs);
19
		if(\sizeof($tabs)>0)
20
			$this->activate(0);
21
	}
22
23
	protected function createItem($value){
24
		$count=$this->count();
25
		$title=$value;
26
		$content=NULL;
27
		if(\is_array($value)){
28
			$title=@$value[0];$content=@$value[1];
29
		}
30
		$menuItem=$this->content["menu"]->addItem($title);
31
		$menuItem->addToProperty("data-tab", $menuItem->getIdentifier());
32
		$menuItem->removeProperty("href");
33
		$segment=new HtmlSegment("item-".$this->identifier."-".$count, $content);
34
		$segment->setAttachment(NULL,Side::BOTTOM)->addToProperty("class", "tab")->addToProperty("data-tab",$menuItem->getIdentifier());
0 ignored issues
show
Documentation introduced by
NULL is of type null, but the function expects a object<Ajax\semantic\htm...e\HtmlSemDoubleElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
		return $segment;
36
	}
37
38
	public function activate($index){
39
		$this->content["menu"]->getItem($index)->setActive(true);
40
		$this->content[$index]->setActive(true);
41
		return $this;
42
	}
43
44
	public function addPanel($title,$content){
45
		return $this->addItem([$title,$content]);
0 ignored issues
show
Documentation introduced by
array($title, $content) is of type array<integer,?,{"0":"?","1":"?"}>, but the function expects a object<Ajax\common\html\HtmlDoubleElement>|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
	}
47
48
	/**
49
	 * render the content of $controller::$action and set the response to a new panel
50
	 * @param JsUtils $js
51
	 * @param string $title The panel title
52
	 * @param Controller $initialController
53
	 * @param string $controller a Phalcon controller
54
	 * @param string $action a Phalcon action
55
	 * @param array $params
56
	 */
57
	public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
58
		return $this->addPanel($title, $js->forward($initialController, $controller, $action,$params));
59
	}
60
61
	/**
62
	 * render the content of an existing view : $controller/$action and set the response to a new panel
63
	 * @param JsUtils $js
64
	 * @param string $title The panel title
65
	 * @param Controller $initialController
66
	 * @param string $viewName
67
	 * @param $params The parameters to pass to the view
68
	 */
69
	public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) {
70
		return $this->addPanel($title, $js->renderContent($initialController, $viewName,$params));
71
	}
72
73
	/*
74
	 * (non-PHPdoc)
75
	 * @see BaseHtml::run()
76
	 */
77
	public function run(JsUtils $js) {
78 View Code Duplication
		if(isset($this->_bsComponent)===false)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
			$this->_bsComponent=$js->semantic()->tab("#".$this->identifier." .item",$this->params);
80
			$this->addEventsOnRun($js);
81
			return $this->_bsComponent;
82
	}
83
}