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

🚜 feat(management) Add strict typing to management functions

issue #5956
parent be957d07
......@@ -49,7 +49,7 @@ class Action
protected $parent;
function __construct ($name, $label, $icon, $targets, $callable, array $acls = array(), $inmenu = TRUE, $inline = TRUE, array $validTypes = array())
function __construct (string $name, $label, $icon, string $targets, $callable, array $acls = array(), bool $inmenu = TRUE, bool $inline = TRUE, array $validTypes = array())
{
if ($targets == '0') {
$inline = FALSE;
......@@ -122,7 +122,7 @@ class Action
$this->parent = $parent;
}
function getName ()
function getName (): string
{
return $this->name;
}
......@@ -132,7 +132,7 @@ class Action
return $this->label;
}
function setSeparator ($bool)
function setSeparator (bool $bool)
{
$this->separator = $bool;
}
......@@ -142,12 +142,12 @@ class Action
$this->enabledCallable = $callable;
}
function setInMenu ($inmenu)
function setInMenu (bool $inmenu)
{
$this->inmenu = $inmenu;
}
function listActions ()
function listActions (): array
{
return array($this->name);
}
......@@ -193,7 +193,7 @@ class Action
{
}
function renderColumnIcons (ListingEntry $entry)
function renderColumnIcons (ListingEntry $entry): string
{
if (!$this->inline) {
return '';
......@@ -218,7 +218,7 @@ class Action
' title="'.$this->label.'" alt="'.$this->label.'" name="listing_'.$this->name.'_'.$entry->row.'"/>';
}
function isEnabledFor (ListingEntry $entry = NULL)
function isEnabledFor (ListingEntry $entry = NULL): bool
{
if (isset($this->enabledCallable)) {
return call_user_func($this->enabledCallable, $this->name, $entry);
......@@ -226,7 +226,7 @@ class Action
return TRUE;
}
function hasPermission ($dn, $type = NULL, $template = FALSE)
function hasPermission ($dn, $type = NULL, bool $template = FALSE): bool
{
global $ui;
......
......@@ -23,7 +23,7 @@
*/
class HiddenAction extends Action
{
function __construct ($name, $callable, array $acl = array())
function __construct (string $name, $callable, array $acl = array())
{
parent::__construct($name, '', '', '0', $callable, $acl, FALSE, FALSE);
}
......
......@@ -26,7 +26,7 @@ class SubMenuAction extends Action
protected $actions = array();
protected $handlers = array();
function __construct ($name, $label, $icon, array $actions, $inmenu = TRUE)
function __construct (string $name, $label, $icon, array $actions, bool $inmenu = TRUE)
{
parent::__construct($name, $label, $icon, '0', FALSE, array(), $inmenu, FALSE);
$this->actions = $actions;
......@@ -57,7 +57,7 @@ class SubMenuAction extends Action
}
}
function listActions ()
function listActions (): array
{
return array_keys($this->handlers);
}
......@@ -93,7 +93,8 @@ class SubMenuAction extends Action
}
}
function renderColumnIcons (ListingEntry $entry)
function renderColumnIcons (ListingEntry $entry): string
{
return '';
}
}
......@@ -332,7 +332,7 @@ class management
}
}
public function getColumnConfiguration ()
public function getColumnConfiguration (): array
{
global $config;
......@@ -360,7 +360,7 @@ class management
* \brief Detects actions/events send by the ui
* and the corresponding targets.
*/
function detectPostActions ()
function detectPostActions (): array
{
if (!is_object($this->listing)) {
throw new FusionDirectoryException('No valid listing object');
......@@ -400,7 +400,7 @@ class management
}
}
protected function handleSubAction (array $action)
protected function handleSubAction (array $action): bool
{
if (preg_match('/^tab_/', $action['subaction'])) {
$tab = preg_replace('/^tab_/', '', $action['subaction']);
......@@ -476,7 +476,7 @@ class management
return $this->renderList();
}
function renderList ()
function renderList (): string
{
global $config, $ui;
......@@ -498,12 +498,12 @@ class management
return $this->getHeader().$smarty->fetch(get_template_path('management/management.tpl'));
}
protected function renderFilter ()
protected function renderFilter (): string
{
return $this->filter->render();
}
protected function renderActionMenu ()
protected function renderActionMenu (): string
{
$menuActions = array();
foreach ($this->actions as $action) {
......@@ -520,7 +520,7 @@ class management
return $smarty->fetch(get_template_path('management/actionmenu.tpl'));
}
function renderActionColumn (ListingEntry $entry)
function renderActionColumn (ListingEntry $entry): string
{
// Go thru all actions
$result = '';
......@@ -554,7 +554,7 @@ class management
}
}
function is_modal_dialog ()
function is_modal_dialog (): bool
{
return (is_object($this->tabObject) || is_object($this->dialogObject));
}
......@@ -562,7 +562,7 @@ class management
/*!
* \brief Generates the plugin header which is displayed whenever a tab object is opened.
*/
protected function getHeader ()
protected function getHeader (): string
{
if ($this->skipHeader) {
return '';
......@@ -597,7 +597,7 @@ class management
set_object_info();
}
protected function listAclCategories ()
protected function listAclCategories (): array
{
$cat = array();
foreach ($this->objectTypes as $type) {
......@@ -610,7 +610,7 @@ class management
/*!
* \brief Generates the footer which is used whenever a tab object is displayed.
*/
protected function _getTabFooter ()
protected function _getTabFooter (): string
{
// Do not display tab footer for non tab objects
if (!($this->tabObject instanceOf simpleTabs)) {
......@@ -658,7 +658,7 @@ class management
}
}
function enablePaste ($action, ListingEntry $entry = NULL)
function enablePaste ($action, ListingEntry $entry = NULL): bool
{
if ($entry === NULL) {
return $this->cpHandler->entries_queued();
......@@ -1109,7 +1109,7 @@ class management
/* Methods related to Snapshots */
function getSnapshotBases ()
function getSnapshotBases (): array
{
$bases = array();
foreach ($this->objectTypes as $type) {
......@@ -1128,7 +1128,7 @@ class management
/*!
* \brief Get all deleted snapshots
*/
function getAllDeletedSnapshots ()
function getAllDeletedSnapshots (): array
{
$bases = $this->getSnapshotBases();
$tmp = array();
......@@ -1143,7 +1143,7 @@ class management
*
* \param string $dn The DN
*/
function getAvailableSnapsShots ($dn)
function getAvailableSnapsShots (string $dn): array
{
return $this->snapHandler->getAvailableSnapsShots($dn);
}
......@@ -1151,7 +1151,7 @@ class management
/*
* \brief Whether snapshot restore action should be enabled for an entry
*/
function enableSnapshotRestore ($action, ListingEntry $entry = NULL)
function enableSnapshotRestore ($action, ListingEntry $entry = NULL): bool
{
if ($entry !== NULL) {
/* For entries */
......@@ -1165,7 +1165,7 @@ class management
/*!
* \brief Creates a new snapshot entry
*/
function createSnapshot ($dn, $description)
function createSnapshot (string $dn, string $description)
{
global $ui;
if ($this->currentDn !== $dn) {
......@@ -1186,7 +1186,7 @@ class management
*
* \param String $dn The DN of the snapshot
*/
function restoreSnapshot ($dn)
function restoreSnapshot (string $dn)
{
global $ui;
if (!empty($dn) && $ui->allow_snapshot_restore($dn, $this->dialogObject->aclCategory, $this->dialogObject->global)) {
......@@ -1204,7 +1204,7 @@ class management
*
* \param string $dn DN of the snapshot
*/
function removeSnapshot ($dn)
function removeSnapshot (string $dn)
{
global $ui;
if (!empty($dn) && $ui->allow_snapshot_delete($dn, $this->dialogObject->aclCategory)) {
......@@ -1249,6 +1249,4 @@ class management
session::set($classname, $managementObject);
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
Copyright (C) 2017-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -58,7 +59,7 @@ class selectManagement extends management
$this->registerAction(new HiddenAction('configure', 'configureDialog'));
}
function renderList ()
function renderList (): string
{
$list = parent::renderList();
......
......@@ -23,7 +23,7 @@
*/
class ActionsColumn extends Column
{
function isSortable ()
function isSortable (): bool
{
return FALSE;
}
......@@ -33,7 +33,7 @@ class ActionsColumn extends Column
$this->parent->parent->fillActionRowClasses($classes, $entry);
}
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
return $this->parent->parent->renderActionColumn($entry);
}
......
......@@ -43,7 +43,7 @@ class Column
* \param string $type a column class
* \param array $data an associative array with "attributes" and "label"
* */
static function build (managementListing $parent, $type, array $data)
static function build (managementListing $parent, $type, array $data): Column
{
$attributes = NULL;
$label = NULL;
......@@ -60,14 +60,14 @@ class Column
return new $type($parent, $attributes, $label);
}
function __construct (managementListing $parent, array $attributes = NULL, $label = NULL)
function __construct (managementListing $parent, array $attributes = NULL, string $label = NULL)
{
$this->parent = $parent;
$this->parent = $parent;
$this->label = $label;
$this->setAttributesVar('attributes', $attributes);
$this->label = $label;
}
protected function setAttributesVar ($var, array $attributes = NULL)
protected function setAttributesVar (string $var, array $attributes = NULL)
{
if (is_array($attributes) && is_numeric(key($attributes))) {
$val = array();
......@@ -89,27 +89,27 @@ class Column
$this->setAttributesVar('templateAttributes', $attributes);
}
function isSortable ()
function isSortable (): bool
{
return TRUE;
}
function isExportable ()
function isExportable (): bool
{
return !empty($this->attributes);
}
function getHtmlProps ()
function getHtmlProps (): string
{
return '';
}
function getHtmlCellProps ()
function getHtmlCellProps (): string
{
return '';
}
function getLabel ()
function getLabel (): string
{
if (isset($this->label)) {
return _($this->label);
......@@ -170,7 +170,7 @@ class Column
return '';
}
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
$value = $this->getAttributeValue($entry);
if ($value == '') {
......@@ -194,7 +194,7 @@ class Column
return $this->getAttributeValue($entry);
}
function compare (ListingEntry $ao, ListingEntry $bo)
function compare (ListingEntry $ao, ListingEntry $bo): int
{
$a = $this->getAttributeValue($ao);
$b = $this->getAttributeValue($bo);
......
......@@ -26,7 +26,7 @@ class LdapGeneralizedTimeColumn extends LinkColumn
{
protected $type = 'string';
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
$value = $this->getAttributeValue($entry);
if ($value != '') {
......
......@@ -23,12 +23,12 @@
*/
class LinkColumn extends Column
{
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
return $this->renderLink($entry, parent::renderCell($entry));
}
protected function renderLink (ListingEntry $entry, $htmlValue)
protected function renderLink (ListingEntry $entry, $htmlValue): string
{
if ($this->parent->parent instanceof selectManagement) {
if ($this->parent->getMultiSelect()) {
......
......@@ -23,12 +23,12 @@
*/
class ObjectTypeColumn extends Column
{
function isSortable ()
function isSortable (): bool
{
return FALSE;
}
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
if ($entry->isTemplate()) {
$infos = objects::infos($entry->getTemplatedType());
......
......@@ -25,7 +25,7 @@ class PropertiesColumn extends Column
{
protected $tabs;
function __construct (managementListing $parent, array $attributes = NULL, $label = NULL)
function __construct (managementListing $parent, array $attributes = NULL, string $label = NULL)
{
global $config;
......@@ -56,7 +56,7 @@ class PropertiesColumn extends Column
}
}
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
$tabs = $this->computeIcons($entry);
$result = '';
......@@ -73,7 +73,7 @@ class PropertiesColumn extends Column
return $result;
}
function compare (ListingEntry $ao, ListingEntry $bo)
function compare (ListingEntry $ao, ListingEntry $bo): int
{
if ($ao->getTemplatedType() != $bo->getTemplatedType()) {
return strcmp($ao->getTemplatedType(), $bo->getTemplatedType());
......@@ -86,7 +86,7 @@ class PropertiesColumn extends Column
return strcmp($a, $b);
}
protected function computeSortString (ListingEntry $entry)
protected function computeSortString (ListingEntry $entry): string
{
if (isset($entry->cache[__CLASS__]['sort'])) {
return $entry->cache[__CLASS__]['sort'];
......@@ -99,12 +99,12 @@ class PropertiesColumn extends Column
return (empty($tab['icon']) ? 0 : 1);
},
$icons
));;
));
return $entry->cache[__CLASS__]['sort'];
}
protected function computeIcons (ListingEntry $entry)
protected function computeIcons (ListingEntry $entry): array
{
if (isset($entry->cache[__CLASS__]['icons'])) {
return $entry->cache[__CLASS__]['icons'];
......
......@@ -25,7 +25,7 @@ class UnixTimestampColumn extends LinkColumn
{
protected $type = 'integer';
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
$value = $this->getAttributeValue($entry);
if ($value != '') {
......
......@@ -203,10 +203,9 @@ class aclManagement extends management
return $smarty->fetch(get_template_path('remove.tpl', TRUE, dirname(__FILE__)));
}
protected function renderFilter ()
protected function renderFilter (): string
{
/* Hide filter box */
return '';
}
}
?>
......@@ -20,7 +20,7 @@
class aclRoleManagement extends management
{
public static function plInfo ()
public static function plInfo (): array
{
return array(
'plShortName' => _('ACL roles'),
......@@ -36,4 +36,3 @@ class aclRoleManagement extends management
);
}
}
?>
......@@ -73,9 +73,8 @@ class departmentManagement extends management
$this->refreshDeps();
}
static function getDepartmentTypes ()
static function getDepartmentTypes (): array
{
return array('DEPARTMENT','COUNTRY','DCOBJECT','DOMAIN','LOCALITY','ORGANIZATION');
}
}
?>
......@@ -23,7 +23,7 @@
*/
class GroupContentColumn extends Column
{
function renderCell (ListingEntry $entry)
function renderCell (ListingEntry $entry): string
{
global $config;
......
......@@ -34,7 +34,7 @@ class groupManagement extends management
protected $siActive = FALSE;
static function plInfo ()
static function plInfo (): array
{
return array(
'plShortName' => _('Groups and roles'),
......@@ -207,7 +207,7 @@ class groupManagement extends management
/*! \brief Detects actions/events send by the ui
* and the corresponding targets.
*/
function detectPostActions ()
function detectPostActions (): array
{
$action = parent::detectPostActions();
if (isset($_POST['save_event_dialog'])) {
......@@ -218,4 +218,3 @@ class groupManagement extends management
return $action;
}
}
?>
......@@ -20,7 +20,7 @@
class LockAction extends Action
{
function __construct ($name, $targets, $callable, array $acl = array(), $inmenu = TRUE, $inline = TRUE)
function __construct (string $name, string $targets, $callable, array $acl = array(), $inmenu = TRUE, $inline = TRUE)
{
parent::__construct(
$name,
......@@ -77,7 +77,7 @@ class LockAction extends Action
}
}
function renderColumnIcons (ListingEntry $entry)
function renderColumnIcons (ListingEntry $entry): string
{
if (!$this->inline) {
return '';
......
......@@ -34,7 +34,7 @@ class userManagement extends management
array('ActionsColumn', array('label' => 'Actions')),
);
static function plInfo ()
static function plInfo (): array
{
return array(
'plShortName' => _('Users'),
......
  • SonarQube analysis reported 2 issues

    • 2 major

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. This function "browseForeignKeys" has 244 lines, which is greater than the 150 lines authorized. Split it into smaller functions. 📘
    2. This function "getAttributesInfo" has 174 lines, which is greater than the 150 lines authorized. Split it into smaller functions. 📘
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