Skip to content

Commit

Permalink
Migrate applications away from deprecated ILogger
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 21, 2023
1 parent b6761fb commit 0a9371f
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Test\TestCase;

class OCSAuthAPIControllerTest extends TestCase {

/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
private $request;

Expand All @@ -54,7 +53,7 @@ class OCSAuthAPIControllerTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject|DbHandler */
private $dbHandler;

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

/** @var \PHPUnit\Framework\MockObject\MockObject|ITimeFactory */
Expand Down
5 changes: 2 additions & 3 deletions apps/federation/tests/TrustedServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use Psr\Log\LoggerInterface;

class TrustedServersTest extends TestCase {

/** @var \PHPUnit\Framework\MockObject\MockObject | TrustedServers */
private $trustedServers;

Expand All @@ -57,7 +56,7 @@ class TrustedServersTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\MockObject | IResponse */
private $response;

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

/** @var \PHPUnit\Framework\MockObject\MockObject | IJobList */
Expand Down Expand Up @@ -132,7 +131,7 @@ public function testAddServer(): void {
$this->dbHandler->expects($this->once())->method('addToken')->with('https://url', 'token');
$this->jobList->expects($this->once())->method('add')
->with('OCA\Federation\BackgroundJob\RequestSharedSecret',
['url' => 'https://url', 'token' => 'token', 'created' => 1234567]);
['url' => 'https://url', 'token' => 'token', 'created' => 1234567]);

$this->assertSame(
$trustedServers->addServer('url'),
Expand Down
26 changes: 9 additions & 17 deletions apps/files/lib/Controller/DirectEditingViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,19 @@
use OCP\DirectEditing\IManager;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

#[IgnoreOpenAPI]
class DirectEditingViewController extends Controller {

/** @var IEventDispatcher */
private $eventDispatcher;

/** @var IManager */
private $directEditingManager;

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

public function __construct($appName, IRequest $request, IEventDispatcher $eventDispatcher, IManager $manager, ILogger $logger) {
public function __construct(
$appName,

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $appName has no provided type
IRequest $request,
private IEventDispatcher $eventDispatcher,
private IManager $directEditingManager,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);

$this->eventDispatcher = $eventDispatcher;
$this->directEditingManager = $manager;
$this->logger = $logger;
}

/**
Expand All @@ -66,7 +58,7 @@ public function edit(string $token): Response {
try {
return $this->directEditingManager->edit($token);
} catch (Exception $e) {
$this->logger->logException($e);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new NotFoundResponse();
}
}
Expand Down
6 changes: 2 additions & 4 deletions apps/files_trashbin/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@
use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

class Storage extends Wrapper {
private string $mountPoint;
private IUserManager$userManager;
private IUserManager$userManager;
private LoggerInterface $logger;
private IEventDispatcher $eventDispatcher;
private IRootFolder $rootFolder;
Expand Down Expand Up @@ -218,7 +216,7 @@ function (string $mountPoint, IStorage $storage) use ($trashManager, $userManage
$rootFolder,
);
},
1);
1);
}

public function getMountPoint() {
Expand Down
1 change: 0 additions & 1 deletion apps/files_trashbin/tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use OCP\BackgroundJob\Job;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;

Expand Down
29 changes: 8 additions & 21 deletions apps/settings/lib/Controller/WebAuthnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,24 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Webauthn\PublicKeyCredentialCreationOptions;

#[IgnoreOpenAPI]
class WebAuthnController extends Controller {
private const WEBAUTHN_REGISTRATION = 'webauthn_registration';

/** @var Manager */
private $manager;

/** @var IUserSession */
private $userSession;
/**
* @var ISession
*/
private $session;
/**
* @var ILogger
*/
private $logger;

public function __construct(IRequest $request, ILogger $logger, Manager $webAuthnManager, IUserSession $userSession, ISession $session) {
public function __construct(
IRequest $request,
private LoggerInterface $logger,
private Manager $manager,
private IUserSession $userSession,
private ISession $session,
) {
parent::__construct(Application::APP_ID, $request);

$this->manager = $webAuthnManager;
$this->userSession = $userSession;
$this->session = $session;
$this->logger = $logger;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions apps/settings/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -74,8 +73,6 @@ class UsersControllerTest extends \Test\TestCase {
private $userSession;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
private $mailer;
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
Expand Down
35 changes: 9 additions & 26 deletions apps/theming/lib/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,21 @@
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\ITempManager;
use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;

class ImageManager {
public const SUPPORTED_IMAGE_KEYS = ['background', 'logo', 'logoheader', 'favicon'];

/** @var IConfig */
private $config;
/** @var IAppData */
private $appData;
/** @var IURLGenerator */
private $urlGenerator;
/** @var ICacheFactory */
private $cacheFactory;
/** @var ILogger */
private $logger;
/** @var ITempManager */
private $tempManager;

public function __construct(IConfig $config,
IAppData $appData,
IURLGenerator $urlGenerator,
ICacheFactory $cacheFactory,
ILogger $logger,
ITempManager $tempManager) {
$this->config = $config;
$this->urlGenerator = $urlGenerator;
$this->cacheFactory = $cacheFactory;
$this->logger = $logger;
$this->tempManager = $tempManager;
$this->appData = $appData;
public function __construct(
private IConfig $config,
private IAppData $appData,
private IURLGenerator $urlGenerator,
private ICacheFactory $cacheFactory,
private LoggerInterface $logger,
private ITempManager $tempManager,
) {
}

/**
Expand Down
11 changes: 5 additions & 6 deletions apps/theming/tests/ImageManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\ITempManager;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ImageManagerTest extends TestCase {

/** @var IConfig|MockObject */
protected $config;
/** @var IAppData|MockObject */
Expand All @@ -52,7 +51,7 @@ class ImageManagerTest extends TestCase {
private $urlGenerator;
/** @var ICacheFactory|MockObject */
private $cacheFactory;
/** @var ILogger|MockObject */
/** @var LoggerInterface|MockObject */
private $logger;
/** @var ITempManager|MockObject */
private $tempManager;
Expand All @@ -65,7 +64,7 @@ protected function setUp(): void {
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->tempManager = $this->createMock(ITempManager::class);
$this->rootFolder = $this->createMock(ISimpleFolder::class);
$this->imageManager = new ImageManager(
Expand Down Expand Up @@ -143,7 +142,7 @@ public function testGetImageUrl() {
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'logoMime', '']
)
)
->willReturn(0);
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
Expand Down Expand Up @@ -322,7 +321,7 @@ public function testCleanup() {
$folders[2]->expects($this->never())->method('delete');
$this->config->expects($this->once())
->method('getAppValue')
->with('theming','cachebuster','0')
->with('theming', 'cachebuster', '0')
->willReturn('2');
$this->rootFolder->expects($this->once())
->method('getDirectoryListing')
Expand Down
20 changes: 6 additions & 14 deletions apps/twofactor_backupcodes/lib/Listener/ActivityPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,13 @@
use OCP\Activity\IManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class ActivityPublisher implements IEventListener {

/** @var IManager */
private $activityManager;

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

public function __construct(IManager $activityManager,
ILogger $logger) {
$this->activityManager = $activityManager;
$this->logger = $logger;
public function __construct(
private IManager $activityManager,
private LoggerInterface $logger,
) {
}

/**
Expand All @@ -60,8 +53,7 @@ public function handle(Event $event): void {
try {
$this->activityManager->publish($activity);
} catch (BadMethodCallException $e) {
$this->logger->warning('could not publish backup code creation activity', ['app' => 'twofactor_backupcodes']);
$this->logger->logException($e, ['app' => 'twofactor_backupcodes']);
$this->logger->error('Could not publish backup code creation activity', ['exception' => $e]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\EventDispatcher\Event;
use OCP\ILogger;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class ActivityPublisherTest extends TestCase {

/** @var IManager|MockObject */
private $activityManager;

/** @var ILogger */

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

/** @var ActivityPublisher */
Expand All @@ -53,7 +51,7 @@ protected function setUp(): void {
parent::setUp();

$this->activityManager = $this->createMock(IManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->listener = new ActivityPublisher($this->activityManager, $this->logger);
}
Expand Down
14 changes: 7 additions & 7 deletions apps/updatenotification/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
use OCP\AppFramework\QueryException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Util;
use Psr\Log\LoggerInterface;

class Application extends App implements IBootstrap {
public function __construct() {
Expand All @@ -56,11 +56,11 @@ public function register(IRegistrationContext $context): void {

public function boot(IBootContext $context): void {
$context->injectFn(function (IConfig $config,
IUserSession $userSession,
IAppManager $appManager,
IGroupManager $groupManager,
IAppContainer $appContainer,
ILogger $logger) {
IUserSession $userSession,
IAppManager $appManager,
IGroupManager $groupManager,
IAppContainer $appContainer,

Check notice

Code scanning / Psalm

DeprecatedInterface Note

Interface OCP\AppFramework\IAppContainer is marked as deprecated
LoggerInterface $logger) {
if ($config->getSystemValue('updatechecker', true) !== true) {
// Updater check is disabled
return;
Expand All @@ -77,7 +77,7 @@ public function boot(IBootContext $context): void {
try {
$updateChecker = $appContainer->get(UpdateChecker::class);
} catch (QueryException $e) {
$logger->logException($e);
$logger->error($e->getMessage(), ['exception' => $e]);
return;
}

Expand Down

0 comments on commit 0a9371f

Please sign in to comment.