Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Sep 2, 2024
1 parent 745f75a commit c78f304
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu
* @return string
*/
public function getUserValue($userId, $appName, $key, $default = '') {
if ($userId === null || $userId === '') {
return $default;
}
return \OC::$server->get(UserPreferences::class)->getValueMixed($userId, $appName, $key, $default);

Check failure

Code scanning / Psalm

NullableReturnStatement Error

The declared return type 'string' for OC\AllConfig::getUserValue is not nullable, but the function returns 'null|string'

Check failure on line 262 in lib/private/AllConfig.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

NullableReturnStatement

lib/private/AllConfig.php:262:10: NullableReturnStatement: The declared return type 'string' for OC\AllConfig::getUserValue is not nullable, but the function returns 'null|string' (see https://psalm.dev/139)
}

Expand Down
16 changes: 8 additions & 8 deletions lib/public/UserPreferences/IUserPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function getValueInt(string $userId, string $app, string $key, int $defau
* @param bool $lazy search within lazy loaded preferences
*
* @return float stored preference value or $default if not set in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see getValueString()
* @see getValueInt()
Expand All @@ -236,7 +236,7 @@ public function getValueFloat(string $userId, string $app, string $key, float $d
* @param bool $lazy search within lazy loaded preferences
*
* @return bool stored preference value or $default if not set in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPrefences for explanation about lazy loading
* @see getValueString()
* @see getValueInt()
Expand All @@ -253,11 +253,11 @@ public function getValueBool(string $userId, string $app, string $key, bool $def
* @param string $userId id of the user
* @param string $app id of the app
* @param string $key preference key
* @param array $default default value
* @param array $default default value`
* @param bool $lazy search within lazy loaded preferences
*
* @return array stored preference value or $default if not set in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see getValueString()
* @see getValueInt()
Expand Down Expand Up @@ -300,7 +300,7 @@ public function getValueType(string $userId, string $app, string $key, ?bool $la
* @param bool $lazy set preference as lazy loaded
*
* @return bool TRUE if value was different, therefor updated in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see setValueInt()
* @see setValueFloat()
Expand Down Expand Up @@ -330,7 +330,7 @@ public function setValueString(string $userId, string $app, string $key, string
* @param bool $lazy set preference as lazy loaded
*
* @return bool TRUE if value was different, therefor updated in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see setValueString()
* @see setValueFloat()
Expand All @@ -355,7 +355,7 @@ public function setValueInt(string $userId, string $app, string $key, int $value
* @param bool $lazy set preference as lazy loaded
*
* @return bool TRUE if value was different, therefor updated in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see setValueString()
* @see setValueInt()
Expand All @@ -379,7 +379,7 @@ public function setValueFloat(string $userId, string $app, string $key, float $v
* @param bool $lazy set preference as lazy loaded
*
* @return bool TRUE if value was different, therefor updated in database
* @since 30.0.0
* @since 31.0.0
* @see IUserPreferences for explanation about lazy loading
* @see setValueString()
* @see setValueInt()
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/AllConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ public function testGetUserKeysAllInts() {

// preparation - add something to the database
$data = [
['userFetch', 'appFetch1', '123', 'value'],
['userFetch', 'appFetch1', '456', 'value'],
['userFetch2', 'appFetch1', '123', 'value'],
['userFetch2', 'appFetch1', '456', 'value'],
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
Expand All @@ -292,7 +292,7 @@ public function testGetUserKeysAllInts() {
);
}

$value = $config->getUserKeys('userFetch', 'appFetch1');
$value = $config->getUserKeys('userFetch2', 'appFetch1');
$this->assertEquals(['123', '456'], $value);
$this->assertIsString($value[0]);
$this->assertIsString($value[1]);
Expand Down

0 comments on commit c78f304

Please sign in to comment.