diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-01-03 14:32:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 14:32:31 +0100 |
commit | 06da8adcd309952b7b83ebfaa88c7259a41cd2ed (patch) | |
tree | 47f1a69fe4f452098bfa62689bad43a7604a7a69 | |
parent | 4e877b7ff1977389a67cafd6f028f40f83bc91b3 (diff) | |
parent | a7740c0ae67490aba55e9a05fcb09e7049818341 (diff) | |
download | nextcloud-server-06da8adcd309952b7b83ebfaa88c7259a41cd2ed.tar.gz nextcloud-server-06da8adcd309952b7b83ebfaa88c7259a41cd2ed.zip |
Merge pull request #35943 from nextcloud/fix/code-fixes-from-34997
Code fixes from PR 34997
-rw-r--r-- | apps/dav/lib/Connector/Sabre/File.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php | 21 | ||||
-rw-r--r-- | apps/files_external/tests/Backend/BackendTest.php | 4 | ||||
-rw-r--r-- | apps/settings/tests/Controller/UsersControllerTest.php | 10 | ||||
-rw-r--r-- | apps/user_ldap/ajax/wizard.php | 4 | ||||
-rw-r--r-- | apps/user_ldap/lib/Access.php | 4 | ||||
-rw-r--r-- | apps/user_ldap/lib/Mapping/AbstractMapping.php | 9 | ||||
-rw-r--r-- | apps/weather_status/lib/Service/WeatherStatusService.php | 18 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php | 3 | ||||
-rw-r--r-- | lib/private/KnownUser/KnownUserMapper.php | 5 | ||||
-rwxr-xr-x | lib/private/LargeFileHelper.php | 2 | ||||
-rw-r--r-- | lib/private/Preview/Office.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/OC_API.php | 7 |
13 files changed, 42 insertions, 51 deletions
diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 3a871b06259..fd8a6437222 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -273,9 +273,9 @@ class File extends Node implements IFile { if ($result === false) { $expected = -1; if (isset($_SERVER['CONTENT_LENGTH'])) { - $expected = $_SERVER['CONTENT_LENGTH']; + $expected = (int)$_SERVER['CONTENT_LENGTH']; } - if ($expected !== "0") { + if ($expected !== 0) { throw new Exception( $this->l10n->t( 'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)', diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php index f92bc4f3a0d..98be4e41917 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php @@ -36,7 +36,6 @@ use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; class AppleProvisioningPlugin extends ServerPlugin { - /** * @var Server */ @@ -68,23 +67,21 @@ class AppleProvisioningPlugin extends ServerPlugin { protected $l10n; /** - * @var \closure + * @var \Closure */ protected $uuidClosure; /** * AppleProvisioningPlugin constructor. - * - * @param IUserSession $userSession - * @param IURLGenerator $urlGenerator - * @param \OC_Defaults $themingDefaults - * @param IRequest $request - * @param IL10N $l10n - * @param \closure $uuidClosure */ - public function __construct(IUserSession $userSession, IURLGenerator $urlGenerator, - \OC_Defaults $themingDefaults, IRequest $request, - IL10N $l10n, \closure $uuidClosure) { + public function __construct( + IUserSession $userSession, + IURLGenerator $urlGenerator, + \OC_Defaults $themingDefaults, + IRequest $request, + IL10N $l10n, + \Closure $uuidClosure + ) { $this->userSession = $userSession; $this->urlGenerator = $urlGenerator; $this->themingDefaults = $themingDefaults; diff --git a/apps/files_external/tests/Backend/BackendTest.php b/apps/files_external/tests/Backend/BackendTest.php index 011b8711c4a..066aab0ff31 100644 --- a/apps/files_external/tests/Backend/BackendTest.php +++ b/apps/files_external/tests/Backend/BackendTest.php @@ -46,8 +46,8 @@ class BackendTest extends \Test\TestCase { $this->assertEquals($json['name'], $json['backend']); $this->assertEquals(57, $json['priority']); - $this->assertContains('foopass', $json['authSchemes']); - $this->assertContains('barauth', $json['authSchemes']); + $this->assertContains('foopass', array_keys($json['authSchemes'])); + $this->assertContains('barauth', array_keys($json['authSchemes'])); } public function validateStorageProvider() { diff --git a/apps/settings/tests/Controller/UsersControllerTest.php b/apps/settings/tests/Controller/UsersControllerTest.php index e90f34d3efd..6f0bf012889 100644 --- a/apps/settings/tests/Controller/UsersControllerTest.php +++ b/apps/settings/tests/Controller/UsersControllerTest.php @@ -635,8 +635,8 @@ class UsersControllerTest extends \Test\TestCase { * @dataProvider dataTestSaveUserSettings * * @param array $data - * @param string $oldEmailAddress - * @param string $oldDisplayName + * @param ?string $oldEmailAddress + * @param ?string $oldDisplayName */ public function testSaveUserSettings($data, $oldEmailAddress, @@ -649,16 +649,14 @@ class UsersControllerTest extends \Test\TestCase { $user->method('getSystemEMailAddress')->willReturn($oldEmailAddress); $user->method('canChangeDisplayName')->willReturn(true); - if (strtolower($data[IAccountManager::PROPERTY_EMAIL]['value']) === strtolower($oldEmailAddress) || - ($oldEmailAddress === null && $data[IAccountManager::PROPERTY_EMAIL]['value'] === '')) { + if (strtolower($data[IAccountManager::PROPERTY_EMAIL]['value']) === strtolower($oldEmailAddress ?? '')) { $user->expects($this->never())->method('setSystemEMailAddress'); } else { $user->expects($this->once())->method('setSystemEMailAddress') ->with($data[IAccountManager::PROPERTY_EMAIL]['value']); } - if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName || - ($oldDisplayName === null && $data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === '')) { + if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ?? '') { $user->expects($this->never())->method('setDisplayName'); } else { $user->expects($this->once())->method('setDisplayName') diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index 8cae22daf19..dcfe9ff76b8 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -111,6 +111,10 @@ switch ($action) { \OC_JSON::error(['message' => $l->t('No data specified')]); exit; } + if (is_array($key)) { + \OC_JSON::error(['message' => $l->t('Invalid data specified')]); + exit; + } $cfg = [$key => $val]; $setParameters = []; $configuration->setConfiguration($cfg, $setParameters); diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 6b12e0edc11..1cc0c62ff1d 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -1376,7 +1376,7 @@ class Access extends LDAPUtility { $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name); if (strlen($name) > 64) { - $name = (string)hash('sha256', $name, false); + $name = hash('sha256', $name, false); } if ($name === '') { @@ -1389,7 +1389,7 @@ class Access extends LDAPUtility { public function sanitizeGroupIDCandidate(string $candidate): string { $candidate = trim($candidate); if (strlen($candidate) > 64) { - $candidate = (string)hash('sha256', $candidate, false); + $candidate = hash('sha256', $candidate, false); } if ($candidate === '') { throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters'); diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 8fbad6aae3a..3f05091a537 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -27,9 +27,9 @@ namespace OCA\User_LDAP\Mapping; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\SqlitePlatform; use OCP\DB\IPreparedStatement; use OCP\DB\QueryBuilder\IQueryBuilder; -use Doctrine\DBAL\Platforms\SqlitePlatform; /** * Class AbstractMapping @@ -191,12 +191,7 @@ abstract class AbstractMapping { * Get the hash to store in database column ldap_dn_hash for a given dn */ protected function getDNHash(string $fdn): string { - $hash = hash('sha256', $fdn, false); - if (is_string($hash)) { - return $hash; - } else { - throw new \RuntimeException('hash function did not return a string'); - } + return hash('sha256', $fdn, false); } /** diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php index fa3177b20f6..5b1d926f090 100644 --- a/apps/weather_status/lib/Service/WeatherStatusService.php +++ b/apps/weather_status/lib/Service/WeatherStatusService.php @@ -26,19 +26,19 @@ declare(strict_types=1); */ namespace OCA\WeatherStatus\Service; -use OCP\IConfig; -use OCP\IL10N; -use OCP\App\IAppManager; +use OCA\WeatherStatus\AppInfo\Application; use OCP\Accounts\IAccountManager; use OCP\Accounts\PropertyDoesNotExistException; -use OCP\IUserManager; -use OCP\Http\Client\IClientService; +use OCP\App\IAppManager; use OCP\Http\Client\IClient; -use OCP\ICacheFactory; +use OCP\Http\Client\IClientService; use OCP\ICache; +use OCP\ICacheFactory; +use OCP\IConfig; +use OCP\IL10N; use OCP\ILogger; -use OCA\WeatherStatus\AppInfo\Application; +use OCP\IUserManager; /** * Class WeatherStatusService @@ -426,8 +426,8 @@ class WeatherStatusService { $cacheDuration = 60 * 60; if (isset($headers['Expires']) && count($headers['Expires']) > 0) { // if the Expires response header is set, use it to define cache duration - $expireTs = (new \Datetime($headers['Expires'][0]))->getTimestamp(); - $nowTs = (new \Datetime())->getTimestamp(); + $expireTs = (new \DateTime($headers['Expires'][0]))->getTimestamp(); + $nowTs = (new \DateTime())->getTimestamp(); $duration = $expireTs - $nowTs; if ($duration > $cacheDuration) { $cacheDuration = $duration; diff --git a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php index 935a15af4cf..fd0d2707f8d 100644 --- a/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php +++ b/lib/private/Files/Storage/Wrapper/EncodingDirectoryWrapper.php @@ -31,7 +31,8 @@ use OC\Files\Filesystem; */ class EncodingDirectoryWrapper extends DirectoryWrapper { /** - * @return string + * @psalm-suppress ImplementedReturnTypeMismatch Until return type is fixed upstream + * @return string|false */ public function dir_readdir() { $file = readdir($this->source); diff --git a/lib/private/KnownUser/KnownUserMapper.php b/lib/private/KnownUser/KnownUserMapper.php index 864ece36345..ce7dc9ead63 100644 --- a/lib/private/KnownUser/KnownUserMapper.php +++ b/lib/private/KnownUser/KnownUserMapper.php @@ -32,7 +32,6 @@ use OCP\IDBConnection; * @method KnownUser mapRowToEntity(array $row) */ class KnownUserMapper extends QBMapper { - /** * @param IDBConnection $db */ @@ -49,7 +48,7 @@ class KnownUserMapper extends QBMapper { $query->delete($this->getTableName()) ->where($query->expr()->eq('known_to', $query->createNamedParameter($knownTo))); - return (int) $query->execute(); + return $query->executeStatement(); } /** @@ -61,7 +60,7 @@ class KnownUserMapper extends QBMapper { $query->delete($this->getTableName()) ->where($query->expr()->eq('known_user', $query->createNamedParameter($knownUser))); - return (int) $query->execute(); + return $query->executeStatement(); } /** diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 82b3c5ae760..a9c5a329620 100755 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -50,7 +50,7 @@ class LargeFileHelper { /** * @brief Checks whether our assumptions hold on the PHP platform we are on. * - * @throws \RunTimeException if our assumptions do not hold on the current + * @throws \RuntimeException if our assumptions do not hold on the current * PHP platform. */ public function __construct() { diff --git a/lib/private/Preview/Office.php b/lib/private/Preview/Office.php index 6717584e887..3ba7c5a21a0 100644 --- a/lib/private/Preview/Office.php +++ b/lib/private/Preview/Office.php @@ -71,7 +71,7 @@ abstract class Office extends ProviderV2 { [$dirname, , , $filename] = array_values(pathinfo($absPath)); $pngPreview = $tmpDir . '/' . $filename . '.png'; - $png = new \imagick($pngPreview . '[0]'); + $png = new \Imagick($pngPreview . '[0]'); $png->setImageFormat('jpg'); } catch (\Exception $e) { $this->cleanTmpFiles(); diff --git a/lib/private/legacy/OC_API.php b/lib/private/legacy/OC_API.php index 9e9c28e2dba..46ee3495572 100644 --- a/lib/private/legacy/OC_API.php +++ b/lib/private/legacy/OC_API.php @@ -98,13 +98,10 @@ class OC_API { } } - /** - * @return string - */ - public static function requestedFormat() { + public static function requestedFormat(): string { $formats = ['json', 'xml']; - $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml'; + $format = (isset($_GET['format']) && in_array($_GET['format'], $formats)) ? $_GET['format'] : 'xml'; return $format; } |