diff --git a/lib/AppWhitelist.php b/lib/AppWhitelist.php index 02cafc9a..2973ae8e 100644 --- a/lib/AppWhitelist.php +++ b/lib/AppWhitelist.php @@ -23,11 +23,11 @@ use OCP\App\IAppManager; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUser; use OCP\Template; +use Psr\Log\LoggerInterface; /** * Only allow whitelisted apps to be accessed by guests @@ -35,20 +35,8 @@ * @package OCA\Guests */ class AppWhitelist { - /** @var Config */ - private $config; - /** @var GuestManager */ - private $guestManager; - /** @var IL10N */ - private $l10n; - /** @var IAppManager */ - private $appManager; - /** @var string */ - private $baseUrl; - /** @var int */ - private $baseUrlLength; - /** @var ILogger */ - private $logger; + private string $baseUrl; + private int $baseUrlLength; public const WHITELIST_ALWAYS = ',core,theming,settings,avatar,files,heartbeat,dav,guests,impersonate,accessibility,terms_of_service,dashboard,weather_status,user_status,apporder'; @@ -62,23 +50,18 @@ class AppWhitelist { * @param IL10N $l10n * @param IAppManager $appManager * @param IURLGenerator $urlGenerator - * @param ILogger $logger + * @param LoggerInterface $logger */ public function __construct( - Config $config, - GuestManager $guestManager, - IL10N $l10n, - IAppManager $appManager, IURLGenerator $urlGenerator, - ILogger $logger + private Config $config, + private GuestManager $guestManager, + private IL10N $l10n, + private IAppManager $appManager, + private LoggerInterface $logger, ) { - $this->config = $config; - $this->guestManager = $guestManager; - $this->l10n = $l10n; - $this->appManager = $appManager; $this->baseUrl = $urlGenerator->getBaseUrl(); $this->baseUrlLength = strlen($this->baseUrl); - $this->logger = $logger; } public function isAppWhitelisted($appId): bool { @@ -104,7 +87,7 @@ public function isUrlAllowed(IUser $user, $url): bool { echo "[]"; exit; } - $this->logger->info("Blocking access to non-whitelisted app ($app) for guest", ['app' => 'guests']); + $this->logger->notice("Blocking access to non-whitelisted app ($app) for guest", ['app' => 'guests']); return false; } } else { diff --git a/lib/Listener/ShareAutoAcceptListener.php b/lib/Listener/ShareAutoAcceptListener.php index 0b12359f..235e01d6 100644 --- a/lib/Listener/ShareAutoAcceptListener.php +++ b/lib/Listener/ShareAutoAcceptListener.php @@ -28,32 +28,22 @@ use OCA\Guests\UserBackend; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\ILogger; use OCP\IUserManager; use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\IManager as ShareManager; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; /** * @template-implements IEventListener */ class ShareAutoAcceptListener implements IEventListener { - /** @var IUserManager */ - private $userManager; - - /** @var ShareManager */ - private $shareManager; - - /** @var ILogger */ - private $logger; - - public function __construct(IUserManager $userManager, - ShareManager $shareManager, - ILogger $logger) { - $this->userManager = $userManager; - $this->shareManager = $shareManager; - $this->logger = $logger; + public function __construct( + private IUserManager $userManager, + private ShareManager $shareManager, + private LoggerInterface $logger, + ) { } public function handle(Event $event): void { diff --git a/lib/Mail.php b/lib/Mail.php index 870e6510..ec9c0db0 100644 --- a/lib/Mail.php +++ b/lib/Mail.php @@ -23,7 +23,6 @@ use OCP\Defaults; use OCP\IConfig; -use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\IUserSession; @@ -31,50 +30,20 @@ use OCP\Mail\IMailer; use OCP\Share; use OCP\Util; +use Psr\Log\LoggerInterface; class Mail { - /** @var IConfig */ - private $config; - - /** @var ILogger */ - private $logger; - - /** @var IUserSession */ - private $userSession; - - /** @var IMailer */ - private $mailer; - - /** @var Defaults */ - private $defaults; - - /** @var IFactory */ - private $l10nFactory; - - private $userManager; - - /** @var IURLGenerator */ - private $urlGenerator; - public function __construct( - IConfig $config, - ILogger $logger, - IUserSession $userSession, - IMailer $mailer, - Defaults $defaults, - IFactory $l10nFactory, - IUserManager $userManager, - IURLGenerator $urlGenerator + private IConfig $config, + private LoggerInterface $logger, + private IUserSession $userSession, + private IMailer $mailer, + private Defaults $defaults, + private IFactory $l10nFactory, + private IUserManager $userManager, + private IURLGenerator $urlGenerator, ) { - $this->config = $config; - $this->logger = $logger; - $this->userSession = $userSession; - $this->mailer = $mailer; - $this->defaults = $defaults; - $this->l10nFactory = $l10nFactory; - $this->userManager = $userManager; - $this->urlGenerator = $urlGenerator; } /** diff --git a/tests/stub.php b/tests/stub.php index 94d5ff40..47f270f1 100644 --- a/tests/stub.php +++ b/tests/stub.php @@ -453,38 +453,6 @@ public function getFileInfo(): \OCP\Files\FileInfo { } } -namespace OC\BackgroundJob { - - use OCP\BackgroundJob\IJob; - use OCP\BackgroundJob\IJobList; - use OCP\ILogger; - - abstract class TimedJob implements IJob { - public function execute(IJobList $jobList, ?ILogger $logger = null) { - } - - abstract protected function run($argument); - - public function setId(int $id) { - } - - public function setLastRun(int $lastRun) { - } - - public function setArgument($argument) { - } - - public function getId() { - } - - public function getLastRun() { - } - - public function getArgument() { - } - } -} - namespace OC\Files\Mount { use OC\Files\Storage\Storage; use OCP\Files\Mount\IMountPoint; diff --git a/tests/unit/AppWhitelistTest.php b/tests/unit/AppWhitelistTest.php index 85ae3852..01215166 100644 --- a/tests/unit/AppWhitelistTest.php +++ b/tests/unit/AppWhitelistTest.php @@ -28,23 +28,18 @@ use OCA\Guests\GuestManager; use OCP\App\IAppManager; use OCP\IL10N; -use OCP\ILogger; use OCP\IURLGenerator; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class AppWhitelistTest extends TestCase { - /** @var Config|MockObject */ - private $config; - /** @var GuestManager|MockObject */ - private $guestManager; - /** @var IL10N|MockObject */ - private $l10n; - /** @var IAppManager|MockObject */ - private $appManager; - /** @var IURLGenerator|MockObject */ - private $urlGenerator; + private Config&MockObject $config; + private GuestManager&MockObject $guestManager; + private IL10N&MockObject $l10n; + private IAppManager&MockObject $appManager; + private IURLGenerator&MockObject $urlGenerator; /** @var AppWhitelist */ private $appWhitelist; @@ -61,12 +56,12 @@ protected function setUp(): void { ->willReturn(''); $this->appWhitelist = new AppWhitelist( + $this->urlGenerator, $this->config, $this->guestManager, $this->l10n, $this->appManager, - $this->urlGenerator, - $this->createMock(ILogger::class) + $this->createMock(LoggerInterface::class) ); }