Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
17 | class HtmlTab extends HtmlSemCollection{ |
||
18 | |||
19 | protected $params=array("debug"=>true); |
||
20 | |||
21 | public function __construct( $identifier, $tabs=array()){ |
||
28 | |||
29 | /** |
||
30 | * {@inheritDoc} |
||
31 | * @see \Ajax\common\html\HtmlCollection::createItem() |
||
32 | * @return HtmlSegment |
||
33 | */ |
||
34 | protected function createItem($value){ |
||
46 | |||
47 | /** |
||
48 | * @param int $count |
||
49 | * @param string $content |
||
50 | * @param string $datatab |
||
51 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
52 | */ |
||
53 | private function createSegment($count,$content,$datatab){ |
||
58 | |||
59 | /** |
||
60 | * Sets the content of the tab at position $index |
||
61 | * @param int $index index of the tab |
||
62 | * @param String $content new content |
||
63 | * @return \Ajax\semantic\html\modules\HtmlTab |
||
64 | */ |
||
65 | public function setTabContent($index,$content){ |
||
75 | |||
76 | /** |
||
77 | * Sets all contents of tabs |
||
78 | * @param array $contents |
||
79 | * @return \Ajax\semantic\html\modules\HtmlTab |
||
80 | */ |
||
81 | public function setTabsContent($contents){ |
||
87 | |||
88 | /** |
||
89 | * Activates the tab element at $index |
||
90 | * @param int $index |
||
91 | * @return \Ajax\semantic\html\modules\HtmlTab |
||
92 | */ |
||
93 | public function activate($index){ |
||
98 | |||
99 | /** |
||
100 | * Adds a new tab |
||
101 | * @param string $title |
||
102 | * @param string $content |
||
103 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
104 | */ |
||
105 | public function addTab($title,$content){ |
||
108 | |||
109 | /** |
||
110 | * Renders the content of $controller::$action and sets the response to the tab at $index position |
||
111 | * @param int $index |
||
112 | * @param JsUtils $js |
||
113 | * @param string $title The panel title |
||
114 | * @param Controller $initialController |
||
115 | * @param string $controller a controller |
||
116 | * @param string $action an action |
||
117 | * @param array $params |
||
118 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
119 | */ |
||
120 | View Code Duplication | public function forwardTab($index,JsUtils $js,$title,$initialController,$controller,$action,$params=array()){ |
|
128 | |||
129 | /** |
||
130 | * Renders the content of an existing view : $controller/$action and sets the response to the tab at $index position |
||
131 | * @param $index |
||
132 | * @param JsUtils $js |
||
133 | * @param string $title The panel title |
||
134 | * @param Controller $initialController |
||
135 | * @param string $viewName |
||
136 | * @param $params The parameters to pass to the view |
||
137 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
138 | */ |
||
139 | View Code Duplication | public function renderViewTab($index,JsUtils $js,$title,$initialController, $viewName, $params=array()) { |
|
146 | |||
147 | |||
148 | /** |
||
149 | * render the content of $controller::$action and set the response to a new tab |
||
150 | * @param JsUtils $js |
||
151 | * @param string $title The panel title |
||
152 | * @param Controller $initialController |
||
153 | * @param string $controller a controller |
||
154 | * @param string $action an action |
||
155 | * @param array $params |
||
156 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
157 | */ |
||
158 | public function addAndForwardTab(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){ |
||
161 | |||
162 | /** |
||
163 | * render the content of an existing view : $controller/$action and set the response to a new tab |
||
164 | * @param JsUtils $js |
||
165 | * @param string $title The panel title |
||
166 | * @param Controller $initialController |
||
167 | * @param string $viewName |
||
168 | * @param $params The parameters to pass to the view |
||
169 | * @return \Ajax\semantic\html\elements\HtmlSegment |
||
170 | */ |
||
171 | public function addAndRenderViewTab(JsUtils $js,$title,$initialController, $viewName, $params=array()) { |
||
174 | |||
175 | public function setPointing($value=Direction::NONE) { |
||
178 | |||
179 | public function setSecondary() { |
||
182 | |||
183 | /** |
||
184 | * Returns the menu item at position $index |
||
185 | * @param int $index |
||
186 | * @return Ajax\semantic\html\content\HtmlMenuItem |
||
187 | */ |
||
188 | public function getMenuTab($index){ |
||
191 | |||
192 | /** |
||
193 | * Returns the tab at position $index |
||
194 | * @param int $index |
||
195 | * @return HtmlSegment |
||
196 | */ |
||
197 | public function getTab($index){ |
||
200 | |||
201 | /** |
||
202 | * Sets the menu of tabs |
||
203 | * @param HtmlMenu $menu |
||
204 | * @return \Ajax\semantic\html\modules\HtmlTab |
||
205 | */ |
||
206 | public function setMenu($menu){ |
||
225 | |||
226 | /* |
||
227 | * (non-PHPdoc) |
||
228 | * @see BaseHtml::run() |
||
229 | */ |
||
230 | public function run(JsUtils $js) { |
||
236 | |||
237 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
242 | } |
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: