Merge pull request #25862 from nextcloud/techdept/psalm/some_loggers

Move away some ILoggers
This commit is contained in:
Roeland Jago Douma 2021-03-02 15:01:44 +01:00 committed by GitHub
commit 2afa1c5739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 26 deletions

View File

@ -48,11 +48,11 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\INavigationManager; use OCP\INavigationManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;
class AppSettingsController extends Controller { class AppSettingsController extends Controller {
@ -76,7 +76,7 @@ class AppSettingsController extends Controller {
private $installer; private $installer;
/** @var IURLGenerator */ /** @var IURLGenerator */
private $urlGenerator; private $urlGenerator;
/** @var ILogger */ /** @var LoggerInterface */
private $logger; private $logger;
/** @var array */ /** @var array */
@ -95,7 +95,7 @@ class AppSettingsController extends Controller {
* @param BundleFetcher $bundleFetcher * @param BundleFetcher $bundleFetcher
* @param Installer $installer * @param Installer $installer
* @param IURLGenerator $urlGenerator * @param IURLGenerator $urlGenerator
* @param ILogger $logger * @param LoggerInterface $logger
*/ */
public function __construct(string $appName, public function __construct(string $appName,
IRequest $request, IRequest $request,
@ -109,7 +109,7 @@ class AppSettingsController extends Controller {
BundleFetcher $bundleFetcher, BundleFetcher $bundleFetcher,
Installer $installer, Installer $installer,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
ILogger $logger) { LoggerInterface $logger) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->l10n = $l10n; $this->l10n = $l10n;
$this->config = $config; $this->config = $config;
@ -458,7 +458,7 @@ class AppSettingsController extends Controller {
} }
return new JSONResponse(['data' => ['update_required' => $updateRequired]]); return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e); $this->logger->error('could not enable apps', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
} }
} }
@ -499,7 +499,7 @@ class AppSettingsController extends Controller {
} }
return new JSONResponse([]); return new JSONResponse([]);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e); $this->logger->error('could not disable app', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
} }
} }

View File

@ -46,12 +46,12 @@ use OCP\Activity\IManager;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\Session\Exceptions\SessionNotAvailableException;
use Psr\Log\LoggerInterface;
class AuthSettingsController extends Controller { class AuthSettingsController extends Controller {
@ -76,7 +76,7 @@ class AuthSettingsController extends Controller {
/** @var RemoteWipe */ /** @var RemoteWipe */
private $remoteWipe; private $remoteWipe;
/** @var ILogger */ /** @var LoggerInterface */
private $logger; private $logger;
/** /**
@ -89,7 +89,7 @@ class AuthSettingsController extends Controller {
* @param IUserSession $userSession * @param IUserSession $userSession
* @param IManager $activityManager * @param IManager $activityManager
* @param RemoteWipe $remoteWipe * @param RemoteWipe $remoteWipe
* @param ILogger $logger * @param LoggerInterface $logger
*/ */
public function __construct(string $appName, public function __construct(string $appName,
IRequest $request, IRequest $request,
@ -100,7 +100,7 @@ class AuthSettingsController extends Controller {
IUserSession $userSession, IUserSession $userSession,
IManager $activityManager, IManager $activityManager,
RemoteWipe $remoteWipe, RemoteWipe $remoteWipe,
ILogger $logger) { LoggerInterface $logger) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->tokenProvider = $tokenProvider; $this->tokenProvider = $tokenProvider;
$this->uid = $userId; $this->uid = $userId;
@ -252,8 +252,7 @@ class AuthSettingsController extends Controller {
try { try {
$this->activityManager->publish($event); $this->activityManager->publish($event);
} catch (BadMethodCallException $e) { } catch (BadMethodCallException $e) {
$this->logger->warning('could not publish activity'); $this->logger->warning('could not publish activity', ['exception' => $e]);
$this->logger->logException($e);
} }
} }

View File

@ -73,11 +73,11 @@ use OCP\IConfig;
use OCP\IDateTimeFormatter; use OCP\IDateTimeFormatter;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
@ -92,7 +92,7 @@ class CheckSetupController extends Controller {
private $l10n; private $l10n;
/** @var Checker */ /** @var Checker */
private $checker; private $checker;
/** @var ILogger */ /** @var LoggerInterface */
private $logger; private $logger;
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
private $dispatcher; private $dispatcher;
@ -118,7 +118,7 @@ class CheckSetupController extends Controller {
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
IL10N $l10n, IL10N $l10n,
Checker $checker, Checker $checker,
ILogger $logger, LoggerInterface $logger,
EventDispatcherInterface $dispatcher, EventDispatcherInterface $dispatcher,
Connection $db, Connection $db,
ILockingProvider $lockingProvider, ILockingProvider $lockingProvider,
@ -178,7 +178,10 @@ class CheckSetupController extends Controller {
$client->get($httpSiteName); $client->get($httpSiteName);
$client->get($httpsSiteName); $client->get($httpsSiteName);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'internet_connection_check']); $this->logger->error('Cannot connect to: ' . $sitename, [
'app' => 'internet_connection_check',
'exception' => $e,
]);
return false; return false;
} }
return true; return true;
@ -273,7 +276,10 @@ class CheckSetupController extends Controller {
return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['NSS', $versionString, $features]); return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['NSS', $versionString, $features]);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'settings', 'level' => \OCP\ILogger::WARN]); $this->logger->warning('error checking curl', [
'app' => 'settings',
'exception' => $e,
]);
return $this->l10n->t('Could not determine if TLS version of cURL is outdated or not because an error happened during the HTTPS request against https://nextcloud.com. Please check the nextcloud log file for more details.'); return $this->l10n->t('Could not determine if TLS version of cURL is outdated or not because an error happened during the HTTPS request against https://nextcloud.com. Please check the nextcloud log file for more details.');
} }
} }

View File

@ -40,12 +40,12 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\INavigationManager; use OCP\INavigationManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
/** /**
@ -80,7 +80,7 @@ class AppSettingsControllerTest extends TestCase {
private $installer; private $installer;
/** @var IURLGenerator|MockObject */ /** @var IURLGenerator|MockObject */
private $urlGenerator; private $urlGenerator;
/** @var ILogger|MockObject */ /** @var LoggerInterface|MockObject */
private $logger; private $logger;
protected function setUp(): void { protected function setUp(): void {
@ -100,7 +100,7 @@ class AppSettingsControllerTest extends TestCase {
$this->bundleFetcher = $this->createMock(BundleFetcher::class); $this->bundleFetcher = $this->createMock(BundleFetcher::class);
$this->installer = $this->createMock(Installer::class); $this->installer = $this->createMock(Installer::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->logger = $this->createMock(ILogger::class); $this->logger = $this->createMock(LoggerInterface::class);
$this->appSettingsController = new AppSettingsController( $this->appSettingsController = new AppSettingsController(
'settings', 'settings',

View File

@ -42,13 +42,13 @@ use OCA\Settings\Controller\AuthSettingsController;
use OCP\Activity\IEvent; use OCP\Activity\IEvent;
use OCP\Activity\IManager; use OCP\Activity\IManager;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\Session\Exceptions\SessionNotAvailableException;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
class AuthSettingsControllerTest extends TestCase { class AuthSettingsControllerTest extends TestCase {
@ -81,8 +81,8 @@ class AuthSettingsControllerTest extends TestCase {
$this->secureRandom = $this->createMock(ISecureRandom::class); $this->secureRandom = $this->createMock(ISecureRandom::class);
$this->activityManager = $this->createMock(IManager::class); $this->activityManager = $this->createMock(IManager::class);
$this->remoteWipe = $this->createMock(RemoteWipe::class); $this->remoteWipe = $this->createMock(RemoteWipe::class);
/** @var ILogger|MockObject $logger */ /** @var LoggerInterface|MockObject $logger */
$logger = $this->createMock(ILogger::class); $logger = $this->createMock(LoggerInterface::class);
$this->controller = new AuthSettingsController( $this->controller = new AuthSettingsController(
'core', 'core',

View File

@ -51,12 +51,12 @@ use OCP\IConfig;
use OCP\IDateTimeFormatter; use OCP\IDateTimeFormatter;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase; use Test\TestCase;
@ -79,7 +79,7 @@ class CheckSetupControllerTest extends TestCase {
private $urlGenerator; private $urlGenerator;
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */ /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
private $l10n; private $l10n;
/** @var ILogger */ /** @var LoggerInterface */
private $logger; private $logger;
/** @var Checker|\PHPUnit\Framework\MockObject\MockObject */ /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
private $checker; private $checker;
@ -129,7 +129,7 @@ class CheckSetupControllerTest extends TestCase {
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$this->db = $this->getMockBuilder(Connection::class) $this->db = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock(); $this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();