Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: Run rector type coverage level 10
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed May 19, 2025
commit 2d01c77629bc251eccca9eba64d5b476b93ba371
18 changes: 9 additions & 9 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getForUser(string $userId): array {
->from('photos_albums')
->where($query->expr()->eq('user', $query->createNamedParameter($userId)));
$rows = $query->executeQuery()->fetchAll();
return array_map(fn (array $row) => new AlbumInfo((int)$row['album_id'], $userId, $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
return array_map(fn (array $row): \OCA\Photos\Album\AlbumInfo => new AlbumInfo((int)$row['album_id'], $userId, $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getForFile(int $fileId): array {
->leftJoin('a', 'photos_albums_files', 'p', $query->expr()->eq('a.album_id', 'p.album_id'))
->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$rows = $query->executeQuery()->fetchAll();
return array_map(fn (array $row) => new AlbumInfo((int)$row['album_id'], $row['user'], $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
return array_map(fn (array $row): \OCA\Photos\Album\AlbumInfo => new AlbumInfo((int)$row['album_id'], $row['user'], $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
}

/**
Expand All @@ -140,7 +140,7 @@ public function getForUserAndFile(string $userId, int $fileId): array {
->where($query->expr()->eq('user', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$rows = $query->executeQuery()->fetchAll();
return array_map(fn (array $row) => new AlbumInfo((int)$row['album_id'], $row['user'], $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
return array_map(fn (array $row): \OCA\Photos\Album\AlbumInfo => new AlbumInfo((int)$row['album_id'], $row['user'], $row['name'], $row['location'], (int)$row['created'], (int)$row['last_added_photo']), $rows);
}

public function rename(int $id, string $newName): void {
Expand Down Expand Up @@ -364,7 +364,7 @@ public function getCollaborators(int $albumId): array {
];
}, $rows);

return array_values(array_filter($collaborators, fn ($c) => $c !== null));
return array_values(array_filter($collaborators, fn ($c): bool => $c !== null));
}


Expand Down Expand Up @@ -409,10 +409,10 @@ public function setCollaborators(int $albumId, array $collaborators): void {
$existingCollaborators = $this->getCollaborators($albumId);

// Different behavior if type is link to prevent creating multiple link.
$computeKey = (fn ($c) => ($c['type'] === AlbumMapper::TYPE_LINK ? '' : $c['id']) . $c['type']);
$computeKey = (fn ($c): string => ($c['type'] === AlbumMapper::TYPE_LINK ? '' : $c['id']) . $c['type']);

$collaboratorsToAdd = array_udiff($collaborators, $existingCollaborators, fn ($a, $b) => strcmp($computeKey($a), $computeKey($b)));
$collaboratorsToRemove = array_udiff($existingCollaborators, $collaborators, fn ($a, $b) => strcmp($computeKey($a), $computeKey($b)));
$collaboratorsToAdd = array_udiff($collaborators, $existingCollaborators, fn ($a, $b): int => strcmp($computeKey($a), $computeKey($b)));
$collaboratorsToRemove = array_udiff($existingCollaborators, $collaborators, fn ($a, $b): int => strcmp($computeKey($a), $computeKey($b)));

$this->connection->beginTransaction();

Expand Down Expand Up @@ -477,7 +477,7 @@ public function getSharedAlbumsForCollaborator(string $collaboratorId, int $coll
->executeQuery()
->fetchAll();

return array_map(fn (array $row) => new AlbumInfo(
return array_map(fn (array $row): \OCA\Photos\Album\AlbumInfo => new AlbumInfo(
(int)$row['album_id'],
$row['user'],
$row['name'] . ' (' . $row['user'] . ')',
Expand Down Expand Up @@ -587,7 +587,7 @@ public function getAlbumsForCollaboratorIdAndFileId(string $collaboratorId, int
->fetchAll();


return array_map(fn (array $row) => new AlbumInfo(
return array_map(fn (array $row): \OCA\Photos\Album\AlbumInfo => new AlbumInfo(
(int)$row['album_id'],
$row['user'],
$row['name'] . ' (' . $row['user'] . ')',
Expand Down
2 changes: 1 addition & 1 deletion lib/Album/AlbumWithFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function addFile(AlbumFile $file): array {
* @return int[]
*/
public function getFileIds(): array {
return array_map(fn (AlbumFile $file) => $file->getFileId(), $this->getFiles());
return array_map(fn (AlbumFile $file): int => $file->getFileId(), $this->getFiles());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function index(): TemplateResponse {
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.nomedia'),
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.noimage')
]), 0, 0, [], $user));
$paths = array_map(fn (Node $node) => substr(dirname($node->getPath()), strlen((string)$userFolder->getPath())), $search);
$paths = array_map(fn (Node $node): string => substr(dirname($node->getPath()), strlen((string)$userFolder->getPath())), $search);
$this->nomediaPathsCache->set($key, $paths, 60 * 60 * 24 * 28); // 28 days
}
} catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function ($node) {

if (\count($nodes) === 0) {
$receivedAlbums = $this->albumMapper->getAlbumsForCollaboratorIdAndFileId($user->getUID(), AlbumMapper::TYPE_USER, $fileId);
$receivedAlbums = array_udiff($receivedAlbums, $checkedAlbums, fn ($a, $b) => ($a->getId() - $b->getId()));
$receivedAlbums = array_udiff($receivedAlbums, $checkedAlbums, fn ($a, $b): int => ($a->getId() - $b->getId()));
$nodes = $this->getFileIdForAlbums($fileId, $receivedAlbums);
$checkedAlbums = array_merge($checkedAlbums, $receivedAlbums);
}
Expand All @@ -105,7 +105,7 @@ function ($node) {
$userGroups = $this->groupManager->getUserGroupIds($user);
foreach ($userGroups as $groupId) {
$albumsForGroup = $this->albumMapper->getAlbumsForCollaboratorIdAndFileId($groupId, AlbumMapper::TYPE_GROUP, $fileId);
$albumsForGroup = array_udiff($albumsForGroup, $checkedAlbums, fn ($a, $b) => ($a->getId() - $b->getId()));
$albumsForGroup = array_udiff($albumsForGroup, $checkedAlbums, fn ($a, $b): int => ($a->getId() - $b->getId()));
$nodes = $this->getFileIdForAlbums($fileId, $albumsForGroup);
$checkedAlbums = array_merge($checkedAlbums, $receivedAlbums);
if (\count($nodes) !== 0) {
Expand Down
4 changes: 2 additions & 2 deletions lib/DB/Place/PlaceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function findPlacesForUser(string $userId): array {
->executeQuery()
->fetchAll();

return array_map(fn ($row) => new PlaceInfo($userId, $row['meta_value_string']), $rows);
return array_map(fn ($row): \OCA\Photos\DB\Place\PlaceInfo => new PlaceInfo($userId, $row['meta_value_string']), $rows);
}

/** @return PlaceInfo */
Expand Down Expand Up @@ -104,7 +104,7 @@ public function findFilesForUserAndPlace(string $userId, string $place) {
->fetchAll();

return array_map(
fn ($row) => new PlaceFile(
fn ($row): \OCA\Photos\DB\Place\PlaceFile => new PlaceFile(
(int)$row['fileid'],
$row['name'],
$this->mimeTypeLoader->getMimetypeById($row['mimetype']),
Expand Down
4 changes: 2 additions & 2 deletions lib/Listener/AlbumsManagementEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function handle(Event $event): void {
// Get all albums shared with this specific user:
$albums_user = $this->albumMapper->getSharedAlbumsForCollaborator($event->getUser()->getUID(), AlbumMapper::TYPE_USER);
// Get all group-shared albums that are not directly shared with the removed user in addition
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getId() - $b->getId()));
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b): int => ($a->getId() - $b->getId()));

// Remove their photos from theses albums:
foreach ($albums as $album) {
Expand All @@ -87,7 +87,7 @@ public function handle(Event $event): void {
$albums_user = $this->albumMapper->getSharedAlbumsForCollaborator($user->getUID(), AlbumMapper::TYPE_USER);

// Get all group-shared albums that are not directly shared with the removed user in addition
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b) => ($a->getId() - $b->getId()));
$albums = array_udiff($albums_group, $albums_user, fn ($a, $b): int => ($a->getId() - $b->getId()));

// Remove their photos from theses albums:
foreach ($albums as $album) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Listener/ExifMetadataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function gpsDegreesToDecimal($coordinates, ?string $hemisphere): float {
throw new \Exception('Invalid coordinate format: ' . json_encode($coordinates));
}

[$degrees, $minutes, $seconds] = array_map(fn ($rawDegree) => $this->parseGPSData($rawDegree), $coordinates);
[$degrees, $minutes, $seconds] = array_map(fn ($rawDegree): float => $this->parseGPSData($rawDegree), $coordinates);

$sign = ($hemisphere === 'W' || $hemisphere === 'S') ? -1 : 1;
return $sign * ($degrees + $minutes / 60 + $seconds / 3600);
Expand Down
2 changes: 1 addition & 1 deletion lib/RepairStep/InitMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
) {
}

public function getName() {
public function getName(): string {
return 'init metadata';
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Sabre/Album/AlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function createDirectory($name): never {
* @return AlbumPhoto[]
*/
public function getChildren(): array {
return array_map(fn (AlbumFile $file) => new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)), $this->album->getFiles());
return array_map(fn (AlbumFile $file): \OCA\Photos\Sabre\Album\AlbumPhoto => new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)), $this->album->getFiles());
}

public function getChild($name): AlbumPhoto {
Expand Down Expand Up @@ -212,7 +212,7 @@ public function getCover() {
*/
public function getCollaborators(): array {
return array_map(
fn (array $collaborator) => [ 'nc:collaborator' => $collaborator ],
fn (array $collaborator): array => [ 'nc:collaborator' => $collaborator ],
$this->albumMapper->getCollaborators($this->album->getAlbum()->getId()),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Album/AlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getChild($name) {
public function getChildren(): array {
if ($this->children === null) {
$albumInfos = $this->albumMapper->getForUser($this->userId);
$this->children = array_map(fn (AlbumInfo $albumInfo) => new AlbumRoot(
$this->children = array_map(fn (AlbumInfo $albumInfo): \OCA\Photos\Sabre\Album\AlbumRoot => new AlbumRoot(
$this->albumMapper,
new AlbumWithFiles($albumInfo, $this->albumMapper),
$this->rootFolder,
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Album/PublicAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setCollaborators($collaborators): array {
}

public function getChildren(): array {
return array_map(fn (AlbumFile $file) => new PublicAlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)), $this->album->getFiles());
return array_map(fn (AlbumFile $file): \OCA\Photos\Sabre\Album\PublicAlbumPhoto => new PublicAlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)), $this->album->getFiles());
}

public function getChild($name): PublicAlbumPhoto {
Expand Down
4 changes: 2 additions & 2 deletions lib/Sabre/Album/SharedAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function getChildren(): array {
$userGroups = $this->groupManager->getUserGroupIds($user);
foreach ($userGroups as $groupId) {
$albumsForGroup = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($groupId, AlbumMapper::TYPE_GROUP);
$albumsForGroup = array_udiff($albumsForGroup, $albums, fn ($a, $b) => $a->getAlbum()->getId() - $b->getAlbum()->getId());
$albumsForGroup = array_udiff($albumsForGroup, $albums, fn ($a, $b): int => $a->getAlbum()->getId() - $b->getAlbum()->getId());
$albums = array_merge($albums, $albumsForGroup);
}

$this->children = array_map(fn (AlbumWithFiles $album) => new SharedAlbumRoot(
$this->children = array_map(fn (AlbumWithFiles $album): \OCA\Photos\Sabre\Album\SharedAlbumRoot => new SharedAlbumRoot(
$this->albumMapper,
$album,
$this->rootFolder,
Expand Down
4 changes: 2 additions & 2 deletions lib/Sabre/Place/PlaceRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function createDirectory($name): never {
public function getChildren(): array {
if ($this->children === null) {
$this->children = array_map(
fn (PlaceFile $file) => new PlacePhoto($this->placeInfo, $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)),
fn (PlaceFile $file): \OCA\Photos\Sabre\Place\PlacePhoto => new PlacePhoto($this->placeInfo, $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId)),
$this->placeMapper->findFilesForUserAndPlace($this->placeInfo->getUserId(), $this->placeInfo->getPlace())
);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function getFirstPhoto(): int {
* @return int[]
*/
public function getFileIds(): array {
return array_map(fn (PlacePhoto $file) => $file->getFileId(), $this->getChildren());
return array_map(fn (PlacePhoto $file): int => $file->getFileId(), $this->getChildren());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Place/PlacesHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getChild($name): PlaceRoot {
public function getChildren(): array {
if ($this->children === null) {
$this->children = array_map(
fn (PlaceInfo $placeInfo) => new PlaceRoot($this->placeMapper, $this->reverseGeoCoderService, $placeInfo, $this->userId, $this->rootFolder),
fn (PlaceInfo $placeInfo): \OCA\Photos\Sabre\Place\PlaceRoot => new PlaceRoot($this->placeMapper, $this->reverseGeoCoderService, $placeInfo, $this->userId, $this->rootFolder),
$this->placeMapper->findPlacesForUser($this->userId)
);
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Sabre/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function propFind(PropFind $propFind, INode $node): void {
return;
}

$propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn () => $node->getFile()->getFileId());
$propFind->handle(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, fn (): int => $node->getFile()->getFileId());
$propFind->handle(FilesPlugin::GETETAG_PROPERTYNAME, fn () => $node->getETag());
$propFind->handle(self::FILE_NAME_PROPERTYNAME, fn () => $node->getFile()->getName());
$propFind->handle(self::FAVORITE_PROPERTYNAME, fn () => $node->isFavorite() ? 1 : 0);
$propFind->handle(self::FILE_NAME_PROPERTYNAME, fn (): string => $node->getFile()->getName());
$propFind->handle(self::FAVORITE_PROPERTYNAME, fn (): int => $node->isFavorite() ? 1 : 0);
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => json_encode($this->previewManager->isAvailable($fileInfo)));
$propFind->handle(FilesPlugin::PERMISSIONS_PROPERTYNAME, function () use ($node): string {
$permissions = DavUtil::getDavPermissions($node->getFileInfo());
Expand All @@ -111,17 +111,17 @@ public function propFind(PropFind $propFind, INode $node): void {
}

if ($node instanceof AlbumRoot) {
$propFind->handle(self::ORIGINAL_NAME_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getTitle());
$propFind->handle(self::LAST_PHOTO_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getLastAddedPhoto());
$propFind->handle(self::NBITEMS_PROPERTYNAME, fn () => count($node->getChildren()));
$propFind->handle(self::LOCATION_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getLocation());
$propFind->handle(self::ORIGINAL_NAME_PROPERTYNAME, fn (): string => $node->getAlbum()->getAlbum()->getTitle());
$propFind->handle(self::LAST_PHOTO_PROPERTYNAME, fn (): int => $node->getAlbum()->getAlbum()->getLastAddedPhoto());
$propFind->handle(self::NBITEMS_PROPERTYNAME, fn (): int => count($node->getChildren()));
$propFind->handle(self::LOCATION_PROPERTYNAME, fn (): string => $node->getAlbum()->getAlbum()->getLocation());
$propFind->handle(self::DATE_RANGE_PROPERTYNAME, fn () => json_encode($node->getDateRange()));
$propFind->handle(self::COLLABORATORS_PROPERTYNAME, fn () => $node->getCollaborators());
$propFind->handle(self::COLLABORATORS_PROPERTYNAME, fn (): array => $node->getCollaborators());
}

if ($node instanceof PlaceRoot) {
$propFind->handle(self::LAST_PHOTO_PROPERTYNAME, fn () => $node->getFirstPhoto());
$propFind->handle(self::NBITEMS_PROPERTYNAME, fn () => count($node->getChildren()));
$propFind->handle(self::LAST_PHOTO_PROPERTYNAME, fn (): int => $node->getFirstPhoto());
$propFind->handle(self::NBITEMS_PROPERTYNAME, fn (): int => count($node->getChildren()));
}
}

Expand Down
3 changes: 2 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
__DIR__ . '/lib',
__DIR__ . '/tests',
])
->withPhpSets(php81: true);
->withPhpSets(php81: true)
->withTypeCoverageLevel(10);
6 changes: 3 additions & 3 deletions tests/Album/AlbumMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->l10n = $this->createMock(IL10N::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->timeFactory->method('getTime')->willReturnCallback(fn () => $this->time);
$this->timeFactory->method('getTime')->willReturnCallback(fn (): int => $this->time);

if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$this->markTestSkipped('Feature is broken on oracle');
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testCreateList() {
$this->mapper->create('user2', 'album3');

$retrievedAlbums = $this->mapper->getForUser('user1');
usort($retrievedAlbums, fn (AlbumInfo $a, AlbumInfo $b) => $a->getId() <=> $b->getId());
usort($retrievedAlbums, fn (AlbumInfo $a, AlbumInfo $b): int => $a->getId() <=> $b->getId());
$this->assertEquals([$album1, $album2], $retrievedAlbums);
}

Expand All @@ -155,7 +155,7 @@ public function testCreateDeleteList() {
$this->mapper->delete($album1->getId());

$retrievedAlbums = $this->mapper->getForUser('user1');
usort($retrievedAlbums, fn (AlbumInfo $a, AlbumInfo $b) => $a->getId() <=> $b->getId());
usort($retrievedAlbums, fn (AlbumInfo $a, AlbumInfo $b): int => $a->getId() <=> $b->getId());
$this->assertEquals([$album2], $retrievedAlbums);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Migration/Version30000Date20240417075405Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testPostSchemaChange(): void {

$migration->postSchemaChange(
$this->createMock(IOutput::class),
\Closure::fromCallable(fn () => false),
\Closure::fromCallable(fn (): bool => false),
[]
);

Expand Down