This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Ajax\bootstrap\html; |
||
4 | |||
5 | use Ajax\bootstrap\html\base\CssRef; |
||
6 | use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
||
7 | |||
8 | /** |
||
9 | * Twitter Bootstrap Buttongroups component |
||
10 | * @see http://getbootstrap.com/components/#btn-groups |
||
11 | * @author jc |
||
12 | * @version 1.001 |
||
13 | */ |
||
14 | class HtmlButtongroups extends HtmlBsDoubleElement { |
||
15 | protected $elements; |
||
16 | |||
17 | View Code Duplication | public function __construct($identifier, $elements=array(), $cssStyle=NULL, $size=NULL, $tagName="div") { |
|
0 ignored issues
–
show
|
|||
18 | parent::__construct($identifier, $tagName); |
||
19 | $this->_template="<%tagName% id='%identifier%' %properties%>%elements%</%tagName%>"; |
||
20 | $this->setProperty("class", "btn-group"); |
||
21 | $this->setRole("group"); |
||
22 | $this->addElements($elements); |
||
23 | if (isset($cssStyle)) { |
||
24 | $this->setStyle($cssStyle); |
||
25 | } |
||
26 | if (isset($size)) { |
||
27 | $this->setSize($size); |
||
28 | } |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * define the buttons size |
||
33 | * available values : "btn-group-lg","","btn-group-sm","btn-group-xs" |
||
34 | * @param string|int $size |
||
35 | * @return HtmlButtongroups default : "" |
||
36 | */ |
||
37 | public function setSize($size) { |
||
38 | foreach ( $this->elements as $element ) { |
||
39 | $element->setSize($size); |
||
40 | } |
||
41 | View Code Duplication | if (is_int($size)) { |
|
0 ignored issues
–
show
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. ![]() |
|||
42 | return $this->addToPropertyUnique("class", CssRef::sizes("btn-group")[$size], CssRef::sizes("btn-group")); |
||
43 | } |
||
44 | return $this->addToPropertyCtrl("class", $size, CssRef::sizes("btn-group")); |
||
45 | } |
||
46 | |||
47 | public function setStyle($value) { |
||
48 | foreach ( $this->elements as $element ) |
||
49 | $element->setStyle($value); |
||
50 | } |
||
51 | |||
52 | private function dropdownAsButton($bt) { |
||
53 | $this->addExistingDropDown($bt); |
||
54 | $bt->setTagName("button"); |
||
55 | $bt->addBtnClass("dropdown-toogle"); |
||
56 | $bt->addBtnClass("btn-default"); |
||
57 | } |
||
58 | |||
59 | private function addExistingDropDown($bt) { |
||
60 | $bt->setMTagName("div"); |
||
61 | $bt->setRole("group"); |
||
62 | $bt->setMClass("btn-group"); |
||
63 | } |
||
64 | |||
65 | public function addElement($element) { |
||
66 | $result=$element; |
||
67 | $iid=sizeof($this->elements)+1; |
||
68 | if (($element instanceof HtmlDropdown)||($element instanceof HtmlSplitbutton)) { |
||
69 | $this->addExistingDropDown($element); |
||
70 | $this->elements[]=$element; |
||
71 | } elseif ($element instanceof HtmlButton) { |
||
72 | $this->elements[]=$element; |
||
73 | } elseif (is_array($element)) { |
||
74 | if (array_key_exists("glyph", $element)) |
||
75 | $bt=new HtmlGlyphButton($this->identifier."-button-".$iid); |
||
76 | elseif (array_key_exists("btnCaption", $element)) { |
||
77 | if (array_key_exists("split", $element)) |
||
78 | $bt=new HtmlSplitbutton($this->identifier."-dropdown-".$iid); |
||
79 | else |
||
80 | $bt=new HtmlDropdown($this->identifier."-dropdown-".$iid); |
||
81 | $this->dropdownAsButton($bt); |
||
82 | } else |
||
83 | $bt=new HtmlButton($this->identifier."-button-".$iid); |
||
84 | $bt->fromArray($element); |
||
85 | $this->elements[]=$bt; |
||
86 | $result=$bt; |
||
87 | } elseif (is_string($element)) { |
||
88 | $bt=new HtmlButton($this->identifier."-button-".$iid); |
||
89 | $bt->setValue($element); |
||
90 | $this->elements[]=$bt; |
||
91 | $result=$bt; |
||
92 | } |
||
93 | return $result; |
||
94 | } |
||
95 | |||
96 | public function addElements($elements) { |
||
97 | foreach ( $elements as $element ) { |
||
98 | $this->addElement($element); |
||
99 | } |
||
100 | return $this; |
||
101 | } |
||
102 | |||
103 | /* |
||
104 | * (non-PHPdoc) |
||
105 | * @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray() |
||
106 | */ |
||
107 | public function fromArray($array) { |
||
108 | $this->addElements($array); |
||
109 | } |
||
110 | |||
111 | public function setAlignment($value) { |
||
112 | if (is_int($value)) { |
||
113 | $value=CssRef::alignment("btn-group")[$value]; |
||
114 | } else |
||
115 | $value="btn-group-".$value; |
||
116 | if (strstr($value, "justified")) { |
||
117 | foreach ( $this->elements as $element ) { |
||
118 | $element->wrap('<div class="btn-group" role="group">', '</div>'); |
||
119 | } |
||
120 | } |
||
121 | $this->addToPropertyCtrl("class", $value, CssRef::alignment("btn-group-")); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Return the element at index |
||
126 | * @param int $index |
||
127 | * @return HtmlButton |
||
128 | */ |
||
129 | public function getElement($index) { |
||
130 | if (is_int($index)) |
||
131 | return $this->elements[$index]; |
||
0 ignored issues
–
show
The expression
$this->elements[$index]; of type Ajax\bootstrap\html\Html...p\html\HtmlButtongroups adds the type Ajax\bootstrap\html\HtmlButtongroups to the return on line 131 which is incompatible with the return type documented by Ajax\bootstrap\html\HtmlButtongroups::getElement of type Ajax\bootstrap\html\HtmlButton .
![]() |
|||
132 | else { |
||
133 | $elm=$this->getElementById($index, $this->elements); |
||
134 | return $elm; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | public function setElement($index, $button) { |
||
139 | $this->elements[$index]=$button; |
||
140 | return $this; |
||
141 | } |
||
142 | |||
143 | /* |
||
144 | * (non-PHPdoc) |
||
145 | * @see \Ajax\bootstrap\html\base\BaseHtml::on() |
||
146 | */ |
||
147 | public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
||
148 | foreach ( $this->elements as $element ) { |
||
149 | $element->on($event, $jsCode, $stopPropagation, $preventDefault); |
||
150 | } |
||
151 | return $this; |
||
152 | } |
||
153 | |||
154 | public function getElements() { |
||
155 | return $this->elements; |
||
156 | } |
||
157 | |||
158 | /* (non-PHPdoc) |
||
159 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
160 | */ |
||
161 | public function fromDatabaseObject($object, $function) { |
||
162 | $this->addElement($function($object)); |
||
163 | } |
||
164 | |||
165 | } |
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.