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

feat(management) More strict typing in management classes

issue #5956
parent e99b7404
......@@ -314,7 +314,7 @@ class userinfo
*
* \return boolean TRUE if the given object is copyable else FALSE
*/
function is_copyable ($dn, $object)
function is_copyable ($dn, $object): bool
{
return (strpos($this->get_complete_category_acls($dn, $object), 'r') !== FALSE);
}
......@@ -331,7 +331,7 @@ class userinfo
*
* \return boolean TRUE if the given object is cutable else FALSE
*/
function is_cutable ($dn, $object, $class)
function is_cutable ($dn, $object, $class): bool
{
$remove = (strpos($this->get_permissions($dn, $object.'/'.$class), 'd') !== FALSE);
$read = (strpos($this->get_complete_category_acls($dn, $object), 'r') !== FALSE);
......@@ -348,7 +348,7 @@ class userinfo
*
* \return Boolean TRUE if we are allowed to paste an object.
*/
function is_pasteable ($dn, $object)
function is_pasteable ($dn, $object): bool
{
return (strpos($this->get_complete_category_acls($dn, $object), 'w') !== FALSE);
}
......@@ -365,7 +365,7 @@ class userinfo
*
* \return boolean TRUE if we are allowed to restore a snapshot.
*/
function allow_snapshot_restore ($dn, $categories, $deleted)
function allow_snapshot_restore ($dn, $categories, $deleted): bool
{
$permissions = $this->get_snapshot_permissions($dn, $categories);
return in_array(($deleted ? 'restore_deleted' : 'restore_over'), $permissions);
......@@ -381,7 +381,7 @@ class userinfo
*
* \return boolean TRUE if we are allowed to create a snapshot.
*/
function allow_snapshot_create ($dn, $categories)
function allow_snapshot_create ($dn, $categories): bool
{
$permissions = $this->get_snapshot_permissions($dn, $categories);
return in_array('c', $permissions);
......@@ -397,7 +397,7 @@ class userinfo
*
* \return boolean TRUE if we are allowed to delete a snapshot.
*/
function allow_snapshot_delete ($dn, $categories)
function allow_snapshot_delete ($dn, $categories): bool
{
$permissions = $this->get_snapshot_permissions($dn, $categories);
return in_array('d', $permissions);
......
......@@ -152,7 +152,7 @@ class Action
return [$this->name];
}
function execute ($management, $action)
function execute (management $management, array $action)
{
if ($this->callable === FALSE) {
return;
......@@ -170,7 +170,7 @@ class Action
return call_user_func($func, $action);
}
function fillMenuItems (&$actions)
function fillMenuItems (array &$actions)
{
if (!$this->inmenu) {
return;
......@@ -189,7 +189,7 @@ class Action
];
}
function fillRowClasses (&$classes, ListingEntry $entry)
function fillRowClasses (array &$classes, ListingEntry $entry)
{
}
......@@ -226,7 +226,7 @@ class Action
return TRUE;
}
function hasPermission ($dn, $type = NULL, bool $template = FALSE): bool
function hasPermission (string $dn, string $type = NULL, bool $template = FALSE): bool
{
global $ui;
......
......@@ -62,7 +62,7 @@ class SubMenuAction extends Action
return array_keys($this->handlers);
}
function execute ($management, $action)
function execute (management $management, array $action)
{
if (isset($action['subaction']) && isset($this->handlers[$action['action'].'_'.$action['subaction']])) {
return $this->handlers[$action['action'].'_'.$action['subaction']]->execute($management, $action);
......@@ -71,7 +71,7 @@ class SubMenuAction extends Action
}
}
function fillMenuItems (&$actions)
function fillMenuItems (array &$actions)
{
if (!$this->inmenu) {
return;
......
<?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
......@@ -29,7 +30,7 @@ class DateFilterElement extends FilterElement
protected $max;
protected $types;
public function __construct (managementFilter $parent, $attribute, $label, $types = [])
public function __construct (managementFilter $parent, string $attribute, string $label, array $types = [])
{
global $config;
......@@ -54,7 +55,7 @@ class DateFilterElement extends FilterElement
}
}
public function render ()
public function render (): string
{
$smarty = get_smarty();
$smarty->assign('NAME', $this->label);
......@@ -64,7 +65,7 @@ class DateFilterElement extends FilterElement
return $smarty->fetch(get_template_path('management/filter-element-date.tpl'));
}
public function getFilters ($type, array &$filters)
public function getFilters (string $type, array &$filters): bool
{
if (!empty($this->types) && !in_array_ics($type, $this->types)) {
return FALSE;
......
......@@ -36,12 +36,13 @@ class FilterElement
{
}
public function render ()
public function render (): string
{
return '';
}
/* Fills LDAP filters for the given type. Returns TRUE if type should be skipped altogether. */
public function getFilters ($type, array &$filters)
public function getFilters (string $type, array &$filters): bool
{
return FALSE;
}
......
<?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
......@@ -29,7 +30,7 @@ class ListingEntry implements ArrayAccess
/* Cache where columns may store stuff */
public $cache = [];
public function __construct (managementListing $listing, $type, $dn, array $attrs, $row = NULL)
public function __construct (managementListing $listing, string $type, string $dn, array $attrs, int $row = NULL)
{
$this->listing = $listing;
$this->type = $type;
......@@ -58,27 +59,27 @@ class ListingEntry implements ArrayAccess
return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
}
public function getPid ()
public function getPid (): string
{
return $this->listing->pid;
}
public function isTemplate ()
public function isTemplate (): bool
{
return preg_match('/^template_/', $this->type);
}
public function getTemplatedType ()
public function getTemplatedType (): string
{
return preg_replace('/^template_/', '', $this->type);
}
public function getTemplatedFields ()
public function getTemplatedFields (): array
{
return templateHandling::fieldsFromLDAP($this->attrs);
}
public function checkAcl ($acls)
public function checkAcl (string $acls): bool
{
global $ui;
......@@ -93,7 +94,7 @@ class ListingEntry implements ArrayAccess
return TRUE;
}
public function snapshotCreationAllowed ()
public function snapshotCreationAllowed (): bool
{
global $ui;
......@@ -101,7 +102,7 @@ class ListingEntry implements ArrayAccess
return $ui->allow_snapshot_create($this->dn, $infos['aclCategory']);
}
public function snapshotRestoreAllowed ()
public function snapshotRestoreAllowed (): bool
{
global $ui;
......
......@@ -62,7 +62,7 @@ class TabFilterElement extends FilterElement
unset($tab);
}
public function render ()
public function render (): string
{
if (empty($this->tabs)) {
return '';
......@@ -82,7 +82,7 @@ class TabFilterElement extends FilterElement
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters ($type, array &$filters)
public function getFilters (string $type, array &$filters): bool
{
foreach ($this->tabs as $tab) {
if ($tab['checked']) {
......
......@@ -436,7 +436,7 @@ class management
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action, 'Action');
try {
$str = $this->handleAction($action);
if ($str) {
if (!empty($str)) {
return $this->getHeader().$str;
}
} catch (FusionDirectoryException $e) {
......
......@@ -47,7 +47,7 @@ class managementFilter
*
* \param string $parent management instance
*/
function __construct ($parent)
function __construct (management $parent)
{
global $config;
......@@ -68,7 +68,7 @@ class managementFilter
];
}
function setScope ($scope)
function setScope (string $scope)
{
$this->scope = $scope;
}
......@@ -78,7 +78,7 @@ class managementFilter
$this->filterElements[] = $element;
}
function update ($base)
function update (string $base)
{
global $ui;
......@@ -117,7 +117,7 @@ class managementFilter
/*!
* \brief Render
*/
function render ()
function render (): string
{
$smarty = get_smarty();
......@@ -152,7 +152,7 @@ class managementFilter
return $smarty->fetch($file);
}
function query (array $attrs, $base)
function query (array $attrs, string $base): array
{
global $ui;
......
......@@ -57,7 +57,7 @@ class managementListing
*
* \param string $parent management instance
*/
function __construct ($parent, $baseMode = TRUE, $multiSelect = TRUE)
function __construct (management $parent, bool $baseMode = TRUE, bool $multiSelect = TRUE)
{
global $config, $ui;
......@@ -85,11 +85,16 @@ class managementListing
$this->reloadColumns();
}
function getBaseMode ()
function getBaseMode (): bool
{
return $this->baseMode;
}
function getMultiSelect (): bool
{
return $this->multiSelect;
}
function reloadColumns ()
{
$columnInfos = $this->parent->getColumnConfiguration();
......@@ -102,7 +107,7 @@ class managementListing
$this->columns[1]->setTemplateAttributes(['cn']);
}
function getColumns ()
function getColumns (): array
{
return $this->columns;
}
......@@ -139,7 +144,7 @@ class managementListing
/*!
* \brief Render
*/
function render ()
function render (): string
{
global $ui;
......@@ -209,7 +214,7 @@ class managementListing
return $smarty->fetch(get_template_path('management/list.tpl'));
}
function getIterator ()
function getIterator (): Iterator
{
return new EntrySortIterator($this->entries, $this->columns[$this->sortColumn], $this->sortDirection[$this->sortColumn]);
}
......@@ -281,7 +286,7 @@ class managementListing
/*!
* \brief Update a listing
*/
function update ($dn = NULL)
function update (string $dn = NULL)
{
if ($dn === NULL) {
$this->updateBase();
......@@ -333,21 +338,21 @@ class managementListing
*
* \return the base
*/
function getBase ()
function getBase (): string
{
return $this->base;
}
function renderBase ()
function renderBase (): string
{
if (!$this->baseMode) {
return;
return '';
}
return $this->baseSelector->render();
}
function renderNavigation ()
function renderNavigation (): array
{
$enableBack = TRUE;
$enableRoot = TRUE;
......@@ -552,7 +557,7 @@ class managementListing
*
* \param string $dn The DN
*/
function getEntry ($dn)
function getEntry (string $dn)
{
if (isset($this->entries[$dn])) {
return $this->entries[$dn];
......@@ -560,12 +565,7 @@ class managementListing
return NULL;
}
function getMultiSelect ()
{
return $this->multiSelect;
}
function fillSearchedAttributes ($type, array &$attrs)
function fillSearchedAttributes (string $type, array &$attrs)
{
global $ui;
......
......@@ -37,7 +37,7 @@ class selectManagement extends management
['LinkColumn', ['attributes' => 'description', 'label' => 'Description']],
];
function __construct ($objectTypes = FALSE, $multiSelect = TRUE, $neededAttrs = [])
function __construct ($objectTypes = FALSE, bool $multiSelect = TRUE, array $neededAttrs = [])
{
$this->neededAttrs = $neededAttrs;
$this->multiSelect = $multiSelect;
......
......@@ -28,7 +28,7 @@ class ActionsColumn extends Column
return FALSE;
}
function fillRowClasses (&$classes, ListingEntry $entry)
function fillRowClasses (array &$classes, ListingEntry $entry)
{
$this->parent->parent->fillActionRowClasses($classes, $entry);
}
......
......@@ -39,10 +39,11 @@ class Column
/*!
* \brief Builds a column object from given data
*
* \param managementListing $parent the managementListing instance
* \param string $type a column class
* \param array $data an associative array with "attributes" and "label"
* */
static function build (managementListing $parent, $type, array $data): Column
static function build (managementListing $parent, string $type, array $data): Column
{
$attributes = NULL;
$label = NULL;
......@@ -138,7 +139,7 @@ class Column
}
}
function fillRowClasses (&$classes, ListingEntry $entry)
function fillRowClasses (array &$classes, ListingEntry $entry)
{
}
......
......@@ -54,7 +54,7 @@ class GroupContentFilterElement extends FilterElement
unset($infos);
}
public function render ()
public function render (): string
{
$inputs = [];
foreach ($this->types as $type => $infos) {
......@@ -71,7 +71,7 @@ class GroupContentFilterElement extends FilterElement
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters ($type, array &$filters)
public function getFilters (string $type, array &$filters): bool
{
if (strtoupper($type) == 'OGROUP') {
foreach ($this->types as $type => $infos) {
......
......@@ -20,7 +20,7 @@
class LockAction extends Action
{
function __construct (string $name, string $targets, $callable, array $acl = [], $inmenu = TRUE, $inline = TRUE)
function __construct (string $name, string $targets, $callable, array $acl = [], bool $inmenu = TRUE, bool $inline = TRUE)
{
parent::__construct(
$name,
......@@ -43,7 +43,7 @@ class LockAction extends Action
return NULL;
}
function fillMenuItems (&$actions)
function fillMenuItems (array &$actions)
{
if (!$this->inmenu) {
return;
......@@ -70,7 +70,7 @@ class LockAction extends Action
];
}
function fillRowClasses (&$classes, ListingEntry $entry)
function fillRowClasses (array &$classes, ListingEntry $entry)
{
if ($this->isLocked($entry) === TRUE) {
$classes[] = 'entry-locked';
......
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