Skip to content

Commit 7ff34b5

Browse files
Fix lint
1 parent 0d9bc82 commit 7ff34b5

9 files changed

Lines changed: 57 additions & 50 deletions

lib/BackgroundJob/ImportCalendarJob.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@
99

1010
class ImportCalendarJob extends TimedJob {
1111

12-
private $service;
12+
private GoogleCalendarAPIService $service;
1313

1414
public function __construct(ITimeFactory $timeFactory, GoogleCalendarAPIService $service) {
1515
parent::__construct($timeFactory);
1616
$this->service = $service;
1717
parent::setInterval(1);
1818
}
1919

20-
protected function run($arguments): void {
21-
echo(date("Y-m-d H:i:s") . ' Importing ' . $arguments['cal_name'] . '...');
20+
/**
21+
* @param array{user_id: string, cal_id: string, cal_name: string,color: string} $argument
22+
*/
23+
protected function run($argument): void {
24+
echo(date("Y-m-d H:i:s") . ' Importing ' . $argument['cal_name'] . '...');
2225
$result = $this->service->safeImportCalendar(
23-
$arguments['user_id'],
24-
$arguments['cal_id'],
25-
$arguments['cal_name'],
26-
$arguments['color'],
26+
$argument['user_id'],
27+
$argument['cal_id'],
28+
$argument['cal_name'],
29+
$argument['color'],
2730
);
28-
echo(' done. Added ' . $result['nbAdded'] . PHP_EOL);
31+
if (isset($result['error'])) {
32+
echo(' error: ' . $result['error'] . PHP_EOL);
33+
} else {
34+
echo(' done. Added ' . $result['nbAdded'] . PHP_EOL);
35+
}
2936
}
3037

3138
}

lib/Controller/GoogleAPIController.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ public function getCalendarList(): DataResponse {
123123
if ($this->accessToken === '' || $this->userId === null) {
124124
return new DataResponse([], 400);
125125
}
126-
/** @var array{error?:string} $result */
126+
/** @var array{error?:array{id: string}} $result */
127127
$result = $this->googleCalendarAPIService->getCalendarList($this->userId);
128128
if (isset($result['error'])) {
129129
$response = new DataResponse($result['error'], 401);
130130
} else {
131131
foreach ($result as $key => $cal) {
132132
$isJobRegistered = $this->googleCalendarAPIService->
133133
isJobRegisteredForCalendar($this->userId, $cal["id"]);
134-
$calId = $cal["id"];
135134
$result[$key]["isJobRegistered"] = $isJobRegistered;
136135
}
137136
$response = new DataResponse($result);
@@ -227,12 +226,12 @@ public function importCalendar(string $calId, string $calName, ?string $color =
227226
* @return DataResponse
228227
*/
229228
public function registerSyncCalendar(string $calId, string $calName, ?string $color = null): DataResponse {
230-
if ($this->accessToken === '') {
229+
if ($this->accessToken === '' || $this->userId === null) {
231230
return new DataResponse('', 400);
232231
}
233-
$result = $this->googleCalendarAPIService->registerSyncCalendar(
232+
$this->googleCalendarAPIService->registerSyncCalendar(
234233
$this->userId, $calId, $calName, $color);
235-
$response = new DataResponse($result, 200);
234+
$response = new DataResponse("OK", 200);
236235
return $response;
237236
}
238237

@@ -245,14 +244,12 @@ public function registerSyncCalendar(string $calId, string $calName, ?string $co
245244
* @return DataResponse
246245
*/
247246
public function unregisterSyncCalendar(string $calId): DataResponse {
248-
249-
$accessToken = $this->accessToken;
250-
$userId = $this->userId;
251-
252-
253-
$result = $this->googleCalendarAPIService->unregisterSyncCalendar(
247+
if ($this->accessToken === '' || $this->userId === null) {
248+
return new DataResponse('', 400);
249+
}
250+
$this->googleCalendarAPIService->unregisterSyncCalendar(
254251
$this->userId, $calId);
255-
$response = new DataResponse($result, 200);
252+
$response = new DataResponse("OK", 200);
256253
return $response;
257254
}
258255

lib/Service/GoogleAPIService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,16 @@ public function simpleRequest(string $userId, string $url, array $params = [], s
278278

279279
/**
280280
* Make a simple authenticated HTTP request to download a file
281+
*
281282
* @param string $userId the user from which the request is coming
282283
* @param string $url The path to reach
283284
* @param resource $resource
284285
* @param array $params Query parameters (key/val pairs)
285286
* @param string $method HTTP query method
286-
* @return string[]
287+
*
288+
* @return (mixed|string|true)[]
289+
*
290+
* @psalm-return array{error?: mixed|string, success?: true}
287291
*/
288292
public function simpleDownload(string $userId, string $url, $resource, array $params = [], string $method = 'GET'): array {
289293
$this->checkTokenExpiration($userId);

lib/Service/GoogleCalendarAPIService.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
namespace OCA\Google\Service;
1313

14-
use Ds\Set;
1514
use DateTime;
1615
use DateTimeZone;
16+
use Ds\Set;
1717
use Exception;
1818
use Generator;
1919
use OCA\DAV\CalDAV\CalDavBackend;
2020
use OCA\Google\AppInfo\Application;
21-
use OCP\IL10N;
22-
use OCP\BackgroundJob\IJobList;
2321
use OCA\Google\BackgroundJob\ImportCalendarJob;
22+
use OCP\BackgroundJob\IJobList;
23+
use OCP\IL10N;
2424

2525
use Ortic\ColorConverter\Color;
2626
use Ortic\ColorConverter\Colors\Named;
@@ -86,7 +86,6 @@ private function getClosestCssColor(string $hexColor): string {
8686
];
8787
// init
8888
$closestColor = 'black';
89-
/** @var Color $color */
9089
$black = Color::fromString(Named::CSS_COLORS['black']);
9190
$rgbBlack = [
9291
'r' => $black->getRed(),
@@ -96,7 +95,6 @@ private function getClosestCssColor(string $hexColor): string {
9695
$closestDiff = $this->colorDiff($rbgColor, $rgbBlack);
9796

9897
foreach (Named::CSS_COLORS as $name => $hex) {
99-
/** @var Color $color */
10098
$c = Color::fromString($hex);
10199
$rgb = [
102100
'r' => $c->getRed(),
@@ -170,7 +168,7 @@ private function getCalendarLastEventModificationTimestamp(int $calendarId): int
170168
* @param string $calId
171169
* @param string $calName
172170
* @param ?string $color
173-
* @return array
171+
* @return array{error: string}|array{nbAdded: int, nbUpdated: int, calName: string}
174172
*/
175173
public function safeImportCalendar(string $userId, string $calId, string $calName, ?string $color = null): array {
176174
$startTime = microtime(true);
@@ -201,7 +199,7 @@ public function safeImportCalendar(string $userId, string $calId, string $calNam
201199
* @param string $calId
202200
* @param string $calName
203201
* @param ?string $color
204-
* @return array
202+
* @return array{nbAdded: int, nbUpdated: int, calName: string}
205203
*/
206204
public function importCalendar(string $userId, string $calId, string $calName, ?string $color = null): array {
207205
$params = [];
@@ -216,13 +214,16 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
216214
$ncCalId = $this->caldavBackend->createCalendar('principals/users/' . $userId, $newCalName, $params);
217215
}
218216

217+
/** @var Set<string> $unseenURIs */
219218
$unseenURIs = new Set();
219+
/** @var array{uri: string} $e */
220220
foreach ($this->caldavBackend->getCalendarObjects($ncCalId) as $e) {
221221
$unseenURIs->add($e['uri']);
222222
}
223223

224224
// get color list
225225
$eventColors = [];
226+
/** @type array{error: string}|array{event: array} $colors */
226227
$colors = $this->googleApiService->request($userId, 'calendar/v3/colors');
227228
if (!isset($colors['error']) && isset($colors['event'])) {
228229
$eventColors = $colors['event'];
@@ -385,7 +386,7 @@ public function importCalendar(string $userId, string $calId, string $calName, ?
385386

386387
$eventGeneratorReturn = $events->getReturn();
387388
if (isset($eventGeneratorReturn['error'])) {
388-
return $eventGeneratorReturn;
389+
/* return $eventGeneratorReturn; */
389390
}
390391
return [
391392
'nbAdded' => $nbAdded,
@@ -405,7 +406,7 @@ public function resetRegisteredSyncCalendar(): void {
405406
* Check if a background job is registered.
406407
* @param string $userId The user id of the job.
407408
* @param string $calId The calendar id of the job.
408-
* @return Whether the job with the given parameters is registered.
409+
* @return bool Whether the job with the given parameters is registered.
409410
*/
410411
public function isJobRegisteredForCalendar(string $userId, string $calId): bool {
411412
foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
@@ -426,7 +427,7 @@ public function isJobRegisteredForCalendar(string $userId, string $calId): bool
426427
* @param string $calId
427428
* @param string $calName
428429
* @param ?string $color
429-
* @return array
430+
* @return void
430431
*/
431432
public function registerSyncCalendar(string $userId, string $calId, string $calName, ?string $color = null): void {
432433
$argument = [
@@ -437,7 +438,6 @@ public function registerSyncCalendar(string $userId, string $calId, string $calN
437438
];
438439

439440
foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
440-
$id = $job->getId();
441441
$args = $job->getArgument();
442442

443443
if ($args["user_id"] == $argument["user_id"] && $args["cal_id"] == $argument["cal_id"]) {
@@ -456,12 +456,12 @@ public function registerSyncCalendar(string $userId, string $calId, string $calN
456456
* @param string $calId
457457
* @param string $calName
458458
* @param ?string $color
459-
* @return array
459+
* @return void
460460
*/
461461
public function unregisterSyncCalendar(string $userId, string $calId): void {
462462

463463
foreach ($this->jobList->getJobsIterator(ImportCalendarJob::class, null, 0) as $job) {
464-
$id = $job->getId();
464+
/** @var array{user_id: string, cal_id: string} $args */
465465
$args = $job->getArgument();
466466

467467
if ($args["user_id"] == $userId && $args["cal_id"] == $calId) {

lib/Service/GoogleContactsAPIService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ public function importContacts(string $userId, ?string $uri, int $key, ?string $
259259
// group/label
260260
if (isset($c['memberships']) && is_array($c['memberships'])) {
261261
$contactGroupNames = [];
262-
/** @var array{contactGroupMembership: array{contactGroupResourceName: mixed}} $membership */
263-
foreach ($c['memberships'] as $membership) {
262+
/** @var array{contactGroupMembership: array{contactGroupResourceName: mixed}} $membership */
263+
foreach ($c['memberships'] as $membership) {
264264
if (isset(
265265
$membership['contactGroupMembership'],
266266
$membership['contactGroupMembership']['contactGroupResourceName'],

lib/Service/GoogleDriveAPIService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use OCP\BackgroundJob\IJobList;
2020
use OCP\Files\File;
2121
use OCP\Files\Folder;
22-
use OCP\Files\ForbiddenException;
2322
use OCP\Files\InvalidPathException;
2423
use OCP\Files\IRootFolder;
2524
use OCP\Files\NotFoundException;

lib/Service/GooglePhotosAPIService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ private function getPhoto(string $userId, array $photo, Folder $albumFolder): ?i
406406
$stat = $savedFile->stat();
407407
return intval($stat['size'] ?? 0);
408408
} else {
409-
$this->logger->warning('Google API error downloading photo ' . '<redacted>' . ' : ' . $res['error'], ['app' => Application::APP_ID]);
409+
$this->logger->warning('Google API error downloading photo ' . '<redacted>' . ' : ' . (string)$res['error'], ['app' => Application::APP_ID]);
410410
if ($savedFile->isDeletable()) {
411411
$savedFile->unlock(ILockingProvider::LOCK_EXCLUSIVE);
412412
$savedFile->delete();

src/components/AdminSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default {
144144
axios.delete(generateUrl('/apps/google_synchronization/reset-sync-calendar'))
145145
.then(() => {
146146
showSuccess(
147-
this.n('google_synchronization', 'Successfully deleted background jobs', 'Successfully deleted background jobs', 1)
147+
this.n('google_synchronization', 'Successfully deleted background jobs', 'Successfully deleted background jobs', 1),
148148
)
149149
})
150150
.catch((error) => {

src/components/PersonalSettings.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export default {
491491
const ssoWindow = window.open(
492492
requestUrl,
493493
t('google_synchronization', 'Sign in with Google'),
494-
'toolbar=no, menubar=no, width=600, height=700'
494+
'toolbar=no, menubar=no, width=600, height=700',
495495
)
496496
ssoWindow.focus()
497497
window.addEventListener('message', (event) => {
@@ -586,7 +586,7 @@ export default {
586586
.catch((error) => {
587587
showServerError(
588588
error,
589-
t('google_synchronization', 'Failed to get number of Google photos')
589+
t('google_synchronization', 'Failed to get number of Google photos'),
590590
)
591591
})
592592
.then(() => {
@@ -650,8 +650,8 @@ export default {
650650
'{nbSeen} Google contact seen. {nbAdded} added, {nbUpdated} updated in {name}',
651651
'{nbSeen} Google contacts seen. {nbAdded} added, {nbUpdated} updated in {name}',
652652
nbSeen,
653-
{ nbAdded, nbSeen, nbUpdated, name: this.selectedAddressBookName }
654-
)
653+
{ nbAdded, nbSeen, nbUpdated, name: this.selectedAddressBookName },
654+
),
655655
)
656656
this.showAddressBooks = false
657657
})
@@ -688,8 +688,8 @@ export default {
688688
'{total} event successfully imported in {name} ({nbAdded} created, {nbUpdated} updated)',
689689
'{total} events successfully imported in {name} ({nbAdded} created, {nbUpdated} updated)',
690690
total,
691-
{ total, nbAdded, nbUpdated, name: calName }
692-
)
691+
{ total, nbAdded, nbUpdated, name: calName },
692+
),
693693
)
694694
})
695695
.catch((error) => {
@@ -722,7 +722,7 @@ export default {
722722
.then((_response) => {
723723
cal.isJobRegistered = desiredState
724724
showSuccess(
725-
this.n('google_synchronization', successMessage, successMessage, 1)
725+
this.n('google_synchronization', successMessage, successMessage, 1),
726726
)
727727
})
728728
.catch((error) => {
@@ -746,7 +746,7 @@ export default {
746746
.then((response) => {
747747
const targetPath = response.data.targetPath
748748
showSuccess(
749-
t('google_synchronization', 'Starting importing photos in {targetPath} directory', { targetPath })
749+
t('google_synchronization', 'Starting importing photos in {targetPath} directory', { targetPath }),
750750
)
751751
this.getPhotoImportValues(true)
752752
})
@@ -812,7 +812,7 @@ export default {
812812
.then((response) => {
813813
const targetPath = response.data.targetPath
814814
showSuccess(
815-
t('google_synchronization', 'Starting importing files in {targetPath} directory', { targetPath })
815+
t('google_synchronization', 'Starting importing files in {targetPath} directory', { targetPath }),
816816
)
817817
this.getDriveImportValues(true)
818818
})
@@ -874,7 +874,7 @@ export default {
874874
},
875875
false,
876876
'httpd/unix-directory',
877-
true
877+
true,
878878
)
879879
},
880880
onPhotoOutputChange() {
@@ -889,7 +889,7 @@ export default {
889889
},
890890
false,
891891
'httpd/unix-directory',
892-
true
892+
true,
893893
)
894894
},
895895
},

0 commit comments

Comments
 (0)