| Conditions | 30 |
| Paths | 513 |
| Total Lines | 94 |
| Code Lines | 61 |
| Lines | 94 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 197 | * |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function editHeader($row, $href, $label, $title, $icon, $attributes) |
||
| 201 | {
|
||
| 202 | return '<a href="'.$this->addToUrl($href.'&id='.$row['id']).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> '; |
||
| 203 | } |
||
| 204 | /** |
||
| 205 | * Add the type of input field |
||
| 206 | * |
||
| 207 | * @param array $arrRow |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | public function listQuestions($arrRow) |
||
| 212 | {
|
||
| 213 | $key = $arrRow['published'] ? 'published' : 'unpublished'; |
||
| 214 | $date = Date::parse(Config::get('datimFormat'), $arrRow['tstamp']);
|
||
| 215 | return ' |
||
| 216 | <div class="cte_type ' . $key . '">' . $date . '</div> |
||
| 217 | <div class="limit_height' . (!Config::get('doNotCollapse') ? ' h40' : '') . '">
|
||
| 218 | ' . StringUtil::insertTagToSrc($arrRow['name']) . |
||
| 219 | (!empty($arrRow['infotext']) ? '<span style="color:#b3b3b3;padding-left:3px">[' . StringUtil::insertTagToSrc($arrRow['infotext']) . ']</span>' : '') . ' |
||
| 220 | </div>' . "\n"; |
||
| 221 | } |
||
| 222 | /** |
||
| 223 | * Return the "toggle visibility" button |
||
| 224 | * |
||
| 225 | * @param array $row |
||
| 226 | * @param string $href |
||
| 227 | * @param string $label |
||
| 228 | * @param string $title |
||
| 229 | * @param string $icon |
||
| 230 | * @param string $attributes |
||
| 231 | * |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function toggleIcon($row, $href, $label, $title, $icon, $attributes) |
||
| 235 | {
|
||
| 236 | if (strlen(Input::get('tid')))
|
||
| 237 | {
|
||
| 238 | $this->toggleVisibility(Input::get('tid'), (Input::get('state') == 1), (@func_get_arg(12) ?: null));
|
||
| 239 | $this->redirect($this->getReferer()); |
||
| 240 | } |
||
| 241 | |||
| 242 | $href .= '&tid='.$row['id'].'&state='.($row['published'] ? '' : 1); |
||
| 243 | if (!$row['published']) |
||
| 244 | {
|
||
| 245 | $icon = 'invisible.svg'; |
||
| 246 | } |
||
| 247 | return '<a href="'.$this->addToUrl($href).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label, 'data-state="' . ($row['published'] ? 1 : 0) . '"').'</a> '; |
||
| 248 | } |
||
| 249 | /** |
||
| 250 | * Disable/enable a user group |
||
| 251 | * |
||
| 252 | * @param integer $intId |
||
| 253 | * @param boolean $blnVisible |
||
| 254 | * @param DataContainer $dc |
||
| 255 | * |
||
| 256 | * @throws Contao\CoreBundle\Exception\AccessDeniedException |
||
| 257 | */ |
||
| 258 | public function toggleVisibility($intId, $blnVisible, DataContainer $dc=null) {
|
||
| 259 | // Set the ID and action |
||
| 260 | Input::setGet('id', $intId);
|
||
| 261 | Input::setGet('act', 'toggle');
|
||
| 262 | if($dc) {
|
||
| 263 | $dc->id = $intId; // see #8043 |
||
| 264 | } |
||
| 265 | |||
| 266 | // Set the current record |
||
| 267 | if($dc) {
|
||
| 268 | $objRow = $this->Database->prepare("SELECT * FROM tl_belegungsplan_objekte WHERE id=?")
|
||
| 269 | ->limit(1) |
||
| 270 | ->execute($intId); |
||
| 271 | if($objRow->numRows) {
|
||
| 272 | $dc->activeRecord = $objRow; |
||
| 273 | } |
||
| 274 | } |
||
| 275 | $objVersions = new Versions('tl_belegungsplan_objekte', $intId);
|
||
| 276 | $objVersions->initialize(); |
||
| 277 | // Trigger the save_callback |
||
| 278 | if(is_array($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['fields']['published']['save_callback'])) {
|
||
| 279 | foreach($GLOBALS['TL_DCA']['tl_belegungsplan_objekte']['fields']['published']['save_callback'] as $callback) {
|
||
| 280 | if(is_array($callback)) {
|
||
| 281 | $this->import($callback[0]); |
||
| 282 | $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc);
|
||
| 283 | } |
||
| 284 | elseif(is_callable($callback)) {
|
||
| 285 | $blnVisible = $callback($blnVisible, $dc); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | } |
||
| 289 | $time = time(); |
||
| 290 | // Update the database |
||
| 291 | $this->Database->prepare("UPDATE tl_belegungsplan_objekte SET tstamp=$time, published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")
|
||
| 312 |