Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-03-03 13:53:50 +0300
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-03-03 13:53:50 +0300
commit0c5bd588ed4528d46df244a686b6f91299766836 (patch)
tree0c7af0bd7444018364477e0a326c6e9ddcaf712e /apps/user_ldap
parente80eb79a1e59d74f35136e33407c98909474d3af (diff)
Fix types in OCA\User_LDAP\Configuration
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/lib/Configuration.php86
-rw-r--r--apps/user_ldap/lib/Connection.php4
2 files changed, 31 insertions, 59 deletions
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index ab5aa23f98d..9ffb2a79781 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -47,7 +47,13 @@ class Configuration {
public const LDAP_SERVER_FEATURE_AVAILABLE = 'available';
public const LDAP_SERVER_FEATURE_UNAVAILABLE = 'unavailable';
- protected $configPrefix = null;
+ /**
+ * @var string
+ */
+ protected $configPrefix;
+ /**
+ * @var bool
+ */
protected $configRead = false;
/**
* @var string[] pre-filled with one reference key so that at least one entry is written on save request and
@@ -55,7 +61,9 @@ class Configuration {
*/
protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive'];
- //settings
+ /**
+ * @var array<string, mixed> settings
+ */
protected $config = [
'ldapHost' => null,
'ldapPort' => null,
@@ -115,11 +123,7 @@ class Configuration {
'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
];
- /**
- * @param string $configPrefix
- * @param bool $autoRead
- */
- public function __construct($configPrefix, $autoRead = true) {
+ public function __construct(string $configPrefix, bool $autoRead = true) {
$this->configPrefix = $configPrefix;
if ($autoRead) {
$this->readConfiguration();
@@ -145,10 +149,7 @@ class Configuration {
$this->setConfiguration([$name => $value]);
}
- /**
- * @return array
- */
- public function getConfiguration() {
+ public function getConfiguration(): array {
return $this->config;
}
@@ -159,13 +160,8 @@ class Configuration {
* @param array $config array that holds the config parameters in an associated
* array
* @param array &$applied optional; array where the set fields will be given to
- * @return false|null
*/
- public function setConfiguration($config, &$applied = null) {
- if (!is_array($config)) {
- return false;
- }
-
+ public function setConfiguration(array $config, array &$applied = null): void {
$cta = $this->getConfigTranslationArray();
foreach ($config as $inputKey => $val) {
if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
@@ -207,11 +203,10 @@ class Configuration {
}
$this->unsavedChanges[$key] = $key;
}
- return null;
}
- public function readConfiguration() {
- if (!$this->configRead && !is_null($this->configPrefix)) {
+ public function readConfiguration(): void {
+ if (!$this->configRead) {
$cta = array_flip($this->getConfigTranslationArray());
foreach ($this->config as $key => $val) {
if (!isset($cta[$key])) {
@@ -260,7 +255,7 @@ class Configuration {
/**
* saves the current config changes in the database
*/
- public function saveConfiguration() {
+ public function saveConfiguration(): void {
$cta = array_flip($this->getConfigTranslationArray());
foreach ($this->unsavedChanges as $key) {
$value = $this->config[$key];
@@ -293,7 +288,7 @@ class Configuration {
}
$this->saveValue($cta[$key], $value);
}
- $this->saveValue('_lastChange', time());
+ $this->saveValue('_lastChange', (string)time());
$this->unsavedChanges = [];
}
@@ -318,7 +313,7 @@ class Configuration {
* @param string $varName name of config-key
* @param array|string $value to set
*/
- protected function setMultiLine($varName, $value) {
+ protected function setMultiLine(string $varName, $value): void {
if (empty($value)) {
$value = '';
} elseif (!is_array($value)) {
@@ -349,36 +344,20 @@ class Configuration {
$this->setRawValue($varName, $finalValue);
}
- /**
- * @param string $varName
- * @return string
- */
- protected function getPwd($varName) {
+ protected function getPwd(string $varName): string {
return base64_decode($this->getValue($varName));
}
- /**
- * @param string $varName
- * @return string
- */
- protected function getLcValue($varName) {
+ protected function getLcValue(string $varName): string {
return mb_strtolower($this->getValue($varName), 'UTF-8');
}
- /**
- * @param string $varName
- * @return string
- */
- protected function getSystemValue($varName) {
+ protected function getSystemValue(string $varName): string {
//FIXME: if another system value is added, softcode the default value
return \OC::$server->getConfig()->getSystemValue($varName, false);
}
- /**
- * @param string $varName
- * @return string
- */
- protected function getValue($varName) {
+ protected function getValue(string $varName): string {
static $defaults;
if (is_null($defaults)) {
$defaults = $this->getDefaults();
@@ -394,7 +373,7 @@ class Configuration {
* @param string $varName name of config key
* @param mixed $value to set
*/
- protected function setValue($varName, $value) {
+ protected function setValue(string $varName, $value): void {
if (is_string($value)) {
$value = trim($value);
}
@@ -407,16 +386,11 @@ class Configuration {
* @param string $varName name of config key
* @param mixed $value to set
*/
- protected function setRawValue($varName, $value) {
+ protected function setRawValue(string $varName, $value): void {
$this->config[$varName] = $value;
}
- /**
- * @param string $varName
- * @param string $value
- * @return bool
- */
- protected function saveValue($varName, $value) {
+ protected function saveValue(string $varName, string $value): bool {
\OC::$server->getConfig()->setAppValue(
'user_ldap',
$this->configPrefix.$varName,
@@ -429,7 +403,7 @@ class Configuration {
* @return array an associative array with the default values. Keys are correspond
* to config-value entries in the database table
*/
- public function getDefaults() {
+ public function getDefaults(): array {
return [
'ldap_host' => '',
'ldap_port' => '',
@@ -492,7 +466,7 @@ class Configuration {
/**
* @return array that maps internal variable names to database fields
*/
- public function getConfigTranslationArray() {
+ public function getConfigTranslationArray(): array {
//TODO: merge them into one representation
static $array = [
'ldap_host' => 'ldapHost',
@@ -554,18 +528,16 @@ class Configuration {
}
/**
- * @param string $rule
- * @return array
* @throws \RuntimeException
*/
- public function resolveRule($rule) {
+ public function resolveRule(string $rule): array {
if ($rule === 'avatar') {
return $this->getAvatarAttributes();
}
throw new \RuntimeException('Invalid rule');
}
- public function getAvatarAttributes() {
+ public function getAvatarAttributes(): array {
$value = $this->ldapUserAvatarRule ?: self::AVATAR_PREFIX_DEFAULT;
$defaultAttributes = ['jpegphoto', 'thumbnailphoto'];
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 3cd6a340a56..fefa1f0e329 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -304,9 +304,9 @@ class Connection extends LDAPUtility {
* set LDAP configuration with values delivered by an array, not read from configuration
* @param array $config array that holds the config parameters in an associated array
* @param array &$setParameters optional; array where the set fields will be given to
- * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
+ * @return bool true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
*/
- public function setConfiguration($config, &$setParameters = null) {
+ public function setConfiguration($config, &$setParameters = null): bool {
if (is_null($setParameters)) {
$setParameters = [];
}