Skip to content

Commit

Permalink
Merge pull request #25925 from nextcloud/techdept/psalm/ActionProvide…
Browse files Browse the repository at this point in the history
…rStore

Pimp ActionProviderStore
  • Loading branch information
rullzer authored Mar 8, 2021
2 parents 43c8298 + f04a2ce commit 615721d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
33 changes: 16 additions & 17 deletions lib/private/Contacts/ContactsMenu/ActionProviderStore.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*
Expand Down Expand Up @@ -28,9 +30,9 @@
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IUser;
use Psr\Log\LoggerInterface;

class ActionProviderStore {

Expand All @@ -40,15 +42,10 @@ class ActionProviderStore {
/** @var AppManager */
private $appManager;

/** @var ILogger */
/** @var LoggerInterface */
private $logger;

/**
* @param IServerContainer $serverContainer
* @param AppManager $appManager
* @param ILogger $logger
*/
public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) {
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
$this->serverContainer = $serverContainer;
$this->appManager = $appManager;
$this->logger = $logger;
Expand All @@ -59,7 +56,7 @@ public function __construct(IServerContainer $serverContainer, AppManager $appMa
* @return IProvider[]
* @throws Exception
*/
public function getProviders(IUser $user) {
public function getProviders(IUser $user): array {
$appClasses = $this->getAppProviderClasses($user);
$providerClasses = $this->getServerProviderClasses();
$allClasses = array_merge($providerClasses, $appClasses);
Expand All @@ -69,11 +66,13 @@ public function getProviders(IUser $user) {
try {
$providers[] = $this->serverContainer->query($class);
} catch (QueryException $ex) {
$this->logger->logException($ex, [
'message' => "Could not load contacts menu action provider $class",
'app' => 'core',
]);
throw new Exception("Could not load contacts menu action provider");
$this->logger->error('Could not load contacts menu action provider ' . $class,
[
'app' => 'core',
'exception' => $ex,
]
);
throw new Exception('Could not load contacts menu action provider');
}
}

Expand All @@ -83,7 +82,7 @@ public function getProviders(IUser $user) {
/**
* @return string[]
*/
private function getServerProviderClasses() {
private function getServerProviderClasses(): array {
return [
EMailProvider::class,
];
Expand All @@ -93,11 +92,11 @@ private function getServerProviderClasses() {
* @param IUser $user
* @return string[]
*/
private function getAppProviderClasses(IUser $user) {
private function getAppProviderClasses(IUser $user): array {
return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) {
$info = $this->appManager->getAppInfo($appId);

if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) {
if (!isset($info['contactsmenu'])) {
// Nothing to add
return $all;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ActionProviderStoreTest extends TestCase {
Expand All @@ -43,7 +43,7 @@ class ActionProviderStoreTest extends TestCase {
/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
private $appManager;

/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;

/** @var ActionProviderStore */
Expand All @@ -54,7 +54,7 @@ protected function setUp(): void {

$this->serverContainer = $this->createMock(IServerContainer::class);
$this->appManager = $this->createMock(AppManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $this->logger);
}
Expand Down

0 comments on commit 615721d

Please sign in to comment.