Skip to content

Commit 9139e05

Browse files
marcelklehrMarcelRobitaille
authored andcommitted
fix(psalm)
1 parent 441c9a3 commit 9139e05

7 files changed

Lines changed: 285 additions & 347 deletions

File tree

lib/Controller/ConfigController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public function setConfig(array $values): DataResponse {
7676
$result['user_name'] = '';
7777
} else {
7878
if (isset($values['drive_output_dir'])) {
79-
/** @var \OCP\Files\IRootFolder $root */
80-
$root = \OC::$server->get(\OCP\Files\IRootFolder::class);
79+
$root = \OCP\Server::get(\OCP\Files\IRootFolder::class);
8180
$userRoot = $root->getUserFolder($this->userId);
8281
$result['free_space'] = \OCA\Google\Settings\Personal::getFreeSpace($userRoot, $values['drive_output_dir']);
8382
}

lib/Service/GoogleCalendarAPIService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
234234
$nbAdded = 0;
235235
$nbUpdated = 0;
236236

237+
/** @var array{id: string, start?: array{date?: string, dateTime?: string}, end?: array{date?: string, dateTime?: string}, colorId?: string, summary?: string, visibility?: string, sequence?: string, location?: string, description?: string, status?: string, created?: string, updated?: string, reminders?: array{useDefault?: bool, overrides?: list{array{minutes?: string, hours?: string, days?: string, weeks?: string}}}, recurrence?: list<string>} $e */
237238
foreach ($events as $e) {
238239
$objectUri = $e['id'];
239240

@@ -249,6 +250,9 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
249250
// check if it already exists and if we should update it
250251
$existingEvent = $this->caldavBackend->getCalendarObject($ncCalId, $objectUri);
251252
if ($existingEvent !== null) {
253+
if (!isset($e['updated'])) {
254+
continue;
255+
}
252256
$remoteEventUpdatedTimestamp = (new DateTime($e['updated']))->getTimestamp();
253257
$localEventUpdatedTimestamp = $this->getEventLastModifiedTimestamp($existingEvent['calendardata']);
254258
if ($localEventUpdatedTimestamp !== null && $remoteEventUpdatedTimestamp <= $localEventUpdatedTimestamp) {
@@ -269,7 +273,7 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
269273
}
270274
$calData .= isset($e['summary'])
271275
? ('SUMMARY:' . substr(str_replace("\n", '\n', $e['summary']), 0, 250) . "\n")
272-
: ($e['visibility'] ?? '' === 'private'
276+
: (($e['visibility'] ?? '') === 'private'
273277
? ('SUMMARY:' . $this->l10n->t('Private event') . "\n")
274278
: '');
275279
$calData .= isset($e['sequence']) ? ('SEQUENCE:' . $e['sequence'] . "\n") : '';

lib/Service/GoogleContactsAPIService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
210210
$displayName = '';
211211
// we just take first name
212212
if (isset($c['names']) && is_array($c['names'])) {
213+
/** @var array{displayName?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string } $n */
213214
foreach ($c['names'] as $n) {
214215
$displayName = $n['displayName'] ?? '';
215216
$familyName = $n['familyName'] ?? '';
@@ -324,6 +325,7 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
324325

325326
// address
326327
if (isset($c['addresses']) && is_array($c['addresses'])) {
328+
/** @var array{streetAddress?: string, extendedAddress?: string, postalCode?: string, city?: string, type?: string, country?: string, poBox?: string} $address */
327329
foreach ($c['addresses'] as $address) {
328330
$streetAddress = $address['streetAddress'] ?? '';
329331
$extendedAddress = $address['extendedAddress'] ?? '';
@@ -380,6 +382,7 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
380382
}
381383

382384
if (isset($c['emailAddresses']) && is_array($c['emailAddresses'])) {
385+
/** @var array{value?: string, type?: string} $email */
383386
foreach ($c['emailAddresses'] as $email) {
384387
if (isset($email['value'])) {
385388
$addrType = $email['type'] ?? '';
@@ -405,6 +408,7 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
405408

406409
// we just take first org
407410
if (isset($c['organizations']) && is_array($c['organizations'])) {
411+
/** @var array{title?: string, name?: string} $org */
408412
foreach ($c['organizations'] as $org) {
409413
$name = $org['name'] ?? '';
410414
if ($name) {

lib/Service/GoogleDriveAPIService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public function importFiles(
329329
$fileName = $this->getFileName($fileItem, $userId, in_array($fileItem['id'], $conflictingIds));
330330

331331
// If file already exists in folder, don't download unless timestamp is different
332-
if ($saveFolder->nodeExists($fileName)) {
332+
if ($saveFolder->nodeExists($fileName) === true) {
333333
$savedFile = $saveFolder->get($fileName);
334334
$timestampOnFile = $savedFile->getMtime();
335335
$d = new DateTime($fileItem['modifiedTime']);
@@ -349,7 +349,7 @@ public function importFiles(
349349
$this->config->setUserValue($userId, Application::APP_ID, 'nb_imported_files', $alreadyImported + $nbDownloaded);
350350
$downloadedSize += $size;
351351
$this->config->setUserValue($userId, Application::APP_ID, 'drive_imported_size', $alreadyImportedSize + $downloadedSize);
352-
if ($maxDownloadSize && $downloadedSize > $maxDownloadSize) {
352+
if ($maxDownloadSize !== null && $downloadedSize > $maxDownloadSize) {
353353
return [
354354
'nbDownloaded' => $nbDownloaded,
355355
'targetPath' => $targetPath,
@@ -362,7 +362,7 @@ public function importFiles(
362362
}
363363
} catch (\Throwable $e) {
364364
$this->logger->warning('Error while importing file', ['exception' => $e]);
365-
$this->logger->debug('Skipping file ' . $fileItem['id']);
365+
$this->logger->debug('Skipping file ' . strval($fileItem['id']));
366366
continue;
367367
}
368368
}
@@ -692,11 +692,11 @@ private function getFile(string $userId, array $fileItem, Folder $saveFolder, st
692692
$documentFormat = $this->getUserDocumentFormat($userId);
693693
// potentially a doc
694694
$params = $this->getDocumentRequestParams($fileItem['mimeType'], $documentFormat);
695-
$fileUrl = 'https://www.googleapis.com/drive/v3/files/' . urlencode($fileItem['id']) . '/export';
695+
$fileUrl = 'https://www.googleapis.com/drive/v3/files/' . urlencode((string) $fileItem['id']) . '/export';
696696
return $this->downloadAndSaveFile($saveFolder, $fileName, $userId, $fileUrl, $fileItem, $params);
697697
} elseif (isset($fileItem['webContentLink'])) {
698698
// classic file
699-
$fileUrl = 'https://www.googleapis.com/drive/v3/files/' . urlencode($fileItem['id']) . '?alt=media';
699+
$fileUrl = 'https://www.googleapis.com/drive/v3/files/' . urlencode((string) $fileItem['id']) . '?alt=media';
700700
return $this->downloadAndSaveFile($saveFolder, $fileName, $userId, $fileUrl, $fileItem);
701701
}
702702
return null;

lib/Service/GooglePhotosAPIService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public function importPhotos(
303303
$nbDownloaded++;
304304
$this->config->setUserValue($userId, Application::APP_ID, 'nb_imported_photos', $alreadyImported + $nbDownloaded);
305305
$downloadedSize += $size;
306-
if ($maxDownloadSize && $downloadedSize > $maxDownloadSize) {
306+
if ($maxDownloadSize !== null && $downloadedSize > $maxDownloadSize) {
307307
return [
308308
'nbDownloaded' => $nbDownloaded,
309309
'targetPath' => $targetPath,
@@ -337,7 +337,7 @@ public function importPhotos(
337337
$nbDownloaded++;
338338
$this->config->setUserValue($userId, Application::APP_ID, 'nb_imported_photos', $alreadyImported + $nbDownloaded);
339339
$downloadedSize += $size;
340-
if ($maxDownloadSize && $downloadedSize > $maxDownloadSize) {
340+
if ($maxDownloadSize !== null && $downloadedSize > $maxDownloadSize) {
341341
return [
342342
'nbDownloaded' => $nbDownloaded,
343343
'targetPath' => $targetPath,

lib/Settings/Personal.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public function getPriority(): int {
9898
return 10;
9999
}
100100

101+
/**
102+
* @param \OCP\Files\Folder $userRoot
103+
* @param string $outputDir
104+
* @return bool|float|int
105+
* @throws NotFoundException
106+
*/
101107
public static function getFreeSpace(\OCP\Files\Folder $userRoot, string $outputDir) {
102108
try {
103109
// OutputDir can be on an external storage which can have more free space

0 commit comments

Comments
 (0)