Skip to content

Commit

Permalink
fix psalm
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jan 30, 2023
1 parent 9e1914c commit 6631ea2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
use OCP\Share\IShare;
use OCP\Util;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

class CloudFederationProviderFiles implements ICloudFederationProvider {

Expand Down Expand Up @@ -842,8 +843,11 @@ private function getUserDisplayName(string $userId): string {

try {
$slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class);
} catch (ContainerExceptionInterface $e) {
\OC::$server->getLogger()->logException($e);
} catch (\Throwable $e) {
Server::get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
return '';
}

Expand Down
35 changes: 25 additions & 10 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

/**
* Class Share20OCS
Expand Down Expand Up @@ -345,11 +347,20 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
*/
private function getDisplayNameFromAddressBook(string $query, string $property): string {
// FIXME: If we inject the contacts manager it gets initialized before any address books are registered
$result = \OC::$server->getContactsManager()->search($query, [$property], [
'limit' => 1,
'enumeration' => false,
'strict_search' => true,
]);
try {
$result = \OC::$server->getContactsManager()->search($query, [$property], [
'limit' => 1,
'enumeration' => false,
'strict_search' => true,
]);
} catch (Exception $e) {
Server::get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
return '';
}

foreach ($result as $r) {
foreach ($r[$property] as $value) {
if ($value === $query && $r['FN']) {
Expand All @@ -372,7 +383,9 @@ private function fixMissingDisplayName(array $shares, ?array $updatedDisplayName
$userIds = $updated = [];
foreach ($shares as $share) {
// share is federated and share have no display name yet
if ($share['share_type'] === IShare::TYPE_REMOTE && $share['share_with_displayname'] === '') {
if ($share['share_type'] === IShare::TYPE_REMOTE
&& ($share['share_with'] ?? '') !== ''
&& ($share['share_with_displayname'] ?? '') === '') {
$userIds[] = $userId = $share['share_with'];

if ($updatedDisplayName !== null && array_key_exists($userId, $updatedDisplayName)) {
Expand Down Expand Up @@ -410,8 +423,7 @@ private function fixMissingDisplayName(array $shares, ?array $updatedDisplayName
* @param bool $cacheOnly - do not reach LUS, get data from cache.
*
* @return array
* @psalm-suppress DeprecatedMethod
* @psalm-suppress UndefinedClass
* @throws ContainerExceptionInterface
*/
private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly = false): array {
// check if gss is enabled and available
Expand All @@ -423,8 +435,11 @@ private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly =

try {
$slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class);
} catch (Exception $e) {
\OC::$server->getLogger()->logException($e);
} catch (\Throwable $e) {
Server::get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
return [];
}

Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<errorLevel type="suppress">
<referencedClass name="OCA\GroupFolders\Mount\GroupFolderStorage"/>
<referencedClass name="OCA\TwoFactorNextcloudNotification\Controller\APIController"/>
<referencedClass name="OCA\GlobalSiteSelector\Service\SlaveService"/>
</errorLevel>
</UndefinedClass>
<UndefinedFunction>
Expand Down Expand Up @@ -126,6 +127,7 @@
<!-- Helper classes for sharing API integration from other apps -->
<referencedClass name="OCA\Deck\Sharing\ShareAPIHelper" />
<referencedClass name="OCA\Talk\Share\Helper\DeletedShareAPIController" />
<referencedClass name="OCA\GlobalSiteSelector\Service\SlaveService"/>
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
Expand Down

0 comments on commit 6631ea2

Please sign in to comment.