Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function boot(IBootContext $context): void {
}
});

$context->injectFn([$this, 'registerNotifier']);
$context->injectFn([$this, 'createNotificationOnFirstLogin']);
$context->injectFn([$this, 'registerFrontend']);
$context->injectFn($this->registerNotifier(...));
$context->injectFn($this->createNotificationOnFirstLogin(...));
$context->injectFn($this->registerFrontend(...));
}

public function registerFrontend(IRequest $request, IAppConfig $appConfig, IUserSession $userSession): void {
Expand Down Expand Up @@ -123,7 +123,7 @@ public function registerFrontend(IRequest $request, IAppConfig $appConfig, IUser

public function addStorageWrapper(): void {
Filesystem::addStorageWrapper(
'terms_of_service', [$this, 'addStorageWrapperCallback'], -10
'terms_of_service', $this->addStorageWrapperCallback(...), -10
);
}

Expand All @@ -139,12 +139,12 @@ public function addStorageWrapperCallback(string $mountPoint, IStorage $storage)
[
'storage' => $storage,
'mountPoint' => $mountPoint,
'request' => \OC::$server->get(IRequest::class),
'checker' => \OC::$server->get(Checker::class),
'request' => \OCP\Server::get(IRequest::class),
'checker' => \OCP\Server::get(Checker::class),
]
);
} catch (ContainerExceptionInterface $e) {
\OC::$server->get(LoggerInterface::class)->error(
\OCP\Server::get(LoggerInterface::class)->error(
$e->getMessage(),
['exception' => $e]
);
Expand Down
2 changes: 1 addition & 1 deletion lib/BackgroundJobs/CreateNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function run($argument): void {

$this->notificationsManager->defer();
$this->currentBatch = 0;
$this->userManager->callForSeenUsers(\Closure::fromCallable([$this, 'callForSeenUsers']));
$this->userManager->callForSeenUsers($this->callForSeenUsers(...));
$this->notificationsManager->flush();
}

Expand Down
20 changes: 10 additions & 10 deletions lib/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class Checker {
private array $termsCache = [];

public function __construct(
private IRequest $request,
private IUserSession $userSession,
private ISession $session,
private SignatoryMapper $signatoryMapper,
private TermsMapper $termsMapper,
private CountryDetector $countryDetector,
private IAppConfig $appConfig,
private \OCP\IAppConfig $globalAppConfig,
private LoggerInterface $logger,
private IURLGenerator $url,
private readonly IRequest $request,
private readonly IUserSession $userSession,
private readonly ISession $session,
private readonly SignatoryMapper $signatoryMapper,
private readonly TermsMapper $termsMapper,
private readonly CountryDetector $countryDetector,
private readonly IAppConfig $appConfig,
private readonly \OCP\IAppConfig $globalAppConfig,
private readonly LoggerInterface $logger,
private readonly IURLGenerator $url,
) {
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/SigningController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
class SigningController extends OCSController {
public function __construct(
string $appName,
private ?string $userId,
private readonly ?string $userId,
IRequest $request,
private SignatoryMapper $signatoryMapper,
private IManager $notificationsManager,
private IAppConfig $appConfig,
private ISession $session,
private IEventDispatcher $eventDispatcher,
private readonly SignatoryMapper $signatoryMapper,
private readonly IManager $notificationsManager,
private readonly IAppConfig $appConfig,
private readonly ISession $session,
private readonly IEventDispatcher $eventDispatcher,
protected IJobList $jobList,
) {
parent::__construct($appName, $request);
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/TermsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class TermsController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private TermsMapper $termsMapper,
private SignatoryMapper $signatoryMapper,
private CountryMapper $countryMapper,
private LanguageMapper $languageMapper,
private CountryDetector $countryDetector,
private Checker $checker,
private IAppConfig $appConfig,
private IEventDispatcher $eventDispatcher,
private readonly TermsMapper $termsMapper,
private readonly SignatoryMapper $signatoryMapper,
private readonly CountryMapper $countryMapper,
private readonly LanguageMapper $languageMapper,
private readonly CountryDetector $countryDetector,
private readonly Checker $checker,
private readonly IAppConfig $appConfig,
private readonly IEventDispatcher $eventDispatcher,
protected IJobList $jobList,
) {
parent::__construct($appName, $request);
Expand Down
4 changes: 2 additions & 2 deletions lib/CountryDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

class CountryDetector {
public function __construct(
private IRequest $request,
private CountryMapper $countryMapper,
private readonly IRequest $request,
private readonly CountryMapper $countryMapper,
) {
}

Expand Down
20 changes: 10 additions & 10 deletions lib/Dav/CheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ class CheckPlugin extends ServerPlugin {
*/
public function initialize(Server $server): void {
$this->server = $server;
$server->on('method:PROPFIND', [$this, 'checkToS']);
$server->on('method:PROPPATCH', [$this, 'checkToS']);
$server->on('method:GET', [$this, 'checkToS']);
$server->on('method:POST', [$this, 'checkToS']);
$server->on('method:PUT', [$this, 'checkToS']);
$server->on('method:DELETE', [$this, 'checkToS']);
$server->on('method:MKCOL', [$this, 'checkToS']);
$server->on('method:MOVE', [$this, 'checkToS']);
$server->on('method:COPY', [$this, 'checkToS']);
$server->on('method:REPORT', [$this, 'checkToS']);
$server->on('method:PROPFIND', $this->checkToS(...));
$server->on('method:PROPPATCH', $this->checkToS(...));
$server->on('method:GET', $this->checkToS(...));
$server->on('method:POST', $this->checkToS(...));
$server->on('method:PUT', $this->checkToS(...));
$server->on('method:DELETE', $this->checkToS(...));
$server->on('method:MKCOL', $this->checkToS(...));
$server->on('method:MOVE', $this->checkToS(...));
$server->on('method:COPY', $this->checkToS(...));
$server->on('method:REPORT', $this->checkToS(...));
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/Events/SignaturesResetEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
* @package OCA\Terms_Of_Service\Events
*/
class SignaturesResetEvent extends Event {
public function __construct() {
}
}
2 changes: 0 additions & 2 deletions lib/Events/TermsCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
* @package OCA\Terms_Of_Service\Events
*/
class TermsCreatedEvent extends Event {
public function __construct() {
}
}
34 changes: 15 additions & 19 deletions lib/Filesystem/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,30 @@
use OC\Files\Cache\Wrapper\CacheWrapper as Wrapper;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\Storage\IStorage;
use OCP\Files\Cache\ICacheEntry;
use Override;

class CacheWrapper extends Wrapper {
protected int $mask;

public function __construct(
ICache $cache,
protected IStorage $storage,
private Helper $helper,
private readonly Helper $helper,
) {
parent::__construct($cache);

$this->mask = Constants::PERMISSION_ALL;
$this->mask &= ~Constants::PERMISSION_READ;
$this->mask &= ~Constants::PERMISSION_CREATE;
$this->mask &= ~Constants::PERMISSION_UPDATE;
$this->mask &= ~Constants::PERMISSION_DELETE;
}

public const PERMISSION_CREATE = 4;
public const PERMISSION_READ = 1;
public const PERMISSION_UPDATE = 2;
public const PERMISSION_DELETE = 8;

protected function formatCacheEntry($entry) {
if (isset($entry['path'], $entry['permissions'])
/**
* @param ICacheEntry|false $entry
*/
#[Override]
protected function formatCacheEntry($entry): ICacheEntry|false {
if ($entry !== false && isset($entry['path'], $entry['permissions'])
&& !$this->helper->verifyAccess($entry['path'])) {
$entry['permissions'] &= $this->mask;
$mask = Constants::PERMISSION_ALL
& ~Constants::PERMISSION_READ
& ~Constants::PERMISSION_CREATE
& ~Constants::PERMISSION_UPDATE
& ~Constants::PERMISSION_DELETE;
$entry['permissions'] &= $mask;
}
return $entry;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Filesystem/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class Helper {
public function __construct(
private Checker $checker,
private string $mountPoint,
private readonly Checker $checker,
private readonly string $mountPoint,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Filesystem/StorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class StorageWrapper extends Wrapper {
public string $mountPoint;
private Helper $helper;
private readonly Helper $helper;

public function __construct($parameters) {
parent::__construct($parameters);
Expand Down Expand Up @@ -82,6 +82,6 @@ public function getCache($path = '', $storage = null): ICache {
$storage = $this;
}
$cache = $this->storage->getCache($path, $storage);
return new CacheWrapper($cache, $storage, $this->helper);
return new CacheWrapper($cache, $this->helper);
}
}
8 changes: 4 additions & 4 deletions lib/Listener/RegistrationIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
class RegistrationIntegration implements IEventListener {

public function __construct(
private SignatoryMapper $signatoryMapper,
private TermsMapper $termsMapper,
private CountryDetector $countryDetector,
private IRequest $request,
private readonly SignatoryMapper $signatoryMapper,
private readonly TermsMapper $termsMapper,
private readonly CountryDetector $countryDetector,
private readonly IRequest $request,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class UserDeletedListener implements IEventListener {

public function __construct(
private SignatoryMapper $signatoryMapper,
private readonly SignatoryMapper $signatoryMapper,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Notifications/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
class Notifier implements INotifier {

public function __construct(
private IFactory $l10nFactory,
private IURLGenerator $url,
private IManager $notificationManager,
private \OCA\TermsOfService\Checker $checker,
private readonly IFactory $l10nFactory,
private readonly IURLGenerator $url,
private readonly IManager $notificationManager,
private readonly \OCA\TermsOfService\Checker $checker,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/PublicCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class PublicCapabilities implements IPublicCapability {
public function __construct(
private IAppConfig $config,
private readonly IAppConfig $config,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class AdminSection implements IIconSection {
public function __construct(
private IL10N $l,
private IURLGenerator $url,
private readonly IL10N $l,
private readonly IURLGenerator $url,
) {
}

Expand Down
8 changes: 8 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

use Nextcloud\Rector\Set\NextcloudSets;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPaths([
Expand All @@ -16,8 +19,13 @@
->withSkip([
__DIR__ . '/tests/stubs',
])
->withSets([
NextcloudSets::NEXTCLOUD_27,
PHPUnitSetList::PHPUNIT_120
])
->withPreparedSets(
deadCode: true,
phpunitCodeQuality: true,
typeDeclarations: true,
)->withPhpSets(
php81: true,
Expand Down
15 changes: 8 additions & 7 deletions tests/DeleteTermsCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\TermsOfService\Tests;

use OCA\TermsOfService\Command\DeleteTermsCommand;
Expand All @@ -23,7 +24,7 @@
/**
* @group Command
*/
class DeleteTermsCommandTest extends TestCase {
final class DeleteTermsCommandTest extends TestCase {

protected CountryMapper&MockObject $countryMapper;
protected TermsMapper&MockObject $termsMapper;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function testDeletesExistingTerms(): void {
->with($terms);

$result = $this->command->run($this->inputInterface, $this->outputInterface);
$this->assertSame($result, Command::SUCCESS);
$this->assertSame(Command::SUCCESS, $result);
}

public function testFallsBackToGlobalCountry(): void {
Expand Down Expand Up @@ -120,7 +121,7 @@ public function testFallsBackToGlobalCountry(): void {
->with($terms);

$result = $this->command->run($this->inputInterface, $this->outputInterface);
$this->assertSame($result, Command::SUCCESS);
$this->assertSame(Command::SUCCESS, $result);
}

public function testRejectsInvalidCountry(): void {
Expand Down Expand Up @@ -152,7 +153,7 @@ public function testRejectsInvalidCountry(): void {
->method('deleteTerm');

$result = $this->command->run($this->inputInterface, $this->outputInterface);
$this->assertSame($result, Command::FAILURE);
$this->assertSame(Command::FAILURE, $result);
}

public function testRejectsInvalidLanguage(): void {
Expand Down Expand Up @@ -184,7 +185,7 @@ public function testRejectsInvalidLanguage(): void {
->method('deleteTerm');

$result = $this->command->run($this->inputInterface, $this->outputInterface);
$this->assertSame($result, Command::FAILURE);
$this->assertSame(Command::FAILURE, $result);
}

public function testFailsForNonExistingTerms(): void {
Expand Down Expand Up @@ -217,6 +218,6 @@ public function testFailsForNonExistingTerms(): void {
->method('deleteTerm');

$result = $this->command->run($this->inputInterface, $this->outputInterface);
$this->assertSame($result, Command::FAILURE);
$this->assertSame(Command::FAILURE, $result);
}
}
Loading
Loading