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\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;
class AppSettingsController extends Controller {
@ -76,7 +76,7 @@ class AppSettingsController extends Controller {
private $installer;
/** @var IURLGenerator */
private $urlGenerator;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/** @var array */
@ -95,7 +95,7 @@ class AppSettingsController extends Controller {
* @param BundleFetcher $bundleFetcher
* @param Installer $installer
* @param IURLGenerator $urlGenerator
* @param ILogger $logger
* @param LoggerInterface $logger
*/
public function __construct(string $appName,
IRequest $request,
@ -109,7 +109,7 @@ class AppSettingsController extends Controller {
BundleFetcher $bundleFetcher,
Installer $installer,
IURLGenerator $urlGenerator,
ILogger $logger) {
LoggerInterface $logger) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
@ -458,7 +458,7 @@ class AppSettingsController extends Controller {
}
return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
} 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);
}
}
@ -499,7 +499,7 @@ class AppSettingsController extends Controller {
}
return new JSONResponse([]);
} 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);
}
}

View File

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

View File

@ -73,11 +73,11 @@ use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@ -92,7 +92,7 @@ class CheckSetupController extends Controller {
private $l10n;
/** @var Checker */
private $checker;
/** @var ILogger */
/** @var LoggerInterface */
private $logger;
/** @var EventDispatcherInterface */
private $dispatcher;
@ -118,7 +118,7 @@ class CheckSetupController extends Controller {
IURLGenerator $urlGenerator,
IL10N $l10n,
Checker $checker,
ILogger $logger,
LoggerInterface $logger,
EventDispatcherInterface $dispatcher,
Connection $db,
ILockingProvider $lockingProvider,
@ -178,7 +178,10 @@ class CheckSetupController extends Controller {
$client->get($httpSiteName);
$client->get($httpsSiteName);
} 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 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]);
}
} 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.');
}
}

View File

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

View File

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

View File

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