diff --git a/include/simpleplugin/attributes/class_DateAttribute.inc b/include/simpleplugin/attributes/class_DateAttribute.inc index 59820d400143877beb160a3dca7b3380a3875052..5c22704d5574c59bbdf04a7a51dd4d2d46b918b9 100755 --- a/include/simpleplugin/attributes/class_DateAttribute.inc +++ b/include/simpleplugin/attributes/class_DateAttribute.inc @@ -48,14 +48,14 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute if ($min !== NULL) { try { $this->minDate = new DateTime($min, new DateTimeZone('UTC')); - } catch (Exception $e) { + } catch (Exception) { // Failed to parse min date, ignore } } if ($max !== NULL) { try { $this->maxDate = new DateTime($max, new DateTimeZone('UTC')); - } catch (Exception $e) { + } catch (Exception) { // Failed to parse max date, ignore } } @@ -65,7 +65,7 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute { if ( ($value === '') || - ($this->isTemplate() && preg_match('/%/', $value)) + ($this->isTemplate() && preg_match('/%/', (string) $value)) ) { return $value; } else { @@ -80,7 +80,7 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute } else { try { return $this->getDateValue()->format('Y-m-d'); - } catch (Exception $e) { + } catch (Exception) { return $this->value; } } @@ -111,7 +111,7 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute /* Fallback to LdapGeneralizedTime to accept LDAP format */ try { $value = LdapGeneralizedTime::fromString($value); - } catch (LdapGeneralizedTimeBadFormatException $e2) { + } catch (LdapGeneralizedTimeBadFormatException) { throw $e; } } @@ -126,7 +126,7 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute } elseif (!($this->value instanceof DateTime)) { try { $this->setValue($this->getDateValue()); - } catch (Exception $e) { + } catch (Exception) { return $this->value; } } @@ -157,7 +157,7 @@ class DateAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute ); } } catch (Exception $e) { - if ($this->isTemplate() && preg_match('/%/', $this->value)) { + if ($this->isTemplate() && preg_match('/%/', (string) $this->value)) { return ''; } else { return new SimplePluginCheckError( @@ -216,7 +216,7 @@ class GeneralizedTimeDateAttribute extends DateAttribute { try { return LdapGeneralizedTime::fromString($ldapValue); - } catch (LdapGeneralizedTimeBadFormatException $e) { + } catch (LdapGeneralizedTimeBadFormatException) { return $ldapValue; } } diff --git a/include/simpleplugin/attributes/class_DisplayAttribute.inc b/include/simpleplugin/attributes/class_DisplayAttribute.inc index 5f6b514f9a7e1f9ac28dea6813ea5bd06d3e1a4a..66964c4569f8c18b303ce01ce28797b3c8cbe5b7 100755 --- a/include/simpleplugin/attributes/class_DisplayAttribute.inc +++ b/include/simpleplugin/attributes/class_DisplayAttribute.inc @@ -85,7 +85,7 @@ class DisplayLDAPArrayAttribute extends \FusionDirectory\Core\SimplePlugin\Attri { $value = $this->getValue(); if (is_array($value)) { - $value = join(', ', $value); + $value = implode(', ', $value); } return '{literal}'.htmlescape($value).'{/literal}'; } @@ -124,7 +124,7 @@ class ObjectLinkAttribute extends DisplayLDAPAttribute try { return objects::link($this->value, $this->type); - } catch (NonExistingLdapNodeException $e) { + } catch (NonExistingLdapNodeException) { return '<a><img src="geticon.php?context=status&icon=dialog-warning&size=16" alt="warning" class="center"/> '.sprintf(_('Invalid: %s'), $this->value).'</a>'; } } diff --git a/include/simpleplugin/attributes/class_FileAttribute.inc b/include/simpleplugin/attributes/class_FileAttribute.inc index 0a3ce86602fe4ce6694ad51676b7d408eb829bd4..5405c60937ef88216ed2bef1bbcd567ba1790c36 100755 --- a/include/simpleplugin/attributes/class_FileAttribute.inc +++ b/include/simpleplugin/attributes/class_FileAttribute.inc @@ -92,7 +92,7 @@ class FileAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute function displayValue ($value): string { - return sprintf(_('%s (%d bytes)'), $this->getLabel(), mb_strlen($value, '8bit')); + return sprintf(_('%s (%d bytes)'), $this->getLabel(), mb_strlen((string) $value, '8bit')); } /*! \brief Serialize this attribute for RPC requests @@ -121,7 +121,7 @@ class FileAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute $value = $this->getValue(); } if ($this->binary) { - return base64_encode($value); + return base64_encode((string) $value); } else { return $value; } @@ -140,7 +140,7 @@ class FileAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute ); } if ($this->binary) { - $data = base64_decode($value, TRUE); + $data = base64_decode((string) $value, TRUE); if ($data === FALSE) { return new SimplePluginError( $this, @@ -502,6 +502,6 @@ class ImageAttribute extends FileAttribute function inputValue ($value) { /* Remove %% that might be there in case of templating */ - return preg_replace('/^%%/', '', $value); + return preg_replace('/^%%/', '', (string) $value); } } diff --git a/include/simpleplugin/attributes/class_ObjectSelectAttribute.inc b/include/simpleplugin/attributes/class_ObjectSelectAttribute.inc index bbdd4f7873c7b42500a0e842ba6f4459cd874806..a34df309301200f9adcd1e2cbea4871eba9a6327 100755 --- a/include/simpleplugin/attributes/class_ObjectSelectAttribute.inc +++ b/include/simpleplugin/attributes/class_ObjectSelectAttribute.inc @@ -77,7 +77,7 @@ class ObjectSelectAttribute extends SelectAttribute foreach (array_column($objects, $realDisplayAttr) as $output) { $outputs[] = $output; } - } catch (NonExistingObjectTypeException $e) { + } catch (NonExistingObjectTypeException) { continue; } } diff --git a/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc b/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc index 7b790c35926ea8232b63573ba1093cc2d236f74d..e75bfd61b2ec8ca23aa1463f7876e91f85dfeaa3 100755 --- a/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc +++ b/include/simpleplugin/attributes/class_PhoneNumberAttribute.inc @@ -73,19 +73,12 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute public function getSelectManagementParameters (): array { - switch ($this->type) { - case 'phone': - $objectTypes = ['phone']; - break; - case 'mobile': - $objectTypes = ['mobilePhone']; - break; - case 'any': - $objectTypes = ['phone','mobilePhone']; - break; - default: - throw new FusionDirectoryException('Invalid type "'.$this->type.'" for PhoneNumberButtonAttribute'); - } + $objectTypes = match ($this->type) { + 'phone' => ['phone'], + 'mobile' => ['mobilePhone'], + 'any' => ['phone','mobilePhone'], + default => throw new FusionDirectoryException('Invalid type "'.$this->type.'" for PhoneNumberButtonAttribute'), + }; return [ $objectTypes, diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index cb0a7de621fe63857559541fd5791311682b0287..197177b4f0078dbb5aaf1dc3064ef4537a3ba787 100755 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -376,11 +376,11 @@ class SetAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute foreach ($this->value as $key => &$value) { if (($source['FIELD'] == 'dn') && ($source['MODE'] == 'move')) { if ($newvalue === NULL) { - if (preg_match('/'.preg_quote($oldvalue, '/').'$/', $value)) { + if (preg_match('/'.preg_quote((string) $oldvalue, '/').'$/', $value)) { unset($this->value[$key]); } } else { - $value = preg_replace('/'.preg_quote($oldvalue, '/').'$/', $newvalue, $value); + $value = preg_replace('/'.preg_quote((string) $oldvalue, '/').'$/', $newvalue, $value); } } elseif ($value == $oldvalue) { if ($newvalue === NULL) { @@ -444,7 +444,7 @@ class OrderedArrayAttribute extends SetAttribute function readValue ($value) { if ($this->order) { - return preg_split('/:/', $value, 2); + return preg_split('/:/', (string) $value, 2); } else { return $value; } @@ -632,8 +632,8 @@ class OrderedArrayAttribute extends SetAttribute protected function handlePostValueActions ($id, $postValue) { if ($this->order) { - if (preg_match('/^'.$id.'_up_/', $postValue)) { - $key = preg_replace('/^'.$id.'_up_/', '', $postValue); + if (preg_match('/^'.$id.'_up_/', (string) $postValue)) { + $key = preg_replace('/^'.$id.'_up_/', '', (string) $postValue); $key = (int)preg_replace('/_[xy]$/', '', $key); $tmp = $this->postValue[$key]; @@ -641,8 +641,8 @@ class OrderedArrayAttribute extends SetAttribute $this->postValue[$key - 1] = $tmp; return TRUE; } - if (preg_match('/^'.$id.'_down_/', $postValue)) { - $key = preg_replace('/^'.$id.'_down_/', '', $postValue); + if (preg_match('/^'.$id.'_down_/', (string) $postValue)) { + $key = preg_replace('/^'.$id.'_down_/', '', (string) $postValue); $key = (int)preg_replace('/_[xy]$/', '', $key); $tmp = $this->postValue[$key]; @@ -651,14 +651,14 @@ class OrderedArrayAttribute extends SetAttribute return TRUE; } } - if ($this->edit_enabled && preg_match('/^'.$id.'_edit_/', $postValue)) { - $key = preg_replace('/^'.$id.'_edit_/', '', $postValue); + if ($this->edit_enabled && preg_match('/^'.$id.'_edit_/', (string) $postValue)) { + $key = preg_replace('/^'.$id.'_edit_/', '', (string) $postValue); $key = preg_replace('/_[xy]$/', '', $key); $this->handleEdit($key); return TRUE; } - if (preg_match('/^'.$id.'_del_/', $postValue)) { - $key = preg_replace('/^'.$id.'_del_/', '', $postValue); + if (preg_match('/^'.$id.'_del_/', (string) $postValue)) { + $key = preg_replace('/^'.$id.'_del_/', '', (string) $postValue); $key = preg_replace('/_[xy]$/', '', $key); $this->delPostValue($key); return TRUE; diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc index ca3ab88bfa0a99d1a25db78a798d196151dc610a..69e55fa7a0921ba6b4b50e758cbc46da485dd101 100755 --- a/include/simpleplugin/attributes/class_StringAttribute.inc +++ b/include/simpleplugin/attributes/class_StringAttribute.inc @@ -61,7 +61,7 @@ class StringAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute function setPattern ($pattern) { $this->pattern = $pattern; - if (preg_match('/^(.)\^(.*)\$\1$/', $pattern, $m)) { + if (preg_match('/^(.)\^(.*)\$\1$/', (string) $pattern, $m)) { /* Only convert anchored patterns * First and last characters are the same means no modifiers are in use */ @@ -164,7 +164,7 @@ class StringAttribute extends \FusionDirectory\Core\SimplePlugin\Attribute function setValue ($value) { if ($this->trim) { - return parent::setValue(trim($value)); + return parent::setValue(trim((string) $value)); } else { return parent::setValue($value); } diff --git a/include/simpleplugin/attributes/dialog/class_GenericDialogAttribute.inc b/include/simpleplugin/attributes/dialog/class_GenericDialogAttribute.inc index f08945290f5d051ca527e97db4b42de551c60ef7..ca2983f01d196a3d1f487db2d88718dd756602a2 100755 --- a/include/simpleplugin/attributes/dialog/class_GenericDialogAttribute.inc +++ b/include/simpleplugin/attributes/dialog/class_GenericDialogAttribute.inc @@ -135,11 +135,11 @@ class GenericDialogAttribute extends DialogAttribute foreach ($this->value as $key => &$value) { if (($source['FIELD'] == 'dn') && ($source['MODE'] == 'move')) { if ($newvalue === NULL) { - if (preg_match('/'.preg_quote($oldvalue, '/').'$/', $value)) { + if (preg_match('/'.preg_quote((string) $oldvalue, '/').'$/', $value)) { $this->removeValue($key); } } else { - $value = preg_replace('/'.preg_quote($oldvalue, '/').'$/', $newvalue, $value, -1, $count); + $value = preg_replace('/'.preg_quote((string) $oldvalue, '/').'$/', $newvalue, $value, -1, $count); if ($count > 0) { /* Update display */ $this->fillDisplayValue($key); diff --git a/include/simpleplugin/attributes/dialog/class_ObjectsAttribute.inc b/include/simpleplugin/attributes/dialog/class_ObjectsAttribute.inc index dc583744d98d270291ee4bac1f3c53f400a6687c..15efd3dfb65ef5d2eab45e4c1f727de042e51e33 100755 --- a/include/simpleplugin/attributes/dialog/class_ObjectsAttribute.inc +++ b/include/simpleplugin/attributes/dialog/class_ObjectsAttribute.inc @@ -60,7 +60,7 @@ class ObjectsAttribute extends GenericDialogAttribute $attributes[$attribute] = '*'; } } - } catch (NonExistingObjectTypeException $e) { + } catch (NonExistingObjectTypeException) { unset($objectTypes[$i]); } } @@ -97,7 +97,7 @@ class ObjectsAttribute extends GenericDialogAttribute } else { $objects = objects::ls($this->selectManagementParameters[0], $this->selectManagementParameters[2], NULL, '('.$this->store_attr.'='.ldap_escape_f($value).')'); } - } catch (EmptyFilterException $e) { + } catch (EmptyFilterException) { $objects = []; } if (empty($objects) && $this->isTemplate()) { @@ -117,7 +117,7 @@ class ObjectsAttribute extends GenericDialogAttribute if (objects::isOfType($attrs, $type)) { $objectType = $type; } - } catch (NonExistingObjectTypeException $e) { + } catch (NonExistingObjectTypeException) { continue; } } @@ -131,7 +131,7 @@ class ObjectsAttribute extends GenericDialogAttribute } else { $display = $attrs[$this->display_attr][0]; } - $this->displays[$i] = trim($display); + $this->displays[$i] = trim((string) $display); $this->types[$i] = $objectType; } if (!isset($this->displays[$i])) { @@ -163,7 +163,7 @@ class ObjectsAttribute extends GenericDialogAttribute if ($this->types[$key] !== FALSE) { $infos = objects::infos($this->types[$key]); } - } catch (NonExistingObjectTypeException $e) { + } catch (NonExistingObjectTypeException) { /* Ignore non-existing types, plugins may have been removed */ } if (isset($infos['icon'])) { diff --git a/include/simpleplugin/class_Attribute.inc b/include/simpleplugin/class_Attribute.inc index 9e38dcee736f2dd904a9d5049fdc43ea86c126e4..8d51d2cc4565854c7794bfbda67fa5975c90121e 100755 --- a/include/simpleplugin/class_Attribute.inc +++ b/include/simpleplugin/class_Attribute.inc @@ -509,11 +509,11 @@ class Attribute } } if (is_array($ldapValue)) { - $filter = '(|('.$this->getLdapName().'='.join(')('.$this->getLdapName().'=', array_map('ldap_escape_f', $ldapValue)).'))'; + $filter = '(|('.$this->getLdapName().'='.implode(')('.$this->getLdapName().'=', array_map('ldap_escape_f', $ldapValue)).'))'; } else { $filter = '('.$this->getLdapName().'='.ldap_escape_f($ldapValue).')'; } - $infos = \pluglist::pluginInfos(get_class($this->plugin)); + $infos = \pluglist::pluginInfos($this->plugin::class); if ($this->uniqueFilter === NULL) { $objectTypeFilters = array_map( function ($key, $ot) @@ -524,7 +524,7 @@ class Attribute try { $oinfos = \objects::infos($ot); return $oinfos['filter']; - } catch (\NonExistingObjectTypeException $e) { + } catch (\NonExistingObjectTypeException) { return ''; } }, @@ -533,16 +533,16 @@ class Attribute ); $filters = []; if (!empty($objectTypeFilters)) { - $filters[] = '(|'.implode($objectTypeFilters).')'; + $filters[] = '(|'.implode('', $objectTypeFilters).')'; } - $pluginFilter = call_user_func([get_class($this->plugin), 'getLdapFilter']); + $pluginFilter = call_user_func([$this->plugin::class, 'getLdapFilter']); if (!empty($pluginFilter)) { $filters[] = $pluginFilter; } } else { $filters = [$this->uniqueFilter]; } - $filter = '(&'.$filter.implode($filters).')'; + $filter = '(&'.$filter.implode('', $filters).')'; $branches = array_filter( array_map( function ($key, $ot) @@ -553,7 +553,7 @@ class Attribute try { $oinfos = \objects::infos($ot); return $oinfos['ou']; - } catch (\NonExistingObjectTypeException $e) { + } catch (\NonExistingObjectTypeException) { return FALSE; } }, @@ -569,13 +569,13 @@ class Attribute $ldap->search($filter, [$this->getLdapName()]); while ($attrs = $ldap->fetch()) { if ($attrs['dn'] != $this->plugin->dn) { - $dn_base = preg_replace('/^[^,]+,/', '', $attrs['dn']); + $dn_base = preg_replace('/^[^,]+,/', '', (string) $attrs['dn']); $found = FALSE; if ($this->unique === 'one') { /* Check that this entry is in a concerned branch */ foreach ($branches as $branch) { if ($branch.$base == $dn_base) { - $dn_base = preg_replace('/^'.preg_quote($branch, '/').'/', '', $dn_base); + $dn_base = preg_replace('/^'.preg_quote((string) $branch, '/').'/', '', (string) $dn_base); $found = TRUE; break; } @@ -583,8 +583,8 @@ class Attribute } elseif ($this->uniqueFilter === NULL) { /* whole (or sub) */ /* Check that this entry is in a concerned branch */ foreach ($branches as $branch) { - if (preg_match('/^'.preg_quote($branch, '/').'/', $dn_base)) { - $dn_base = preg_replace('/^'.preg_quote($branch, '/').'/', '', $dn_base); + if (preg_match('/^'.preg_quote((string) $branch, '/').'/', (string) $dn_base)) { + $dn_base = preg_replace('/^'.preg_quote((string) $branch, '/').'/', '', (string) $dn_base); $found = TRUE; break; } @@ -664,7 +664,7 @@ class Attribute function serializeAttribute (array &$attributes, bool $form = TRUE) { if (!$form || $this->visible) { - $class = get_class($this); + $class = static::class; $type = []; while ($class != FALSE) { $type[] = $class; @@ -794,7 +794,7 @@ class Attribute $this->resetToDefault(); } elseif ($source['FIELD'] == 'dn') { $initialValue = $this->getInitialValue(); - $initialValue = preg_replace('/'.preg_quote($oldvalue, '/').'$/', $newvalue, $initialValue, -1, $count); + $initialValue = preg_replace('/'.preg_quote((string) $oldvalue, '/').'$/', $newvalue, (string) $initialValue, -1, $count); if ($count > 0) { $this->setValue($initialValue); } diff --git a/include/simpleplugin/class_helpersAttribute.inc b/include/simpleplugin/class_helpersAttribute.inc index df7a2601296837a7b441476d34d2a02d1b909014..53eb81ab45280b2333657cbf111611e177f7976d 100755 --- a/include/simpleplugin/class_helpersAttribute.inc +++ b/include/simpleplugin/class_helpersAttribute.inc @@ -128,7 +128,7 @@ class MacAddressAttribute extends StringAttribute function setValue ($value) { - return parent::setValue(strtolower($value)); + return parent::setValue(strtolower((string) $value)); } } @@ -152,7 +152,7 @@ class CharSeparatedCompositeAttribute extends CompositeAttribute function writeValues (array $values) { - return join($this->sep, $values); + return implode($this->sep, $values); } } @@ -196,7 +196,7 @@ class CommaListAttribute extends CompositeAttribute function writeValues (array $values) { - return join($this->sep, $values[0]); + return implode($this->sep, $values[0]); } } diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index ce0481daf6c3f6becaa1fb4db49ee2236a594a3a..0e8cb651c70cf4fe8c89d5d45b77d83e7ce559a1 100755 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -159,8 +159,8 @@ class simplePlugin implements SimpleTab $this->mainTab = $mainTab; try { - $plInfo = pluglist::pluginInfos(get_class($this)); - } catch (UnknownClassException $e) { + $plInfo = pluglist::pluginInfos(static::class); + } catch (UnknownClassException) { /* May happen in special cases like setup */ $plInfo = []; } @@ -257,7 +257,7 @@ class simplePlugin implements SimpleTab /* Is Account? */ if ($this->is_this_account($this->attrs)) { $this->is_account = TRUE; - logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, get_class($this), 'Tab active'); + logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, static::class, 'Tab active'); } } @@ -331,7 +331,7 @@ class simplePlugin implements SimpleTab } $found = TRUE; foreach ($this->objectclasses as $obj) { - if (preg_match('/^top$/i', $obj)) { + if (preg_match('/^top$/i', (string) $obj)) { continue; } if (!isset($attrs['objectClass']) || !in_array_ics($obj, $attrs['objectClass'])) { @@ -478,7 +478,7 @@ class simplePlugin implements SimpleTab throw new FatalError( htmlescape(sprintf( _('Could not compute dn: no parent tab class for "%s"'), - get_class($this) + static::class )) ); } @@ -487,7 +487,7 @@ class simplePlugin implements SimpleTab throw new FatalError( htmlescape(sprintf( _('Could not compute dn: could not find objectType info from tab class "%s"'), - get_class($this->parent) + $this->parent::class )) ); } @@ -547,8 +547,8 @@ class simplePlugin implements SimpleTab /* Add current base */ if (isset($this->base) && isset($departmentTree[$this->base])) { $deps[$this->base] = $departmentTree[$this->base]; - } elseif (strtolower($this->dn) != strtolower($config->current['BASE'])) { - trigger_error('Cannot return list of departments, no default base found in class ' . get_class($this) . '. (base is "' . $this->base . '")'); + } elseif (strtolower((string) $this->dn) != strtolower((string) $config->current['BASE'])) { + trigger_error('Cannot return list of departments, no default base found in class ' . static::class . '. (base is "' . $this->base . '")'); } return $deps; } @@ -597,8 +597,8 @@ class simplePlugin implements SimpleTab } /* Update userinfo if necessary */ - if (preg_match('/' . preg_quote($src_dn, '/') . '$/i', $ui->dn)) { - $ui->dn = preg_replace('/' . preg_quote($src_dn, '/') . '$/i', $dst_dn, $ui->dn); + if (preg_match('/' . preg_quote($src_dn, '/') . '$/i', (string) $ui->dn)) { + $ui->dn = preg_replace('/' . preg_quote($src_dn, '/') . '$/i', $dst_dn, (string) $ui->dn); } /* Check if departments were moved. If so, force the reload of $config departments cache */ @@ -628,7 +628,7 @@ class simplePlugin implements SimpleTab { if ($this->editing_group == NULL) { if (isset($this->parent)) { - $this->editing_group = (get_class($this->parent->getBaseObject()) == 'ogroup'); + $this->editing_group = ($this->parent->getBaseObject()::class == 'ogroup'); } else { return NULL; } @@ -691,14 +691,14 @@ class simplePlugin implements SimpleTab $htmlText, $this->is_account, $disabled, - get_class($this) . '_modify_state' + static::class . '_modify_state' ); if (!$this->is_account) { $this->displayPlugin = FALSE; return $this->header . $this->inheritanceDisplay(); } } elseif (!$this->is_account) { - $plInfo = pluglist::pluginInfos(get_class($this)); + $plInfo = pluglist::pluginInfos(static::class); $this->header = '<img alt="' . htmlescape(_('Error')) . '" src="geticon.php?context=status&icon=dialog-error&size=16" align="middle"/> <b>' . msgPool::noValidExtension($plInfo['plShortName']) . "</b>"; $this->displayPlugin = FALSE; @@ -709,7 +709,7 @@ class simplePlugin implements SimpleTab $smarty = get_smarty(); $this->renderAttributes(FALSE); - $smarty->assign("hiddenPostedInput", get_class($this) . "_posted"); + $smarty->assign("hiddenPostedInput", static::class . "_posted"); if (isset($this->focusedField)) { $smarty->assign("focusedField", $this->focusedField); unset($this->focusedField); @@ -722,7 +722,7 @@ class simplePlugin implements SimpleTab public function getDisplayHeaderInfos (): array { - $plInfo = pluglist::pluginInfos(get_class($this)); + $plInfo = pluglist::pluginInfos(static::class); $disabled = $this->acl_skip_write(); if ($this->is_account) { $depends = []; @@ -893,7 +893,7 @@ class simplePlugin implements SimpleTab $smarty->assign('sectionId', $section); $sectionClasses = ''; if (isset($sectionInfo['class'])) { - $sectionClasses .= ' ' . join(' ', $sectionInfo['class']); + $sectionClasses .= ' ' . implode(' ', $sectionInfo['class']); } $attributes = []; $readableSection = FALSE; @@ -930,14 +930,14 @@ class simplePlugin implements SimpleTab if (!$this->member_of_group) { return ""; } - $class = get_class($this); + $class = static::class; $attrsWrapper = new stdClass(); $attrsWrapper->attrs = $this->group_attrs; $group = new $class($this->group_attrs['dn'], $attrsWrapper, $this->parent, $this->mainTab); $smarty = get_smarty(); $group->renderAttributes(TRUE); - $smarty->assign("hiddenPostedInput", get_class($this) . "_posted"); + $smarty->assign("hiddenPostedInput", static::class . "_posted"); return "<h1>Inherited information:</h1><div></div>\n" . $smarty->fetch($this->templatePath); } @@ -971,7 +971,7 @@ class simplePlugin implements SimpleTab /*! \brief Can we write the attribute */ function acl_is_writeable ($attribute, bool $skipWrite = FALSE): bool { - return (strpos($this->aclGetPermissions($attribute, NULL, $skipWrite), 'w') !== FALSE); + return (str_contains($this->aclGetPermissions($attribute, NULL, $skipWrite), 'w')); } /*! @@ -981,7 +981,7 @@ class simplePlugin implements SimpleTab */ function acl_is_readable ($attribute): bool { - return (strpos($this->aclGetPermissions($attribute), 'r') !== FALSE); + return (str_contains($this->aclGetPermissions($attribute), 'r')); } /*! @@ -991,7 +991,7 @@ class simplePlugin implements SimpleTab */ function acl_is_createable (string $base = NULL): bool { - return (strpos($this->aclGetPermissions('0', $base), 'c') !== FALSE); + return (str_contains($this->aclGetPermissions('0', $base), 'c')); } /*! @@ -1001,7 +1001,7 @@ class simplePlugin implements SimpleTab */ function acl_is_removeable (string $base = NULL): bool { - return (strpos($this->aclGetPermissions('0', $base), 'd') !== FALSE); + return (str_contains($this->aclGetPermissions('0', $base), 'd')); } /*! @@ -1011,7 +1011,7 @@ class simplePlugin implements SimpleTab */ function acl_is_moveable (string $base = NULL): bool { - return (strpos($this->aclGetPermissions('0', $base), 'm') !== FALSE); + return (str_contains($this->aclGetPermissions('0', $base), 'm')); } /*! \brief Test if there are ACLs for this plugin */ @@ -1019,7 +1019,7 @@ class simplePlugin implements SimpleTab { global $config; - return in_array(get_class($this), $config->data['CATEGORIES'][rtrim($this->acl_category, '/')]['classes']); + return in_array(static::class, $config->data['CATEGORIES'][rtrim((string) $this->acl_category, '/')]['classes']); } /*! \brief Get the acl permissions for an attribute or the plugin itself */ @@ -1033,7 +1033,7 @@ class simplePlugin implements SimpleTab if ($base === NULL) { $base = $this->getAclBase(); } - return $ui->get_permissions($base, $this->acl_category . get_class($this), $attribute, $skipWrite); + return $ui->get_permissions($base, $this->acl_category . static::class, $attribute, $skipWrite); } /*! \brief This function removes the object from LDAP @@ -1084,7 +1084,7 @@ class simplePlugin implements SimpleTab if ($this->is_template) { if (isset($tmp['fdTemplateField'])) { foreach ($tmp['fdTemplateField'] as $tpl_field) { - if (preg_match('/^objectClass:(.+)$/', $tpl_field, $m)) { + if (preg_match('/^objectClass:(.+)$/', (string) $tpl_field, $m)) { $oc[] = $m[1]; } } @@ -1143,7 +1143,7 @@ class simplePlugin implements SimpleTab protected function post_remove () { - logging::log('remove', 'plugin/' . get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); + logging::log('remove', 'plugin/' . static::class, $this->dn, array_keys($this->attrs), $this->ldap_error); /* Optionally execute a command after we're done */ $errors = $this->handle_post_events('remove', ['modifiedLdapAttrs' => array_keys($this->attrs)]); @@ -1166,7 +1166,7 @@ class simplePlugin implements SimpleTab { logging::debug(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'readPost'); - if ($this->displayHeader && isset($_POST[get_class($this) . '_modify_state'])) { + if ($this->displayHeader && isset($_POST[static::class . '_modify_state'])) { if ($this->is_account && $this->acl_is_removeable()) { $this->is_account = FALSE; } elseif (!$this->is_account && $this->acl_is_createable()) { @@ -1176,7 +1176,7 @@ class simplePlugin implements SimpleTab if (is_object($this->dialog)) { $this->dialog->readPost(); } - if (isset($_POST[get_class($this) . '_posted'])) { + if (isset($_POST[static::class . '_posted'])) { // If our form has been posted // A first pass that loads the post values foreach ($this->attributesInfo as $sectionInfo) { @@ -1357,7 +1357,7 @@ class simplePlugin implements SimpleTab if ($this->is_template) { if (isset($tmp['fdTemplateField'])) { foreach ($tmp['fdTemplateField'] as $tpl_field) { - if (preg_match('/^objectClass:(.+)$/', $tpl_field, $m)) { + if (preg_match('/^objectClass:(.+)$/', (string) $tpl_field, $m)) { $oc[] = $m[1]; } } @@ -1415,7 +1415,7 @@ class simplePlugin implements SimpleTab } $ldap->cd($config->current['BASE']); try { - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', (string) $this->dn)); } catch (FusionDirectoryError $error) { return [$error]; } @@ -1461,7 +1461,7 @@ class simplePlugin implements SimpleTab if (!empty($auditAttributesValuesToBeHidden)) { foreach ($auditAttributesValuesToBeHidden as $key) { - if (key_exists($key, $this->attrs)) { + if (array_key_exists($key, $this->attrs)) { $this->attrs[$key] = 'Value not stored by policy'; } } @@ -1473,11 +1473,11 @@ class simplePlugin implements SimpleTab $modifiedAttrs = $this->getModifiedAttributesValues(); // We log values of attributes as well if modification occur in order for notification to be aware of the change. (Json allows array to string conversion). - logging::log('modify', 'plugin/' . get_class($this), $this->dn, [json_encode($modifiedAttrs)], $this->ldap_error); + logging::log('modify', 'plugin/' . static::class, $this->dn, [json_encode($modifiedAttrs)], $this->ldap_error); } else { $errors = $this->handle_post_events('add', ['modifiedLdapAttrs' => array_keys($this->attrs)]); - logging::log('create', 'plugin/' . get_class($this), $this->dn, array_keys($this->attrs), $this->ldap_error); + logging::log('create', 'plugin/' . static::class, $this->dn, array_keys($this->attrs), $this->ldap_error); } if (!empty($errors)) { @@ -1625,7 +1625,7 @@ class simplePlugin implements SimpleTab } global $config; - $commands = $config->searchHooks(get_class($this), $cmd); + $commands = $config->searchHooks(static::class, $cmd); $messages = []; foreach ($commands as $command) { @@ -1645,7 +1645,7 @@ class simplePlugin implements SimpleTab if (isset($this->parent->by_object)) { foreach ($this->parent->by_object as $class => $object) { - if ($class != get_class($this)) { + if ($class != static::class) { $object->fillHookAttrs($addAttrs); } } @@ -1679,7 +1679,7 @@ class simplePlugin implements SimpleTab $str = static::passwordProtect($str); logging::debug(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, 'Output: ' . $str); if (!empty($str) && $config->get_cfg_value('displayHookOutput', 'FALSE') == 'TRUE') { - msg_dialog::display('[' . get_class($this) . ' ' . strtolower($cmd) . 'trigger] ' . $command, htmlescape($str), INFO_DIALOG); + msg_dialog::display('[' . static::class . ' ' . strtolower((string) $cmd) . 'trigger] ' . $command, htmlescape($str), INFO_DIALOG); } } unset($arr, $command, $returnCode); @@ -1692,7 +1692,7 @@ class simplePlugin implements SimpleTab protected static function passwordProtect (string $hookCommand = NULL): string { if (isset($_POST["userPassword_password"]) && !empty($_POST["userPassword_password"])) { - if (strpos($hookCommand, $_POST["userPassword_password"]) !== FALSE) { + if (str_contains((string) $hookCommand, (string) $_POST["userPassword_password"])) { $hookCommand = str_replace($_POST["userPassword_password"], '*******', $hookCommand); } } @@ -1723,7 +1723,7 @@ class simplePlugin implements SimpleTab if (!empty($error)) { $messages = array_merge($messages, $error); } elseif (!empty($returnOutput)) { - $messages[] = join("\n", $returnOutput); + $messages[] = implode("\n", $returnOutput); } /* Check entryCSN */ @@ -1761,7 +1761,7 @@ class simplePlugin implements SimpleTab if (preg_match('/^handle_/', $mode)) { $olddn = $param1; $newdn = $param2; - $classes = [get_class($this)]; + $classes = [static::class]; if (($olddn != $newdn) && $this->mainTab) { if ($newdn === NULL) { $subobjects = $this->hadSubobjects; @@ -1805,10 +1805,10 @@ class simplePlugin implements SimpleTab if (!is_numeric($key)) { $objectType = $key; } - if (preg_match('/^ogroup-/i', $objectType)) { + if (preg_match('/^ogroup-/i', (string) $objectType)) { $objectType = 'OGROUP'; } - $objectTypes[] = strtoupper($objectType); + $objectTypes[] = strtoupper((string) $objectType); } $objectTypes = array_unique($objectTypes); } @@ -1862,7 +1862,7 @@ class simplePlugin implements SimpleTab if (!is_numeric($key)) { $objectType = $key; } - if (preg_match('/^ogroup-/i', $objectType)) { + if (preg_match('/^ogroup-/i', (string) $objectType)) { $objectType = 'OGROUP'; } $objectTypes[] = $objectType; @@ -1901,14 +1901,14 @@ class simplePlugin implements SimpleTab ]; $filter = templateHandling::parseString($filter, ['oldvalue' => $this->parent->by_object[$tabclass]->$field], 'ldap_escape_f'); } - if (!preg_match('/^\(.*\)$/', $filter)) { + if (!preg_match('/^\(.*\)$/', (string) $filter)) { $filter = '(' . $filter . ')'; } $foreignRefs[$objectType]['filters'][$filter] = $filter; } } } - } catch (UnknownClassException $e) { + } catch (UnknownClassException) { /* May happen in special cases like setup */ continue; } @@ -1921,7 +1921,7 @@ class simplePlugin implements SimpleTab foreach ($foreignRefs as $objectType => $tabRefs) { // Compute filter $filters = array_values($tabRefs['filters']); - $filter = '(|' . join($filters) . ')'; + $filter = '(|' . implode('', $filters) . ')'; // Search objects try { $objects = objects::ls($objectType, ['dn' => 'raw'], NULL, $filter); @@ -2338,7 +2338,7 @@ class simplePlugin implements SimpleTab if (!session::is_set($classname) || (isset($_GET['reset']) && $_GET['reset'] == 1)) { try { $tabObject = objects::open($entry_dn, $objectType); - } catch (NonExistingLdapNodeException $e) { + } catch (NonExistingLdapNodeException) { $tabObject = objects::open('new', $objectType); } if ($edit_mode) { @@ -2419,7 +2419,7 @@ class simplePlugin implements SimpleTab $display .= ' '; $display .= '<input type="submit" formnovalidate="formnovalidate" name="edit_cancel" value="' . msgPool::cancelButton() . '"/>' . "\n"; $display .= "</p>\n"; - } elseif (strpos($tabObject->by_object[$tabObject->current]->aclGetPermissions(''), 'w') !== FALSE) { + } elseif (str_contains((string) $tabObject->by_object[$tabObject->current]->aclGetPermissions(''), 'w')) { /* Only display edit button if there is at least one attribute writable */ $display .= '<p class="plugbottom">' . "\n"; $info .= '<div style="float:left;" class="optional"><img class="center" alt="information" ' . diff --git a/include/simpleplugin/class_simpleService.inc b/include/simpleplugin/class_simpleService.inc index 889ea71a82eb41514fa7b76fedebc118091aad93..14b9eab72ba5718c928c3d1889e32e7b50200215 100755 --- a/include/simpleplugin/class_simpleService.inc +++ b/include/simpleplugin/class_simpleService.inc @@ -46,7 +46,7 @@ class simpleService extends simplePlugin /* Services do not have the activation header, but can still be disabled */ $this->ignore_account = FALSE; - $plInfos = pluglist::pluginInfos(get_class($this)); + $plInfos = pluglist::pluginInfos(static::class); $this->DisplayName = $plInfos['plShortName']; } diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc index 29df963d68ec4fe45e65489e28981e5cc7ac1ef8..3602f04fc34e5f3ad85b36a7d4cde836e5b962cf 100755 --- a/include/simpleplugin/class_simpleTabs.inc +++ b/include/simpleplugin/class_simpleTabs.inc @@ -71,7 +71,7 @@ class simpleTabs implements FusionDirectoryDialog throw new FusionDirectoryException( sprintf( _('No plugin definitions found to initialize "%s", please check your configuration file.'), - get_class($this) + static::class ) ); } @@ -126,7 +126,7 @@ class simpleTabs implements FusionDirectoryDialog { $baseobject = NULL; foreach ($this->by_object as $name => $object) { - $class = get_class($object); + $class = $object::class; if (in_array($class, ["reference","acl"])) { continue; } @@ -245,7 +245,7 @@ class simpleTabs implements FusionDirectoryDialog public function update (): bool { /* Call update on all tabs as they may react to changes in other tabs */ - foreach ($this->by_object as $key => $obj) { + foreach ($this->by_object as $obj) { $obj->update(); }