@@ -47,15 +47,23 @@ class Configuration {
4747 public const LDAP_SERVER_FEATURE_AVAILABLE = 'available ' ;
4848 public const LDAP_SERVER_FEATURE_UNAVAILABLE = 'unavailable ' ;
4949
50- protected $ configPrefix = null ;
50+ /**
51+ * @var string
52+ */
53+ protected $ configPrefix ;
54+ /**
55+ * @var bool
56+ */
5157 protected $ configRead = false ;
5258 /**
5359 * @var string[] pre-filled with one reference key so that at least one entry is written on save request and
5460 * the config ID is registered
5561 */
5662 protected $ unsavedChanges = ['ldapConfigurationActive ' => 'ldapConfigurationActive ' ];
5763
58- //settings
64+ /**
65+ * @var array<string, mixed> settings
66+ */
5967 protected $ config = [
6068 'ldapHost ' => null ,
6169 'ldapPort ' => null ,
@@ -115,11 +123,7 @@ class Configuration {
115123 'ldapMatchingRuleInChainState ' => self ::LDAP_SERVER_FEATURE_UNKNOWN ,
116124 ];
117125
118- /**
119- * @param string $configPrefix
120- * @param bool $autoRead
121- */
122- public function __construct ($ configPrefix , $ autoRead = true ) {
126+ public function __construct (string $ configPrefix , bool $ autoRead = true ) {
123127 $ this ->configPrefix = $ configPrefix ;
124128 if ($ autoRead ) {
125129 $ this ->readConfiguration ();
@@ -145,10 +149,7 @@ public function __set($name, $value) {
145149 $ this ->setConfiguration ([$ name => $ value ]);
146150 }
147151
148- /**
149- * @return array
150- */
151- public function getConfiguration () {
152+ public function getConfiguration (): array {
152153 return $ this ->config ;
153154 }
154155
@@ -159,13 +160,8 @@ public function getConfiguration() {
159160 * @param array $config array that holds the config parameters in an associated
160161 * array
161162 * @param array &$applied optional; array where the set fields will be given to
162- * @return false|null
163163 */
164- public function setConfiguration ($ config , &$ applied = null ) {
165- if (!is_array ($ config )) {
166- return false ;
167- }
168-
164+ public function setConfiguration (array $ config , array &$ applied = null ): void {
169165 $ cta = $ this ->getConfigTranslationArray ();
170166 foreach ($ config as $ inputKey => $ val ) {
171167 if (strpos ($ inputKey , '_ ' ) !== false && array_key_exists ($ inputKey , $ cta )) {
@@ -207,11 +203,10 @@ public function setConfiguration($config, &$applied = null) {
207203 }
208204 $ this ->unsavedChanges [$ key ] = $ key ;
209205 }
210- return null ;
211206 }
212207
213- public function readConfiguration () {
214- if (!$ this ->configRead && ! is_null ( $ this -> configPrefix ) ) {
208+ public function readConfiguration (): void {
209+ if (!$ this ->configRead ) {
215210 $ cta = array_flip ($ this ->getConfigTranslationArray ());
216211 foreach ($ this ->config as $ key => $ val ) {
217212 if (!isset ($ cta [$ key ])) {
@@ -260,7 +255,7 @@ public function readConfiguration() {
260255 /**
261256 * saves the current config changes in the database
262257 */
263- public function saveConfiguration () {
258+ public function saveConfiguration (): void {
264259 $ cta = array_flip ($ this ->getConfigTranslationArray ());
265260 foreach ($ this ->unsavedChanges as $ key ) {
266261 $ value = $ this ->config [$ key ];
@@ -293,7 +288,7 @@ public function saveConfiguration() {
293288 }
294289 $ this ->saveValue ($ cta [$ key ], $ value );
295290 }
296- $ this ->saveValue ('_lastChange ' , time ());
291+ $ this ->saveValue ('_lastChange ' , ( string ) time ());
297292 $ this ->unsavedChanges = [];
298293 }
299294
@@ -318,7 +313,7 @@ protected function getMultiLine($varName) {
318313 * @param string $varName name of config-key
319314 * @param array|string $value to set
320315 */
321- protected function setMultiLine ($ varName , $ value ) {
316+ protected function setMultiLine (string $ varName , $ value ): void {
322317 if (empty ($ value )) {
323318 $ value = '' ;
324319 } elseif (!is_array ($ value )) {
@@ -349,36 +344,20 @@ protected function setMultiLine($varName, $value) {
349344 $ this ->setRawValue ($ varName , $ finalValue );
350345 }
351346
352- /**
353- * @param string $varName
354- * @return string
355- */
356- protected function getPwd ($ varName ) {
347+ protected function getPwd (string $ varName ): string {
357348 return base64_decode ($ this ->getValue ($ varName ));
358349 }
359350
360- /**
361- * @param string $varName
362- * @return string
363- */
364- protected function getLcValue ($ varName ) {
351+ protected function getLcValue (string $ varName ): string {
365352 return mb_strtolower ($ this ->getValue ($ varName ), 'UTF-8 ' );
366353 }
367354
368- /**
369- * @param string $varName
370- * @return string
371- */
372- protected function getSystemValue ($ varName ) {
355+ protected function getSystemValue (string $ varName ): string {
373356 //FIXME: if another system value is added, softcode the default value
374357 return \OC ::$ server ->getConfig ()->getSystemValue ($ varName , false );
375358 }
376359
377- /**
378- * @param string $varName
379- * @return string
380- */
381- protected function getValue ($ varName ) {
360+ protected function getValue (string $ varName ): string {
382361 static $ defaults ;
383362 if (is_null ($ defaults )) {
384363 $ defaults = $ this ->getDefaults ();
@@ -394,7 +373,7 @@ protected function getValue($varName) {
394373 * @param string $varName name of config key
395374 * @param mixed $value to set
396375 */
397- protected function setValue ($ varName , $ value ) {
376+ protected function setValue (string $ varName , $ value ): void {
398377 if (is_string ($ value )) {
399378 $ value = trim ($ value );
400379 }
@@ -407,16 +386,11 @@ protected function setValue($varName, $value) {
407386 * @param string $varName name of config key
408387 * @param mixed $value to set
409388 */
410- protected function setRawValue ($ varName , $ value ) {
389+ protected function setRawValue (string $ varName , $ value ): void {
411390 $ this ->config [$ varName ] = $ value ;
412391 }
413392
414- /**
415- * @param string $varName
416- * @param string $value
417- * @return bool
418- */
419- protected function saveValue ($ varName , $ value ) {
393+ protected function saveValue (string $ varName , string $ value ): bool {
420394 \OC ::$ server ->getConfig ()->setAppValue (
421395 'user_ldap ' ,
422396 $ this ->configPrefix .$ varName ,
@@ -429,7 +403,7 @@ protected function saveValue($varName, $value) {
429403 * @return array an associative array with the default values. Keys are correspond
430404 * to config-value entries in the database table
431405 */
432- public function getDefaults () {
406+ public function getDefaults (): array {
433407 return [
434408 'ldap_host ' => '' ,
435409 'ldap_port ' => '' ,
@@ -492,7 +466,7 @@ public function getDefaults() {
492466 /**
493467 * @return array that maps internal variable names to database fields
494468 */
495- public function getConfigTranslationArray () {
469+ public function getConfigTranslationArray (): array {
496470 //TODO: merge them into one representation
497471 static $ array = [
498472 'ldap_host ' => 'ldapHost ' ,
@@ -554,18 +528,16 @@ public function getConfigTranslationArray() {
554528 }
555529
556530 /**
557- * @param string $rule
558- * @return array
559531 * @throws \RuntimeException
560532 */
561- public function resolveRule ($ rule ) {
533+ public function resolveRule (string $ rule ): array {
562534 if ($ rule === 'avatar ' ) {
563535 return $ this ->getAvatarAttributes ();
564536 }
565537 throw new \RuntimeException ('Invalid rule ' );
566538 }
567539
568- public function getAvatarAttributes () {
540+ public function getAvatarAttributes (): array {
569541 $ value = $ this ->ldapUserAvatarRule ?: self ::AVATAR_PREFIX_DEFAULT ;
570542 $ defaultAttributes = ['jpegphoto ' , 'thumbnailphoto ' ];
571543
0 commit comments