Skip to content

Commit d64882f

Browse files
authored
Merge pull request #1103 from nextcloud/carl/rector-cs-fix
chore: Add rector and cs-fix
2 parents cfb804a + c8312ea commit d64882f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+6112
-1238
lines changed

.github/workflows/lint-php-cs.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-License-Identifier: MIT
8+
9+
name: Lint php-cs
10+
11+
on: pull_request
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: lint-php-cs-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
lint:
22+
runs-on: ubuntu-latest
23+
24+
name: php-cs
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Get php version
33+
id: versions
34+
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
35+
36+
- name: Set up php${{ steps.versions.outputs.php-min }}
37+
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
38+
with:
39+
php-version: ${{ steps.versions.outputs.php-min }}
40+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
41+
coverage: none
42+
ini-file: development
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Install dependencies
47+
run: |
48+
composer remove nextcloud/ocp --dev --no-scripts
49+
composer i
50+
51+
- name: Lint
52+
run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )

.php-cs-fixer.dist.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
require_once './vendor-bin/cs-fixer/vendor/autoload.php';
9+
10+
use Nextcloud\CodingStandard\Config;
11+
12+
$config = new Config();
13+
$config
14+
->getFinder()
15+
->ignoreVCSIgnored(true)
16+
->notPath('build')
17+
->notPath('tests/stubs')
18+
->notPath('l10n')
19+
->notPath('src')
20+
->notPath('vendor')
21+
->in(__DIR__);
22+
return $config;

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This product includes GeoLite2 data created by MaxMind, available from [maxmind.
3333
<screenshot>https://github.com/nextcloud/terms_of_service/raw/master/docs/notification-and-settings.png</screenshot>
3434

3535
<dependencies>
36-
<nextcloud min-version="28" max-version="33" />
36+
<nextcloud min-version="30" max-version="33" />
3737
</dependencies>
3838

3939
<commands>

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-License-Identifier: AGPL-3.0-or-later

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"autoloader-suffix": "TermsOfService",
1212
"optimize-autoloader": true,
1313
"platform": {
14-
"php": "8.0.2"
14+
"php": "8.1"
1515
},
1616
"sort-packages": true
1717
},
@@ -27,7 +27,10 @@
2727
"scripts": {
2828
"bin": "echo 'bin not installed'",
2929
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
30+
"cs:check": "php-cs-fixer fix --dry-run --diff",
31+
"cs:fix": "php-cs-fixer fix",
3032
"openapi": "generate-spec --verbose",
33+
"rector": "rector && composer cs:fix",
3134
"post-install-cmd": [
3235
"@composer bin all install --ansi",
3336
"composer dump-autoload"

lib/AppInfo/Application.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,24 +9,23 @@
89

910
use Exception;
1011
use OC\Files\Filesystem;
11-
use OC\Files\Storage\Wrapper\Wrapper;
1212
use OCA\Registration\Events\PassedFormEvent;
1313
use OCA\Registration\Events\ShowFormEvent;
1414
use OCA\Registration\Events\ValidateFormEvent;
15-
use OCA\TermsOfService\PublicCapabilities;
1615
use OCA\TermsOfService\Checker;
1716
use OCA\TermsOfService\Dav\CheckPlugin;
1817
use OCA\TermsOfService\Filesystem\StorageWrapper;
1918
use OCA\TermsOfService\Listener\RegistrationIntegration;
2019
use OCA\TermsOfService\Listener\UserDeletedListener;
2120
use OCA\TermsOfService\Notifications\Notifier;
21+
use OCA\TermsOfService\PublicCapabilities;
2222
use OCP\AppFramework\App;
2323
use OCP\AppFramework\Bootstrap\IBootContext;
2424
use OCP\AppFramework\Bootstrap\IBootstrap;
2525
use OCP\AppFramework\Bootstrap\IRegistrationContext;
26+
use OCP\AppFramework\Services\IAppConfig;
2627
use OCP\EventDispatcher\IEventDispatcher;
2728
use OCP\Files\Storage\IStorage;
28-
use OCP\IConfig;
2929
use OCP\IRequest;
3030
use OCP\IUser;
3131
use OCP\IUserSession;
@@ -34,8 +34,8 @@
3434
use OCP\User\Events\UserDeletedEvent;
3535
use OCP\User\Events\UserFirstTimeLoggedInEvent;
3636
use OCP\Util;
37-
use Psr\Log\LoggerInterface;
3837
use Psr\Container\ContainerExceptionInterface;
38+
use Psr\Log\LoggerInterface;
3939

4040
include_once __DIR__ . '/../../vendor/autoload.php';
4141

@@ -46,7 +46,7 @@ class Application extends App implements IBootstrap {
4646

4747

4848
public function __construct() {
49-
parent::__construct('terms_of_service');
49+
parent::__construct(self::APPNAME);
5050
}
5151

5252
public function register(IRegistrationContext $context): void {
@@ -61,7 +61,7 @@ public function boot(IBootContext $context): void {
6161
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
6262

6363
$eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
64-
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) {
64+
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context): void {
6565
$eventServer = $event->getServer();
6666

6767
if ($eventServer !== null) {
@@ -78,7 +78,7 @@ public function boot(IBootContext $context): void {
7878
$context->injectFn([$this, 'registerFrontend']);
7979
}
8080

81-
public function registerFrontend(IRequest $request, IConfig $config, IUserSession $userSession): void {
81+
public function registerFrontend(IRequest $request, IAppConfig $appConfig, IUserSession $userSession): void {
8282
// Ignore CLI
8383
/** @psalm-suppress UndefinedClass */
8484
if (\OC::$CLI) {
@@ -105,14 +105,14 @@ public function registerFrontend(IRequest $request, IConfig $config, IUserSessio
105105
// registration
106106
'#^/apps/registration(?:$|/)#',
107107
];
108-
if (array_filter($skipPatterns, fn($pattern) => preg_match($pattern, $request->getPathInfo()))) {
108+
if (array_filter($skipPatterns, fn (string $pattern): int|false => preg_match($pattern, $request->getPathInfo()))) {
109109
return;
110110
}
111111

112112
if ($userSession->getUser() instanceof IUser) {
113113
// Logged-in user
114114
Util::addScript('terms_of_service', 'terms_of_service-user');
115-
} else if ($config->getAppValue(self::APPNAME, 'tos_on_public_shares', '0') === '1') {
115+
} elseif ($appConfig->getAppValueBool('tos_on_public_shares') === true) {
116116
// Guests on public pages
117117
Util::addScript('terms_of_service', 'terms_of_service-public');
118118
}
@@ -126,9 +126,6 @@ public function addStorageWrapper(): void {
126126
}
127127

128128
/**
129-
* @param string $mountPoint
130-
* @param IStorage $storage
131-
*
132129
* @return StorageWrapper|IStorage
133130
* @throws Exception
134131
*/
@@ -160,7 +157,7 @@ public function registerNotifier(IManager $notificationManager): void {
160157
}
161158

162159
public function createNotificationOnFirstLogin(IManager $notificationManager, IEventDispatcher $dispatcher): void {
163-
$dispatcher->addListener(UserFirstTimeLoggedInEvent::class, function(UserFirstTimeLoggedInEvent $event) use ($notificationManager) {
160+
$dispatcher->addListener(UserFirstTimeLoggedInEvent::class, function (UserFirstTimeLoggedInEvent $event) use ($notificationManager): void {
164161
$user = $event->getUser();
165162
$notification = $notificationManager->createNotification();
166163
$notification->setApp('terms_of_service')

lib/BackgroundJobs/CreateNotifications.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
namespace OCA\TermsOfService\BackgroundJobs;
1010

11-
use OCA\TermsOfService\AppInfo\Application;
1211
use OCA\TermsOfService\Db\Mapper\SignatoryMapper;
1312
use OCA\TermsOfService\Db\Mapper\TermsMapper;
13+
use OCP\AppFramework\Services\IAppConfig;
1414
use OCP\AppFramework\Utility\ITimeFactory;
1515
use OCP\BackgroundJob\QueuedJob;
16-
use OCP\IConfig;
1716
use OCP\IUser;
1817
use OCP\IUserManager;
1918
use OCP\Notification\IManager;
@@ -30,15 +29,15 @@ public function __construct(
3029
protected IManager $notificationsManager,
3130
protected TermsMapper $termsMapper,
3231
protected SignatoryMapper $signatoryMapper,
33-
protected IConfig $config,
32+
protected IAppConfig $appConfig,
3433
protected LoggerInterface $logger,
3534
ITimeFactory $time,
3635
) {
3736
parent::__construct($time);
3837
}
3938

4039
protected function run($argument): void {
41-
if ($this->config->getAppValue(Application::APPNAME, 'sent_notifications', 'no') === 'yes') {
40+
if ($this->appConfig->getAppValueBool('sent_notifications')) {
4241
$this->logger->debug('ToS Notifications have already been sent');
4342
return;
4443
}
@@ -49,7 +48,7 @@ protected function run($argument): void {
4948
return;
5049
}
5150

52-
$this->config->setAppValue(Application::APPNAME, 'sent_notifications', 'yes');
51+
$this->appConfig->setAppValueBool('sent_notifications', true);
5352

5453
$this->notification = $this->notificationsManager->createNotification();
5554
$this->notification->setApp('terms_of_service')
@@ -74,6 +73,7 @@ public function callForSeenUsers(IUser $user): void {
7473
$this->logger->debug('User ' . $user->getUID() . ' already signed ToS');
7574
return;
7675
}
76+
assert($this->notification !== null);
7777

7878
$this->notification->setUser($user->getUID());
7979
$this->notificationsManager->notify($this->notification);

0 commit comments

Comments
 (0)