Merge pull request #35943 from nextcloud/fix/code-fixes-from-34997

Code fixes from PR 34997
This commit is contained in:
Côme Chilliet 2023-01-03 14:32:31 +01:00 committed by GitHub
commit 06da8adcd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 42 additions and 51 deletions

View file

@ -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)',

View file

@ -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;

View file

@ -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() {

View file

@ -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')

View file

@ -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);

View file

@ -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');

View file

@ -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);
}
/**

View file

@ -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;

View file

@ -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);

View file

@ -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();
}
/**

View file

@ -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() {

View file

@ -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();

View file

@ -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;
}