Skip to content
Closed
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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"autoload": {
"exclude-from-classmap": [
"**/bamarni/composer-bin-plugin/**"
],
"psr-4": {
"OCA\\TermsOfService\\": "lib/"
}
Expand Down
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() {
}
}
4 changes: 2 additions & 2 deletions lib/Filesystem/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CacheWrapper extends Wrapper {
public function __construct(
ICache $cache,
protected IStorage $storage,
private Helper $helper,
private readonly Helper $helper,
) {
parent::__construct($cache);

Expand All @@ -33,7 +33,7 @@ public function __construct(
public const PERMISSION_UPDATE = 2;
public const PERMISSION_DELETE = 8;

protected function formatCacheEntry($entry) {
protected function formatCacheEntry(array $entry): array {
if (isset($entry['path'], $entry['permissions'])
&& !$this->helper->verifyAccess($entry['path'])) {
$entry['permissions'] &= $this->mask;
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
2 changes: 1 addition & 1 deletion 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
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
10 changes: 9 additions & 1 deletion 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,11 +19,16 @@
->withSkip([
__DIR__ . '/tests/stubs',
])
->withSets([
NextcloudSets::NEXTCLOUD_27,
PHPUnitSetList::PHPUNIT_120
])
->withPreparedSets(
deadCode: true,
phpunitCodeQuality: true,
typeDeclarations: true,
)->withPhpSets(
php81: true,
php82: true,
)->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
'inline_public' => true,
'rename_property' => true,
Expand Down
26 changes: 8 additions & 18 deletions tests/CountryDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\TermsOfService\CountryDetector;
use OCA\TermsOfService\Db\Mapper\CountryMapper;
use OCP\IRequest;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand All @@ -31,26 +32,15 @@ protected function setUp(): void {
);
}

public function dataGetCountry(): array {
return [
'Local'
=> ['127.0.0.1', null, null, '--'],
'No country only continent'
=> ['138.199.26.4', null, null, '--'],
'India'
=> ['103.232.172.42', 'IN', true, 'IN'],
'Germany'
=> ['109.250.68.153', 'DE', true, 'DE'],
'France'
=> ['88.187.212.139', 'FR', true, 'FR'],
];
public static function dataGetCountry(): \Generator {
yield 'Local' => ['127.0.0.1', null, null, '--'];
yield 'No country only continent' => ['138.199.26.4', null, null, '--'];
yield 'India' => ['103.232.172.42', 'IN', true, 'IN'];
yield 'Germany' => ['109.250.68.153', 'DE', true, 'DE'];
yield 'France' => ['88.187.212.139', 'FR', true, 'FR'];
}

/**
* @dataProvider dataGetCountry
* @param string $iso
* @param bool $valid
*/
#[DataProvider('dataGetCountry')]
public function testGetCountry(string $ip, ?string $iso, ?bool $valid, string $expected): void {
$this->request->method('getRemoteAddress')
->willReturn($ip);
Expand Down
Loading
Loading