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

Merge branch '5956-use-strict-typing' into '1.4-dev'

Resolve "Use strict typing" (Attribute and management)

See merge request fusiondirectory/fd!562
parents e99b7404 18ac0152
......@@ -134,7 +134,7 @@ class SnapshotsAttribute extends OrderedArrayAttribute
$this->setInLdap(FALSE);
}
function setParent (&$plugin)
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
if (is_object($this->plugin)) {
......
......@@ -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)
{
}
......
......@@ -51,7 +51,7 @@ class BaseSelectorAttribute extends Attribute
trigger_error('method setManagedAttributes is not supported for BaseSelectorAttribute');
}
function setParent (&$plugin)
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
if (is_object($this->plugin)) {
......@@ -147,7 +147,7 @@ class BaseSelectorAttribute extends Attribute
return $this->value;
}
function renderFormInput ()
function renderFormInput (): string
{
$smarty = get_smarty();
$smarty->assign('usePrototype', 'true');
......@@ -164,7 +164,7 @@ class BaseSelectorAttribute extends Attribute
return $this->renderAcl($display);
}
function getHtmlId ()
function getHtmlId (): string
{
if (isset($this->baseSelector)) {
return $this->baseSelector->getInputHtmlId();
......@@ -173,7 +173,7 @@ class BaseSelectorAttribute extends Attribute
}
}
function serializeAttribute (array &$attributes, $form = TRUE)
function serializeAttribute (array &$attributes, bool $form = TRUE)
{
if (!$form || $this->visible) {
parent::serializeAttribute($attributes, $form);
......
......@@ -90,7 +90,7 @@ class BooleanAttribute extends Attribute
}
}
function displayValue ($value)
function displayValue ($value): string
{
if ($this->isTemplate() && $this->isTemplatable() && ($value === '%askme%')) {
return $value;
......@@ -99,7 +99,7 @@ class BooleanAttribute extends Attribute
}
}
function renderFormInput ()
function renderFormInput (): string
{
$id = $this->getHtmlId();
$attributes = ($this->value ? ['checked' => 'checked'] : []);
......@@ -114,7 +114,7 @@ class BooleanAttribute extends Attribute
return $this->renderAcl($display);
}
function renderTemplateInput ()
function renderTemplateInput (): string
{
if ($this->isTemplatable()) {
$id = $this->getHtmlId();
......@@ -138,7 +138,7 @@ class BooleanAttribute extends Attribute
}
}
protected function managedAttributesJS ()
protected function managedAttributesJS (): string
{
$js = '';
$id = $this->getHtmlId();
......
......@@ -40,14 +40,14 @@ class CompositeAttribute extends Attribute
* \param string $readFormat the preg_match format that's gonna be used in order to read values from LDAP
* \param string $writeFormat the printf format that's gonna be used in order to write values into LDAP
* \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do)
* \param string $label The label to show for this attribute. Only useful if you put this attribute inside a SetAttribute, or if you use a specific template that needs it.
* \param ?string $label The label to show for this attribute. Only useful if you put this attribute inside a SetAttribute, or if you use a specific template that needs it.
*/
function __construct ($description, $ldapName, array $attributes, $readFormat, $writeFormat, $acl = "", $label = NULL)
function __construct (string $description, string $ldapName, array $attributes, $readFormat, $writeFormat, string $acl = '', string $label = NULL)
{
if ($label === NULL) {
$label = $ldapName;
}
parent::__construct($label, $description, $ldapName, FALSE, "", $acl);
parent::__construct($label, $description, $ldapName, FALSE, '', $acl);
$this->readFormat = $readFormat;
$this->writeFormat = $writeFormat;
$this->setAttributes($attributes);
......@@ -62,7 +62,7 @@ class CompositeAttribute extends Attribute
unset($attribute);
}
function setIsSubAttribute ($bool)
function setIsSubAttribute (bool $bool)
{
parent::setIsSubAttribute($bool);
foreach ($this->attributes as &$attribute) {
......@@ -71,7 +71,7 @@ class CompositeAttribute extends Attribute
unset($attribute);
}
function setAcl ($acl)
function setAcl (string $acl)
{
parent::setAcl($acl);
foreach ($this->attributes as &$attribute) {
......@@ -80,7 +80,7 @@ class CompositeAttribute extends Attribute
unset($attribute);
}
function setParent (&$plugin)
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
foreach ($this->attributes as &$attribute) {
......@@ -94,12 +94,12 @@ class CompositeAttribute extends Attribute
trigger_error('method setManagedAttributes is not supported for CompositeAttribute');
}
function setLinearRendering ($bool)
function setLinearRendering (bool $bool)
{
$this->linearRendering = $bool;
}
function readValues ($value)
function readValues (string $value): array
{
$res = preg_match($this->readFormat, $value, $m);
if ($res === 1) {
......@@ -195,7 +195,7 @@ class CompositeAttribute extends Attribute
return $this->writeValues($values);
}
function getArrayValue ()
function getArrayValue (): array
{
return array_map(
function ($a)
......@@ -221,7 +221,7 @@ class CompositeAttribute extends Attribute
unset($attribute);
}
function renderAttribute (array &$attributes, $readOnly)
function renderAttribute (array &$attributes, bool $readOnly)
{
if ($this->visible) {
if ($this->linearRendering) {
......@@ -236,7 +236,7 @@ class CompositeAttribute extends Attribute
}
}
function getForHtmlId ()
function getForHtmlId (): string
{
// Label (if any) should point to the first attribute