Commit 304391e5 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(code) Fix sonar warnings

Using custom exceptions, avoid same name as class fields, fix a mistake.

issue #5831
parent 280805c1
......@@ -387,7 +387,7 @@ class filter
break;
default:
throw new Exception ('Unknown element type specified: '.$element['type'].'!');
throw new FusionDirectoryException ('Unknown element type specified: '.$element['type'].'!');
}
$smarty->assign("$tag", $htmlCode);
}
......
......@@ -87,7 +87,7 @@ class Action
);
}
switch ($targets) {
switch ($this->targets) {
case '0':
$this->minTargets = 0;
$this->maxTargets = 0;
......@@ -109,7 +109,7 @@ class Action
$this->maxTargets = FALSE;
break;
default:
throw new Exception('Invalid targets value for action '.$name.': '.$targets);
throw new FusionDirectoryException('Invalid targets value for action '.$this->name.': '.$this->targets);
}
}
......@@ -149,10 +149,10 @@ class Action
return;
}
if (count($action['targets']) < $this->minTargets) {
throw new Exception('Not enough targets ('.count($action['targets']).') passed for action '.$name);
throw new FusionDirectoryException('Not enough targets ('.count($action['targets']).') passed for action '.$this->name);
}
if (($this->maxTargets !== FALSE) && (count($action['targets']) > $this->maxTargets)) {
throw new Exception('Too many targets ('.count($action['targets']).') passed for action '.$name);
throw new FusionDirectoryException('Too many targets ('.count($action['targets']).') passed for action '.$this->name);
}
$func = $this->callable;
if (!is_array($func)) {
......
......@@ -40,7 +40,7 @@ class FilterElement
}
/* Fills LDAP filters for the given type. Returns TRUE if type should be skipped altogether. */
public function getFilters($type, &$filters)
public function getFilters($type, array &$filters)
{
return FALSE;
}
......@@ -106,9 +106,9 @@ class TabFilterElement extends FilterElement
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters($type, &$filters)
public function getFilters($type, array &$filters)
{
foreach ($this->tabs as $class => $tab) {
foreach ($this->tabs as $tab) {
if ($tab['checked']) {
$filters[] = $tab['filter'];
}
......
......@@ -90,7 +90,6 @@ class ManagementConfigurationDialog extends simplePlugin
$columnInfos = $this->parent->getColumnConfiguration();
$value = array();
foreach ($columnInfos as $column) {
$data = $column;
if (!isset($column[1]['attribute'])) {
$column[1]['attribute'] = '';
}
......
......@@ -137,23 +137,23 @@ class management
foreach ($this->objectTypes as $type) {
$infos = objects::infos($type);
$icon = 'geticon.php?context=actions&icon=document-new&size=16';
$img = 'geticon.php?context=actions&icon=document-new&size=16';
if (isset($infos['icon'])) {
$icon = $infos['icon'];
$img = $infos['icon'];
}
$createMenu[] = new Action(
'new_'.$type, $infos['name'], $icon,
'new_'.$type, $infos['name'], $img,
'0', 'newEntry',
array($infos['aclCategory'].'/'.$infos['mainTab'].'/c')
);
if (!static::$skipTemplates) {
$templateMenu[] = new Action(
'new_template_'.$type, $infos['name'], $icon,
'new_template_'.$type, $infos['name'], $img,
'0', 'newEntryTemplate',
array($infos['aclCategory'].'/template/c')
);
$fromTemplateMenu[] = new Action(
'template_apply_'.$type, $infos['name'], $icon,
'template_apply_'.$type, $infos['name'], $img,
'?', 'newEntryFromTemplate',
array($infos['aclCategory'].'/template/r', $infos['aclCategory'].'/'.$infos['mainTab'].'/c')
);
......@@ -304,7 +304,7 @@ class management
function detectPostActions()
{
if (!is_object($this->listing)) {
throw new Exception('No valid listing object');
throw new FusionDirectoryException('No valid listing object');
}
$action = array('targets' => array(), 'action' => '', 'subaction' => NULL);
if ($this->is_modal_dialog()) {
......@@ -423,18 +423,18 @@ class management
global $config;
// Rendering things using smarty themselves first
$list = $this->listing->render();
$filter = $this->filter->render();
$actions = $this->renderActionMenu();
$listRender = $this->listing->render();
$filterRender = $this->filter->render();
$actionMenu = $this->renderActionMenu();
$smarty = get_smarty();
$smarty->assign('usePrototype', 'true');
$smarty->assign('FILTER', $filter);
$smarty->assign('LIST', $list);
$smarty->assign('LIST', $listRender);
$smarty->assign('FILTER', $filterRender);
$smarty->assign('ACTIONS', $actionMenu);
$smarty->assign('SIZELIMIT', print_sizelimit_warning());
$smarty->assign('MULTISELECT', $this->listing->multiSelect);
$smarty->assign('NAVIGATION', $this->listing->renderNavigation());
$smarty->assign('ACTIONS', $actions);
$smarty->assign('BASE', $this->listing->renderBase());
$smarty->assign('HEADLINE', $this->headline);
......@@ -563,7 +563,6 @@ class management
$str .= '<p class="plugbottom">'."\n".
'<input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'">'."\n".
'</p>';
return $str;
} else {
// Display ok, (apply) and cancel buttons
$str .= '<p class="plugbottom">'."\n";
......@@ -733,7 +732,7 @@ class management
$this->openTabObject(objects::open($this->dn, $entry->getTemplatedType()), $this->dn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Edit entry initiated');
if (isset($action['subaction'])) {
if ($this->handleSubAction($action) == FALSE) {
if ($this->handleSubAction($action) === FALSE) {
  • Merge this if statement with the enclosing one. 📘

Please register or sign in to reply
trigger_error('Was not able to handle subaction: '.$action['subaction']);
}
}
......
......@@ -267,8 +267,8 @@ class managementListing
if ($action == 'ROOT') {
$this->setBase(key($this->bases));
} elseif ($action == 'BACK') {
$base = preg_replace('/^[^,]+,/', '', $this->base);
$this->tryAndSetBase($base);
$parentBase = preg_replace('/^[^,]+,/', '', $this->base);
$this->tryAndSetBase($parentBase);
} elseif ($action == 'HOME') {
$this->tryAndSetBase(get_base_from_people($ui->dn));
}
......@@ -327,7 +327,6 @@ class managementListing
function renderNavigation()
{
$result = array();
$enableBack = TRUE;
$enableRoot = TRUE;
$enableHome = TRUE;
......@@ -429,10 +428,9 @@ class managementListing
/* Detect the longer base valid for this dn */
$longerBase = '';
foreach (array_keys($this->bases) as $base) {
if (preg_match('/'.preg_quote($base, '/').'$/i', $dn)) {
if (strlen($base) > strlen($longerBase)) {
$longerBase = $base;
}
if (preg_match('/'.preg_quote($base, '/').'$/i', $dn)
&& (strlen($base) > strlen($longerBase))) {
$longerBase = $base;
}
}
$this->setBase($longerBase);
......
......@@ -164,7 +164,7 @@ class Attribute
$this->checkValue($value);
$old_value = $this->value;
$this->value = $value;
if (($this->submitForm != FALSE) && ($this->submitForm !== TRUE) && ($old_value != $value) && is_object($this->plugin)) {
if (($this->submitForm !== FALSE) && ($this->submitForm !== TRUE) && ($old_value != $value) && is_object($this->plugin)) {
$func = $this->submitForm;
$this->plugin->$func();
}
......
  • SonarQube analysis reported 1 issue

    • 1 major

    Watch the comments in this conversation to review them.

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment