diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 00000000000..cc48b49fe43 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,82 @@ +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later +name: Rector + +on: + pull_request: + +permissions: + contents: read + +concurrency: + group: rector-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest-low + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - '**/lib/**' + - '**/tests/**' + - '**/vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + - '**.php' + + rector: + runs-on: ubuntu-latest + + needs: changes + if: ${{ needs.changes.outputs.src != 'false' && github.event_name != 'push' && github.repository_owner != 'nextcloud-gmbh' }} + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + + - name: Set up php + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 #v2.37.2 + with: + php-version: '8.3' + extensions: apcu,ctype,curl,dom,fileinfo,ftp,gd,imagick,intl,json,ldap,mbstring,openssl,pdo_sqlite,posix,sqlite,xml,zip + coverage: none + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Composer install + run: composer i + + - name: Rector + run: composer run rector + + - name: Show changes + if: always() + run: git diff --exit-code -- . ':!lib/composer' + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, rector] + + if: always() + + name: rector-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.rector.result != 'success' }}; then exit 1; fi diff --git a/.gitignore b/.gitignore index 0ed3277a8ca..0f617bc0ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,17 @@ -build/ \.idea/ +build/ node_modules/ -vendor/ -img/twemoji/ +cypress/downloads/ cypress/screenshots/ cypress/snapshots/ cypress/videos/ -cypress/downloads/ +dist/ /playwright-report/ .php-cs-fixer.cache /test-results/ -/tests/clover.xml /tests/.phpunit.result.cache -dist/ +/vendor/ +/vendor-bin/*/vendor webpack-stats.json # js folder, to be updated wth --force diff --git a/composer.json b/composer.json index bab1a6a79b6..e11fcb32d08 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "psalm/phar": "^6.5", "phpunit/phpunit": "^9.5", "ext-mbstring": "*", - "nextcloud/ocp": "dev-master" + "nextcloud/ocp": "dev-master", + "bamarni/composer-bin-plugin": "^1.9" }, "license": "AGPLv3", "authors": [ @@ -24,6 +25,9 @@ "classmap-authoritative": true, "platform": { "php": "8.3" + }, + "allow-plugins": { + "bamarni/composer-bin-plugin": true } }, "scripts": { @@ -31,7 +35,20 @@ "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "psalm": "psalm.phar", - "test:unit": "phpunit -c tests/phpunit.xml" + "rector": "vendor/bin/rector process && composer cs:fix", + "test:unit": "phpunit -c tests/phpunit.xml", + "post-install-cmd": [ + "[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi" + ], + "post-update-cmd": [ + "[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi" + ] + }, + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": true + } }, "autoload-dev": { "psr-4": { diff --git a/composer.lock b/composer.lock index a19d3fc249b..3e8aa101d2e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,66 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "630f11123b2abfd13bea30de5d84f850", + "content-hash": "126742110b22f5fdf9b9887eef6d0630", "packages": [], "packages-dev": [ + { + "name": "bamarni/composer-bin-plugin", + "version": "1.9.1", + "source": { + "type": "git", + "url": "https://github.com/bamarni/composer-bin-plugin.git", + "reference": "641d0663f5ac270b1aeec4337b7856f76204df47" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/composer-bin-plugin/zipball/641d0663f5ac270b1aeec4337b7856f76204df47", + "reference": "641d0663f5ac270b1aeec4337b7856f76204df47", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "composer/composer": "^2.2.26", + "ext-json": "*", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8 || ^2.0", + "phpstan/phpstan-phpunit": "^1.1 || ^2.0", + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.0", + "symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0", + "symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Bamarni\\Composer\\Bin\\BamarniBinPlugin" + }, + "autoload": { + "psr-4": { + "Bamarni\\Composer\\Bin\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "No conflicts for your bin dependencies", + "keywords": [ + "composer", + "conflict", + "dependency", + "executable", + "isolation", + "tool" + ], + "support": { + "issues": "https://github.com/bamarni/composer-bin-plugin/issues", + "source": "https://github.com/bamarni/composer-bin-plugin/tree/1.9.1" + }, + "time": "2026-02-04T10:18:12+00:00" + }, { "name": "doctrine/instantiator", "version": "2.0.0", diff --git a/lib/Command/ResetDocument.php b/lib/Command/ResetDocument.php index 014223cec66..216a5e00c0a 100644 --- a/lib/Command/ResetDocument.php +++ b/lib/Command/ResetDocument.php @@ -16,11 +16,10 @@ use Symfony\Component\Console\Output\OutputInterface; class ResetDocument extends Command { - protected DocumentService $documentService; - - public function __construct(DocumentService $documentService) { + public function __construct( + protected DocumentService $documentService, + ) { parent::__construct(); - $this->documentService = $documentService; } protected function configure(): void { diff --git a/lib/Controller/AiController.php b/lib/Controller/AiController.php index b46af801ad5..baef0c65027 100644 --- a/lib/Controller/AiController.php +++ b/lib/Controller/AiController.php @@ -21,7 +21,7 @@ class AiController extends ApiController { public function __construct( string $appName, IRequest $request, - private AiTagService $aiTagService, + private readonly AiTagService $aiTagService, ) { parent::__construct($appName, $request); } diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 8e095578784..883ffbb1c36 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -16,11 +16,11 @@ class NavigationController extends Controller { /** * - * @NoCSRFRequired - * @NoAdminRequired * * @return TemplateResponse */ + #[\OCP\AppFramework\Http\Attribute\NoCSRFRequired] + #[\OCP\AppFramework\Http\Attribute\NoAdminRequired] public function navigate(): TemplateResponse { return new TemplateResponse(Application::APP_NAME, 'main'); } diff --git a/lib/Controller/PublicSessionController.php b/lib/Controller/PublicSessionController.php index 87805defd0f..9a92c278a61 100644 --- a/lib/Controller/PublicSessionController.php +++ b/lib/Controller/PublicSessionController.php @@ -52,7 +52,7 @@ public function isValidToken(): bool { try { $this->share = $this->shareManager->getShareByToken($this->getToken()); return true; - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { return false; } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 6ac66c28bb9..42b941f2f7d 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -24,8 +24,8 @@ class SettingsController extends Controller { public function __construct( string $appName, IRequest $request, - private IUserConfig $userConfig, - private ?string $userId, + private readonly IUserConfig $userConfig, + private readonly ?string $userId, ) { parent::__construct($appName, $request); } diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 1761f6a3294..7e590ab8cef 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -37,15 +37,15 @@ class WorkspaceController extends OCSController { public function __construct( string $appName, IRequest $request, - private IRootFolder $rootFolder, - private IManager $shareManager, - private IDirectEditingManager $directEditingManager, - private IURLGenerator $urlGenerator, - private WorkspaceService $workspaceService, - private IEventDispatcher $eventDispatcher, - private LoggerInterface $logger, - private ISession $session, - private ?string $userId, + private readonly IRootFolder $rootFolder, + private readonly IManager $shareManager, + private readonly IDirectEditingManager $directEditingManager, + private readonly IURLGenerator $urlGenerator, + private readonly WorkspaceService $workspaceService, + private readonly IEventDispatcher $eventDispatcher, + private readonly LoggerInterface $logger, + private readonly ISession $session, + private readonly ?string $userId, ) { parent::__construct($appName, $request); } diff --git a/lib/DAV/WorkspacePlugin.php b/lib/DAV/WorkspacePlugin.php index 83fbe1a14b8..29f38db26dc 100644 --- a/lib/DAV/WorkspacePlugin.php +++ b/lib/DAV/WorkspacePlugin.php @@ -33,11 +33,11 @@ class WorkspacePlugin extends ServerPlugin { private Server $server; public function __construct( - private WorkspaceService $workspaceService, - private ICacheFactory $cacheFactory, - private ConfigService $configService, - private LoggerInterface $logger, - private ?string $userId, + private readonly WorkspaceService $workspaceService, + private readonly ICacheFactory $cacheFactory, + private readonly ConfigService $configService, + private readonly LoggerInterface $logger, + private readonly ?string $userId, ) { } @@ -55,7 +55,7 @@ public function __construct( public function initialize(Server $server) { $this->server = $server; - $this->server->on('propFind', [$this, 'propFind']); + $this->server->on('propFind', $this->propFind(...)); } public function propFind(PropFind $propFind, INode $node) { diff --git a/lib/Db/DocumentMapper.php b/lib/Db/DocumentMapper.php index efde04e80dd..aedf04ad5d0 100644 --- a/lib/Db/DocumentMapper.php +++ b/lib/Db/DocumentMapper.php @@ -32,7 +32,7 @@ public function find(int $documentId): Document { ->where($qb->expr()->eq('id', $qb->createNamedParameter($documentId))) ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { throw new DoesNotExistException('Document doesn\'t exist'); @@ -46,7 +46,7 @@ public function findAll(): Generator { ->from($this->getTableName()) ->executeQuery(); try { - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { yield $this->mapRowToEntity($row); } } finally { @@ -62,7 +62,7 @@ public function findAllWithNoActiveSessions(): Generator { ->where($qb->expr()->isNull('s.id')) ->executeQuery(); try { - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { yield $this->mapRowToEntity($row); } } finally { diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php index 97e096d5477..cfe596447d0 100644 --- a/lib/Db/SessionMapper.php +++ b/lib/Db/SessionMapper.php @@ -47,7 +47,7 @@ public function find(int $documentId, int $sessionId, string $token): Session { ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { throw new DoesNotExistException('Session is invalid'); @@ -122,9 +122,7 @@ public function deleteInactiveWithoutSteps(?int $documentId = null): int { $inactiveSessionBuilder->andWhere($inactiveSessionBuilder->expr()->eq('s.document_id', $inactiveSessionBuilder->createNamedParameter($documentId))); } $result = $inactiveSessionBuilder->executeQuery(); - $documentIds = array_map(function ($row) { - return (int)$row['id']; - }, $result->fetchAll()); + $documentIds = array_map(fn ($row) => (int)$row['id'], $result->fetchAllAssociative()); $result->closeCursor(); $chunks = array_chunk($documentIds, 500); @@ -157,9 +155,7 @@ public function deleteOldSessions(int $ageInSeconds): int { ->setMaxResults($batchSize) ->executeQuery(); - $sessionIds = array_map(function ($row) { - return (int)$row['id']; - }, $result->fetchAll()); + $sessionIds = array_map(fn ($row) => (int)$row['id'], $result->fetchAllAssociative()); $result->closeCursor(); if (empty($sessionIds)) { @@ -202,9 +198,7 @@ public function deleteOrphanedSteps(int $ageInSeconds): int { ->setMaxResults($batchSize); $result = $orphanedStepsQb->executeQuery(); - $stepIds = array_map(function ($row) { - return (int)$row['id']; - }, $result->fetchAll()); + $stepIds = array_map(fn ($row) => (int)$row['id'], $result->fetchAllAssociative()); $result->closeCursor(); if (empty($stepIds)) { @@ -245,7 +239,7 @@ public function isUserInDocument(int $documentId, string $userId): bool { ->setMaxResults(1) ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { return false; diff --git a/lib/Db/StepMapper.php b/lib/Db/StepMapper.php index 959f797c34b..26339b0912b 100644 --- a/lib/Db/StepMapper.php +++ b/lib/Db/StepMapper.php @@ -48,7 +48,7 @@ public function getLatestVersion(int $documentId): ?int { ->orderBy('id', 'DESC') ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); if ($data === false) { return null; } @@ -66,7 +66,7 @@ public function getBeforeVersion(int $documentId, int $version, int $offset): in ->orderBy('id', 'DESC') ->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $data = end($rows); if ($data === false) { return $version; diff --git a/lib/DirectEditing/TextDirectEditor.php b/lib/DirectEditing/TextDirectEditor.php index 3c62ee24f50..1c50a0a08c6 100644 --- a/lib/DirectEditing/TextDirectEditor.php +++ b/lib/DirectEditing/TextDirectEditor.php @@ -24,25 +24,12 @@ class TextDirectEditor implements IEditor { - /** @var IL10N */ - private $l10n; - - /** @var InitialStateProvider */ - private $initialStateProvider; - - /** @var ApiService */ - private $apiService; - - /** - * @var IAppConfig - */ - private $appConfig; - - public function __construct(IL10N $l10n, InitialStateProvider $initialStateProvider, ApiService $apiService, IAppConfig $appConfig) { - $this->l10n = $l10n; - $this->initialStateProvider = $initialStateProvider; - $this->apiService = $apiService; - $this->appConfig = $appConfig; + public function __construct( + private readonly IL10N $l10n, + private readonly InitialStateProvider $initialStateProvider, + private readonly ApiService $apiService, + private readonly IAppConfig $appConfig, + ) { } /** @@ -155,9 +142,7 @@ public function open(IToken $token): Response { Util::addScript('text', 'text-text'); Util::addStyle('text', 'text-text'); return new TemplateResponse('text', 'main', [], 'base'); - } catch (InvalidPathException $e) { - } catch (NotFoundException $e) { - } catch (NotPermittedException $e) { + } catch (InvalidPathException|NotFoundException|NotPermittedException) { } return new NotFoundResponse(); } diff --git a/lib/DirectEditing/TextDocumentCreator.php b/lib/DirectEditing/TextDocumentCreator.php index 6c455ee5249..00ece098573 100644 --- a/lib/DirectEditing/TextDocumentCreator.php +++ b/lib/DirectEditing/TextDocumentCreator.php @@ -14,19 +14,10 @@ class TextDocumentCreator extends ACreateEmpty { public const string CREATOR_ID = 'textdocument'; - /** - * @var IL10N - */ - private $l10n; - - /** - * @var IAppConfig - */ - private $appConfig; - - public function __construct(IL10N $l10n, IAppConfig $appConfig) { - $this->l10n = $l10n; - $this->appConfig = $appConfig; + public function __construct( + private readonly IL10N $l10n, + private readonly IAppConfig $appConfig, + ) { } public function getId(): string { @@ -42,12 +33,9 @@ public function getExtension(): string { } public function getMimetype(): string { - switch ($this->getExtension()) { - case 'txt': - return 'text/plain'; - case 'md': - default: - return 'text/markdown'; - } + return match ($this->getExtension()) { + 'txt' => 'text/plain', + default => 'text/markdown', + }; } } diff --git a/lib/Event/MentionEvent.php b/lib/Event/MentionEvent.php index a169894f153..98bff5a12b9 100644 --- a/lib/Event/MentionEvent.php +++ b/lib/Event/MentionEvent.php @@ -15,8 +15,8 @@ class MentionEvent extends Event { public function __construct( - private INotification $notification, - private File $file, + private readonly INotification $notification, + private readonly File $file, ) { parent::__construct(); } diff --git a/lib/Listeners/BeforeAssistantNotificationListener.php b/lib/Listeners/BeforeAssistantNotificationListener.php index 3fce9fa0120..79cae59b933 100644 --- a/lib/Listeners/BeforeAssistantNotificationListener.php +++ b/lib/Listeners/BeforeAssistantNotificationListener.php @@ -17,7 +17,7 @@ class BeforeAssistantNotificationListener implements \OCP\EventDispatcher\IEventListener { public function __construct( - private IURLGenerator $urlGenerator, + private readonly IURLGenerator $urlGenerator, ) { } diff --git a/lib/Listeners/BeforeNodeDeletedListener.php b/lib/Listeners/BeforeNodeDeletedListener.php index efd1c8a68a0..9562f02158c 100644 --- a/lib/Listeners/BeforeNodeDeletedListener.php +++ b/lib/Listeners/BeforeNodeDeletedListener.php @@ -19,13 +19,10 @@ * @template-implements IEventListener */ class BeforeNodeDeletedListener implements IEventListener { - private AttachmentService $attachmentService; - private DocumentService $documentService; - - public function __construct(AttachmentService $attachmentService, - DocumentService $documentService) { - $this->attachmentService = $attachmentService; - $this->documentService = $documentService; + public function __construct( + private readonly AttachmentService $attachmentService, + private readonly DocumentService $documentService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listeners/FilesLoadAdditionalScriptsListener.php b/lib/Listeners/FilesLoadAdditionalScriptsListener.php index 5e33fe8c8db..d8284159c6f 100644 --- a/lib/Listeners/FilesLoadAdditionalScriptsListener.php +++ b/lib/Listeners/FilesLoadAdditionalScriptsListener.php @@ -17,10 +17,9 @@ * @implements IEventListener */ class FilesLoadAdditionalScriptsListener implements IEventListener { - private InitialStateProvider $initialStateProvider; - - public function __construct(InitialStateProvider $initialStateProvider) { - $this->initialStateProvider = $initialStateProvider; + public function __construct( + private readonly InitialStateProvider $initialStateProvider, + ) { } public function handle(Event $event): void { diff --git a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php index 40a03f6bc7d..c99e84ab7c8 100644 --- a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php +++ b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php @@ -17,10 +17,10 @@ /** @implements IEventListener */ class FilesSharingLoadAdditionalScriptsListener implements IEventListener { - protected InitialStateProvider $initialStateProvider; - - public function __construct(IConfig $config, InitialStateProvider $initialStateProvider) { - $this->initialStateProvider = $initialStateProvider; + public function __construct( + IConfig $config, + protected InitialStateProvider $initialStateProvider, + ) { } public function handle(Event $event): void { diff --git a/lib/Listeners/LoadEditorListener.php b/lib/Listeners/LoadEditorListener.php index 13329aa132c..70c778c27f9 100644 --- a/lib/Listeners/LoadEditorListener.php +++ b/lib/Listeners/LoadEditorListener.php @@ -20,8 +20,8 @@ /** @template-implements IEventListener */ class LoadEditorListener implements \OCP\EventDispatcher\IEventListener { public function __construct( - private InitialStateProvider $initialStateProvider, - private IEventDispatcher $eventDispatcher, + private readonly InitialStateProvider $initialStateProvider, + private readonly IEventDispatcher $eventDispatcher, ) { } diff --git a/lib/Listeners/LoadViewerListener.php b/lib/Listeners/LoadViewerListener.php index 774d6a02872..a5b4872c708 100644 --- a/lib/Listeners/LoadViewerListener.php +++ b/lib/Listeners/LoadViewerListener.php @@ -18,13 +18,10 @@ /** @implements IEventListener */ class LoadViewerListener implements IEventListener { - private InitialStateProvider $initialStateProvider; - private IEventDispatcher $eventDispatcher; - - public function __construct(InitialStateProvider $initialStateProvider, - IEventDispatcher $eventDispatcher) { - $this->initialStateProvider = $initialStateProvider; - $this->eventDispatcher = $eventDispatcher; + public function __construct( + private readonly InitialStateProvider $initialStateProvider, + private readonly IEventDispatcher $eventDispatcher, + ) { } public function handle(Event $event): void { diff --git a/lib/Listeners/NodeCopiedListener.php b/lib/Listeners/NodeCopiedListener.php index 5f783d30b30..329ad0e8607 100644 --- a/lib/Listeners/NodeCopiedListener.php +++ b/lib/Listeners/NodeCopiedListener.php @@ -20,10 +20,9 @@ * @template-implements IEventListener */ class NodeCopiedListener implements IEventListener { - private $attachmentService; - - public function __construct(AttachmentService $attachmentService) { - $this->attachmentService = $attachmentService; + public function __construct( + private readonly AttachmentService $attachmentService, + ) { } public function handle(Event $event): void { diff --git a/lib/Listeners/NodeWrittenResetDocumentListener.php b/lib/Listeners/NodeWrittenResetDocumentListener.php index 3df2a489fdf..83612123824 100644 --- a/lib/Listeners/NodeWrittenResetDocumentListener.php +++ b/lib/Listeners/NodeWrittenResetDocumentListener.php @@ -25,8 +25,8 @@ class NodeWrittenResetDocumentListener implements IEventListener { private array $oldChecksums = []; public function __construct( - private LoggerInterface $logger, - private DocumentService $documentService, + private readonly LoggerInterface $logger, + private readonly DocumentService $documentService, ) { } diff --git a/lib/Listeners/RegisterTemplateCreatorListener.php b/lib/Listeners/RegisterTemplateCreatorListener.php index 719ffdd961c..6f5550ddff3 100644 --- a/lib/Listeners/RegisterTemplateCreatorListener.php +++ b/lib/Listeners/RegisterTemplateCreatorListener.php @@ -20,9 +20,9 @@ /** @implements IEventListener */ class RegisterTemplateCreatorListener implements IEventListener { public function __construct( - private IL10N $l10n, - private ConfigService $configService, - private IAppManager $appManager, + private readonly IL10N $l10n, + private readonly ConfigService $configService, + private readonly IAppManager $appManager, ) { } diff --git a/lib/Listeners/VersionRestoredListener.php b/lib/Listeners/VersionRestoredListener.php index 7322ebe9848..c16710f45e7 100644 --- a/lib/Listeners/VersionRestoredListener.php +++ b/lib/Listeners/VersionRestoredListener.php @@ -21,7 +21,7 @@ */ class VersionRestoredListener implements IEventListener { public function __construct( - private DocumentService $documentService, + private readonly DocumentService $documentService, ) { } @@ -38,7 +38,7 @@ public function handle(Event $event): void { // Reset document session to avoid manual conflict resolution if there's no unsaved steps try { $this->documentService->resetDocument($sourceFile->getId()); - } catch (DocumentHasUnsavedChangesException|NotFoundException $e) { + } catch (DocumentHasUnsavedChangesException|NotFoundException) { // Do not throw during event handling in this is expected to happen // DocumentHasUnsavedChangesException: A document editing session is likely ongoing, someone can resolve the conflict // NotFoundException: The event was called on a file that was just created so a NonExistingFile object is used that has no id yet diff --git a/lib/Middleware/SessionMiddleware.php b/lib/Middleware/SessionMiddleware.php index 2c0852be7fc..6df5d328ecf 100644 --- a/lib/Middleware/SessionMiddleware.php +++ b/lib/Middleware/SessionMiddleware.php @@ -39,15 +39,15 @@ class SessionMiddleware extends Middleware { public function __construct( - private IRequest $request, - private SessionService $sessionService, - private DocumentService $documentService, - private ISession $session, - private IUserSession $userSession, - private IRootFolder $rootFolder, - private ShareManager $shareManager, - private IL10N $l10n, - private IUserManager $userManager, + private readonly IRequest $request, + private readonly SessionService $sessionService, + private readonly DocumentService $documentService, + private readonly ISession $session, + private readonly IUserSession $userSession, + private readonly IRootFolder $rootFolder, + private readonly ShareManager $shareManager, + private readonly IL10N $l10n, + private readonly IUserManager $userManager, ) { } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 1b9093b8121..2fdb7f48308 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -29,11 +29,11 @@ class Notifier implements INotifier { public const string SUBJECT_MENTIONED_TARGET_USER = 'targetUser'; public function __construct( - private IFactory $factory, - private IUserManager $userManager, - private IURLGenerator $urlGenerator, - private IRootFolder $rootFolder, - private IEventDispatcher $eventDispatcher, + private readonly IFactory $factory, + private readonly IUserManager $userManager, + private readonly IURLGenerator $urlGenerator, + private readonly IRootFolder $rootFolder, + private readonly IEventDispatcher $eventDispatcher, ) { } @@ -66,7 +66,7 @@ public function prepare(INotification $notification, string $languageCode): INot try { $userFolder = $this->rootFolder->getUserFolder($targetUser); - } catch (NotPermittedException|NoUserException $e) { + } catch (NotPermittedException|NoUserException) { throw new UnknownNotificationException(); } $node = $userFolder->getFirstNodeById($fileId); diff --git a/lib/Service/AiTagService.php b/lib/Service/AiTagService.php index 81b50ea172e..5494e8de1e7 100644 --- a/lib/Service/AiTagService.php +++ b/lib/Service/AiTagService.php @@ -16,10 +16,10 @@ class AiTagService { public function __construct( - private ISystemTagObjectMapper $systemTagObjectMapper, - private IRootFolder $rootFolder, - private LoggerInterface $logger, - private ?string $userId, + private readonly ISystemTagObjectMapper $systemTagObjectMapper, + private readonly IRootFolder $rootFolder, + private readonly LoggerInterface $logger, + private readonly ?string $userId, ) { } diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index f471009fe31..8b1b9907d14 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -33,15 +33,15 @@ class ApiService { public function __construct( - private IRequest $request, - private ConfigService $configService, - private SessionService $sessionService, - private DocumentService $documentService, - private EncodingService $encodingService, - private LoggerInterface $logger, - private IL10N $l10n, - private ?string $userId, - private ?IQueue $queue, + private readonly IRequest $request, + private readonly ConfigService $configService, + private readonly SessionService $sessionService, + private readonly DocumentService $documentService, + private readonly EncodingService $encodingService, + private readonly LoggerInterface $logger, + private readonly IL10N $l10n, + private readonly ?string $userId, + private readonly ?IQueue $queue, ) { } @@ -56,9 +56,9 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $b */ try { $this->documentService->checkSharePermissions($token, Constants::PERMISSION_READ); - } catch (NotFoundException $e) { + } catch (NotFoundException) { return new DataResponse([], Http::STATUS_NOT_FOUND); - } catch (NotPermittedException $e) { + } catch (NotPermittedException) { return new DataResponse(['error' => $this->l10n->t('This file cannot be displayed as download is disabled by the share')], Http::STATUS_NOT_FOUND); } } elseif ($fileId !== null) { @@ -113,7 +113,7 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $b try { $stateFile = $this->documentService->getStateFile($document->getId()); $documentState = $stateFile->getContent(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $this->logger->warning('State file not found for saved document' . $file->getId()); // If we have no state file we need to load the content from the file diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 433cb0cbc2a..7147630afc7 100755 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -181,7 +181,7 @@ private function getMediaFilePreviewFile(string $mediaFileName, File $textFile): 'type' => 'file', 'file' => $this->previewManager->getPreview($mediaFile, 1024, 1024), ]; - } catch (NotFoundException $e) { + } catch (NotFoundException) { // the preview might not be found even if the mimetype is supported } } @@ -552,7 +552,7 @@ private function getTextFilePublic(?int $documentId, string $shareToken): File { } } } - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { // same as below } throw new NotFoundException('Text file with id=' . (string)$documentId . ' and shareToken ' . $shareToken . ' was not found.'); @@ -579,7 +579,7 @@ private function getShareFolder(string $shareToken): ?Folder { throw new NotFoundException('Share folder for ' . $shareToken . ' was not a folder.'); } } - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { // same as below } throw new NotFoundException('Share folder for ' . $shareToken . ' was not found.'); @@ -606,7 +606,7 @@ public function cleanupAttachments(int $fileId): int { // get IDs of the files inside the attachment dir try { $attachmentDir = $this->getAttachmentDirectoryForFile($textFile); - } catch (NotFoundException $e) { + } catch (NotFoundException) { // this only happens if the attachment dir was deleted by the user while editing the document return 0; } @@ -614,10 +614,8 @@ public function cleanupAttachments(int $fileId): int { $contentAttachmentNames = self::getAttachmentNamesFromContent($textFile->getContent(), $fileId); $toDelete = array_filter($attachmentDir->getDirectoryListing(), - function ($node) use ($contentAttachmentFileIds, $contentAttachmentNames) { - return !in_array($node->getName(), $contentAttachmentNames) - && !in_array($node->getId(), $contentAttachmentFileIds); - } + fn ($node) => !in_array($node->getName(), $contentAttachmentNames) + && !in_array($node->getId(), $contentAttachmentFileIds) ); foreach ($toDelete as $node) { $node->delete(); @@ -640,9 +638,7 @@ public static function getAttachmentIdsFromContent(string $content): array { $matches, PREG_SET_ORDER ); - return array_map(static function (array $match) { - return intval($match[1]); - }, $matches); + return array_map(static fn (array $match) => intval($match[1]), $matches); } /** @@ -657,9 +653,7 @@ public static function getAttachmentNamesFromContent(string $content, int $fileI $matches, PREG_SET_ORDER ); - return array_map(static function (array $match) { - return urldecode($match[1]); - }, $matches); + return array_map(static fn (array $match) => urldecode($match[1]), $matches); } /** @@ -672,7 +666,7 @@ public static function getAttachmentNamesFromContent(string $content, int $fileI public function copyAttachments(File $source, File $target): array { try { $sourceAttachmentDir = $this->getAttachmentDirectoryForFile($source); - } catch (NotFoundException $e) { + } catch (NotFoundException) { // silently return if no attachment dir was found for source file return []; } @@ -737,7 +731,7 @@ public function moveAttachments(File $source, File $target): void { if ($source->getParent()->getPath() !== $target->getParent()->getPath()) { try { $sourceAttachmentDir = $this->getAttachmentDirectoryForFile($source); - } catch (NotFoundException $e) { + } catch (NotFoundException) { // silently return if no attachment dir was found for source file return; } @@ -760,7 +754,7 @@ public function deleteAttachments(File $source): void { // if there is an attachment dir for this file try { $sourceAttachmentDir = $this->getAttachmentDirectoryForFile($source); - } catch (NotFoundException $e) { + } catch (NotFoundException) { // silently return if no attachment dir was found return; } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 7a85631675b..ff68eed150e 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -14,9 +14,9 @@ class ConfigService { public function __construct( - private IAppConfig $appConfig, - private IUserConfig $userConfig, - private IConfig $config, + private readonly IAppConfig $appConfig, + private readonly IUserConfig $userConfig, + private readonly IConfig $config, ) { } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index b899420b30d..a8cee5c7e0e 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -58,33 +58,25 @@ class DocumentService { public const int AUTOSAVE_MINIMUM_DELAY = 10; private bool $saveFromText = false; - - private ?string $userId; - private DocumentMapper $documentMapper; - private SessionMapper $sessionMapper; - private LoggerInterface $logger; - private ShareManager $shareManager; - private StepMapper $stepMapper; - private IRootFolder $rootFolder; - private ICache $cache; - private IAppData $appData; - private ILockManager $lockManager; - private IUserMountCache $userMountCache; - private IConfig $config; - - public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, ?string $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, LoggerInterface $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockManager $lockManager, IUserMountCache $userMountCache, IConfig $config) { - $this->documentMapper = $documentMapper; - $this->stepMapper = $stepMapper; - $this->sessionMapper = $sessionMapper; - $this->userId = $userId; - $this->appData = $appData; - $this->rootFolder = $rootFolder; + private readonly ICache $cache; + + public function __construct( + private readonly DocumentMapper $documentMapper, + private readonly StepMapper $stepMapper, + private readonly SessionMapper $sessionMapper, + private readonly IAppData $appData, + private ?string $userId, + private readonly IRootFolder $rootFolder, + ICacheFactory $cacheFactory, + private readonly LoggerInterface $logger, + private readonly ShareManager $shareManager, + IRequest $request, + IManager $directManager, + private readonly ILockManager $lockManager, + private readonly IUserMountCache $userMountCache, + private readonly IConfig $config, + ) { $this->cache = $cacheFactory->createDistributed('text'); - $this->logger = $logger; - $this->shareManager = $shareManager; - $this->lockManager = $lockManager; - $this->userMountCache = $userMountCache; - $this->config = $config; $token = $request->getParam('token'); if ($this->userId === null && $token !== null) { try { @@ -92,7 +84,7 @@ public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapp $tokenObject->extend(); $tokenObject->useTokenScope(); $this->userId = $tokenObject->getUser(); - } catch (\Exception $e) { + } catch (\Exception) { } } } @@ -100,7 +92,7 @@ public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapp public function getDocument(int $id): ?Document { try { return $this->documentMapper->find($id); - } catch (DoesNotExistException|NotFoundException $e) { + } catch (DoesNotExistException|NotFoundException) { return null; } } @@ -201,7 +193,7 @@ public function createStateFile(int $documentId): ISimpleFile { public function writeDocumentState(int $documentId, string $content): void { try { $documentStateFile = $this->getStateFile($documentId); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $documentStateFile = $this->createStateFile($documentId); } catch (NotPermittedException $e) { $this->logger->error('Failed to create document state file', ['exception' => $e]); @@ -257,7 +249,7 @@ public function addStep(Document $document, Session $session, array $steps, int // If there were any queries in the steps, send all steps starting 200 steps before last save. // Adding 200 previous steps to workaround race conditions where state with missing step got persisted in the document state. See #7692 $getStepsSinceVersion = $this->stepMapper->getBeforeVersion($documentId, $document->getLastSavedVersion(), 200); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $this->logger->debug('Existing document, but no state file found for ' . $documentId); // If there is no state file, include all the steps. $getStepsSinceVersion = 0; @@ -406,12 +398,8 @@ public function autosave(Document $document, File $file, int $version, string $a 'requestDocumentState' => $documentState, 'document' => $document->jsonSerialize(), 'fileSizeBeforeSave' => $file->getSize(), - 'steps' => array_map(static function (Step $step) { - return $step->jsonSerialize(); - }, $this->stepMapper->find($documentId, 0)), - 'sessions' => array_map(static function (Session $session) { - return $session->jsonSerialize(); - }, $this->sessionMapper->findAll($documentId)) + 'steps' => array_map(static fn (Step $step) => $step->jsonSerialize(), $this->stepMapper->find($documentId, 0)), + 'sessions' => array_map(static fn (Session $session) => $session->jsonSerialize(), $this->sessionMapper->findAll($documentId)) ]); } @@ -431,7 +419,7 @@ public function autosave(Document $document, File $file, int $version, string $a $file, ILock::TYPE_APP, Application::APP_NAME - ), function () use ($file, $autoSaveDocument, $documentState) { + ), function () use ($file, $autoSaveDocument, $documentState): void { $this->saveFromText = true; $file->putContent($autoSaveDocument); $this->writeDocumentState($file->getId(), $documentState); @@ -441,7 +429,7 @@ public function autosave(Document $document, File $file, int $version, string $a $document->setLastSavedVersionEtag($file->getEtag()); $document->setChecksum(self::computeCheckSum($autoSaveDocument)); $this->documentMapper->update($document); - } catch (LockedException $e) { + } catch (LockedException) { // Ignore lock since it might occur when multiple people save at the same time return $document; } finally { @@ -471,7 +459,7 @@ public function resetDocument(int $documentId, bool $force = false): void { $this->getStateFile($documentId)->delete(); $this->logger->debug('document reset for ' . $documentId); - } catch (DoesNotExistException|NotFoundException $e) { + } catch (DoesNotExistException|NotFoundException) { // Ignore if document not found or state file not found } } @@ -503,7 +491,7 @@ public function getFileForSession(Session $session, ?string $shareToken = null): try { $share = $this->shareManager->getShareByToken($shareToken); - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { throw new NotFoundException(); } @@ -522,7 +510,7 @@ public function getFileForSession(Session $session, ?string $shareToken = null): * @throws NotPermittedException */ public function getFileById(int $fileId, ?string $userId = null): File { - $userId = $userId ?? $this->userId; + $userId ??= $this->userId; // If no user is provided we need to get any file from existing mounts for cleanup jobs if ($userId === null) { @@ -537,7 +525,7 @@ public function getFileById(int $fileId, ?string $userId = null): File { try { $userFolder = $this->rootFolder->getUserFolder($userId); - } catch (\OC\User\NoUserException $e) { + } catch (\OC\User\NoUserException) { // It is a bit hacky to depend on internal exceptions here. But it is the best we can do for now throw new NotFoundException(); } @@ -557,9 +545,7 @@ public function getFileById(int $fileId, ?string $userId = null): File { // Workaround to always open files with edit permissions if multiple occurrences of // the same file id are in the user home, ideally we should also track the path of the file when opening - usort($files, static function (Node $a, Node $b) { - return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE); - }); + usort($files, static fn (Node $a, Node $b) => ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE)); $file = array_shift($files); @@ -580,7 +566,7 @@ public function getFileById(int $fileId, ?string $userId = null): File { public function getFileByShareToken(string $shareToken, ?string $path = null): File { try { $share = $this->shareManager->getShareByToken($shareToken); - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { throw new NotFoundException(); } @@ -599,7 +585,7 @@ public function isReadOnly(File $file, ?string $token): bool { if ($token !== null) { try { $this->checkSharePermissions($token, Constants::PERMISSION_UPDATE); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $readOnly = true; } } @@ -619,7 +605,7 @@ public function isReadOnly(File $file, ?string $token): bool { public function getLockInfo(File $file): ?ILock { try { $locks = $this->lockManager->getLocks($file->getId()); - } catch (NoLockProviderException|PreConditionNotMetException $e) { + } catch (NoLockProviderException|PreConditionNotMetException) { return null; } return array_shift($locks); @@ -637,7 +623,7 @@ public function getLockInfo(File $file): ?ILock { public function checkSharePermissions(string $shareToken, int $permission = Constants::PERMISSION_READ): void { try { $share = $this->shareManager->getShareByToken($shareToken); - } catch (ShareNotFound $e) { + } catch (ShareNotFound) { throw new NotFoundException(); } @@ -655,7 +641,7 @@ public function hasUnsavedChanges(Document $document): bool { private function ensureDocumentsFolder(): bool { try { $this->appData->getFolder('documents'); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $this->appData->newFolder('documents'); } catch (\RuntimeException $e) { // Do not fail hard @@ -678,8 +664,8 @@ public function lock(int $fileId): bool { ILock::TYPE_APP, Application::APP_NAME )); - } catch (NoLockProviderException|PreConditionNotMetException|NotFoundException $e) { - } catch (OwnerLockedException $e) { + } catch (NoLockProviderException|PreConditionNotMetException|NotFoundException) { + } catch (OwnerLockedException) { return false; } return true; @@ -697,7 +683,7 @@ public function unlock(int $fileId): void { ILock::TYPE_APP, Application::APP_NAME )); - } catch (NoLockProviderException|PreConditionNotMetException|NotFoundException $e) { + } catch (NoLockProviderException|PreConditionNotMetException|NotFoundException) { } } diff --git a/lib/Service/InitialStateProvider.php b/lib/Service/InitialStateProvider.php index 8b550d57ca1..322fd4a9d4e 100644 --- a/lib/Service/InitialStateProvider.php +++ b/lib/Service/InitialStateProvider.php @@ -22,10 +22,10 @@ class InitialStateProvider { ]; public function __construct( - private IInitialState $initialState, - private ConfigService $configService, - private IManager $taskProcessingManager, - private ?string $userId, + private readonly IInitialState $initialState, + private readonly ConfigService $configService, + private readonly IManager $taskProcessingManager, + private readonly ?string $userId, ) { } @@ -62,9 +62,7 @@ public function provideState(): void { isset($taskTypes['core:text2text:translate']), ); - $filteredTypes = array_filter($taskTypes, static function (string $taskType) { - return in_array($taskType, self::ASSISTANT_TASK_TYPES, true); - }, ARRAY_FILTER_USE_KEY); + $filteredTypes = array_filter($taskTypes, static fn (string $taskType) => in_array($taskType, self::ASSISTANT_TASK_TYPES, true), ARRAY_FILTER_USE_KEY); $this->initialState->provideInitialState( 'taskprocessing', array_map(static function (string $typeId, array $taskType) { diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 3b21f7b0d4e..0f934b37dc5 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -12,14 +12,11 @@ use OCP\Notification\IManager; class NotificationService { - private IManager $manager; - private ITimeFactory $timeFactory; - private ?string $userId; - - public function __construct(IManager $manager, ITimeFactory $timeFactory, ?string $userId = null) { - $this->manager = $manager; - $this->timeFactory = $timeFactory; - $this->userId = $userId; + public function __construct( + private readonly IManager $manager, + private readonly ITimeFactory $timeFactory, + private readonly ?string $userId = null, + ) { } public function mention(int $fileId, string $userId): bool { diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 1de469ea96d..6cf2f872ff9 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -24,36 +24,22 @@ class SessionService { public const int SESSION_VALID_TIME = 5 * 60; - - private SessionMapper $sessionMapper; - private ITimeFactory $timeFactory; - private IUserManager $userManager; - private IAvatarManager $avatarManager; - private ?string $userId; - private ICache $cache; - private EncodingService $encodingService; + private readonly ICache $cache; /** @var ?Session cache current session in the request */ private ?Session $session = null; public function __construct( - SessionMapper $sessionMapper, - ITimeFactory $timeFactory, - IUserManager $userManager, - IAvatarManager $avatarManager, + private readonly SessionMapper $sessionMapper, + private readonly ITimeFactory $timeFactory, + private readonly IUserManager $userManager, + private readonly IAvatarManager $avatarManager, IRequest $request, IManager $directManager, - ?string $userId, + private ?string $userId, ICacheFactory $cacheFactory, - EncodingService $encodingService, + private readonly EncodingService $encodingService, ) { - $this->sessionMapper = $sessionMapper; - $this->timeFactory = $timeFactory; - $this->userManager = $userManager; - $this->avatarManager = $avatarManager; - $this->encodingService = $encodingService; - $this->userId = $userId; - $token = $request->getParam('token'); if ($this->userId === null && $token !== null) { try { @@ -61,7 +47,7 @@ public function __construct( $tokenObject->extend(); $tokenObject->useTokenScope(); $this->userId = $tokenObject->getUser(); - } catch (\Exception $e) { + } catch (\Exception) { } } @@ -90,7 +76,7 @@ public function closeSession(int $documentId, int $sessionId, string $token): vo $session = $this->sessionMapper->find($documentId, $sessionId, $token); $this->cache->remove($token); $this->sessionMapper->delete($session); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { } } @@ -168,7 +154,7 @@ public function getSession(int $documentId, int $sessionId, string $token): ?Ses try { $this->session = $this->sessionMapper->find($documentId, $sessionId, $token); $this->cache->set($token, json_encode($this->session), self::SESSION_VALID_TIME - 30); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $this->session = null; $this->cache->remove($token); } @@ -190,7 +176,7 @@ public function getValidSession(int $documentId, int $sessionId, string $token): */ try { $session = $this->sessionMapper->find($documentId, $sessionId, $token); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $this->session = null; $this->cache->remove($token); return null; diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index 2b200d88262..b2eb8577864 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -17,8 +17,6 @@ use OCP\IL10N; class WorkspaceService { - private IL10N $l10n; - public const string DEFAULT_FILENAME = 'Readme.md'; private const array SUPPORTED_STATIC_FILENAMES = [ @@ -28,8 +26,9 @@ class WorkspaceService { '.Readme.md', ]; - public function __construct(IL10N $l10n) { - $this->l10n = $l10n; + public function __construct( + private readonly IL10N $l10n, + ) { } public function getFile(Folder $folder): ?File { diff --git a/lib/TextFile.php b/lib/TextFile.php index 6298e56ceda..fd140d517b3 100644 --- a/lib/TextFile.php +++ b/lib/TextFile.php @@ -17,12 +17,10 @@ * Wrapper around a ISimpleFile object to ensure that it is correctly encoded (UTF-8) for the text app. */ class TextFile implements ISimpleFile { - private ISimpleFile $file; - private EncodingService $encodingService; - - public function __construct(ISimpleFile $file, EncodingService $encodingService) { - $this->file = $file; - $this->encodingService = $encodingService; + public function __construct( + private readonly ISimpleFile $file, + private readonly EncodingService $encodingService, + ) { } public function getName(): string { diff --git a/lib/YjsMessage.php b/lib/YjsMessage.php index 9f2ef34876e..790a091e7d2 100644 --- a/lib/YjsMessage.php +++ b/lib/YjsMessage.php @@ -35,7 +35,7 @@ class YjsMessage { private int $pos = 0; public function __construct( - private string $data = '', + private readonly string $data = '', ) { } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000000..d6cffc66cfe --- /dev/null +++ b/rector.php @@ -0,0 +1,25 @@ +withPaths([ + __DIR__ . '/appinfo', + __DIR__ . '/lib', + __DIR__ . '/tests', + ]) + ->withPhpSets(php83: true) + ->withTypeCoverageLevel(0) + ->withSets([ + NextcloudSets::NEXTCLOUD_35, + ]) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/tests/unit/Service/ApiServiceTest.php b/tests/unit/Service/ApiServiceTest.php index 3bfebec3a1e..ca366aa2f2b 100644 --- a/tests/unit/Service/ApiServiceTest.php +++ b/tests/unit/Service/ApiServiceTest.php @@ -39,9 +39,7 @@ public function setUp(): void { $document->setId(123); $this->documentService->method('getOrCreateDocument')->willReturn($document); $this->documentService->method('isReadOnly')->willReturn(false); - $this->encodingService->method('encodeToUtf8')->willReturnCallback(function ($str) { - return $str; - }); + $this->encodingService->method('encodeToUtf8')->willReturnCallback(fn ($str) => $str); $this->apiService = new ApiService( $this->request, diff --git a/tests/unit/Service/AttachmentServiceTest.php b/tests/unit/Service/AttachmentServiceTest.php index f915d658c31..70e24cb084e 100755 --- a/tests/unit/Service/AttachmentServiceTest.php +++ b/tests/unit/Service/AttachmentServiceTest.php @@ -90,9 +90,7 @@ public function testGetUniqueFileName(): void { $folder = $this->createMock(Folder::class); $folder->expects(self::any()) ->method('nodeExists') - ->willReturnCallback(function ($name) use ($fileNameList) { - return in_array($name, $fileNameList); - }); + ->willReturnCallback(fn ($name) => in_array($name, $fileNameList)); // files that do not exist yet $this->assertEquals('doesNotExistYet', AttachmentService::getUniqueFileName($folder, 'doesNotExistYet')); @@ -162,7 +160,7 @@ public function testReplaceAttachmentFolderId(string $sourceContent, string $tar $target->method('getId')->willReturn(2); $target->method('getContent')->willReturn($sourceContent); $replacedContent = ''; - $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent) { + $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent): void { $replacedContent = $content; }); @@ -180,7 +178,7 @@ public function testReplaceAttachmentFolderIdNoReplace(string $sourceContent): v $target->method('getId')->willReturn(2); $target->method('getContent')->willReturn($sourceContent); $replacedContent = ''; - $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent) { + $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent): void { $replacedContent = $content; }); @@ -220,7 +218,7 @@ public function testReplaceAttachmentFileId(string $sourceContent, string $targe $target->method('getId')->willReturn(2); $target->method('getContent')->willReturn($sourceContent); $replacedContent = ''; - $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent) { + $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent): void { $replacedContent = $content; }); @@ -260,7 +258,7 @@ public function testReplaceAttachmentFileIdNoReplace(string $sourceContent): voi $target->method('getId')->willReturn(2); $target->method('getContent')->willReturn($sourceContent); $replacedContent = ''; - $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent) { + $target->method('putContent')->willReturnCallback(function (string $content) use (&$replacedContent): void { $replacedContent = $content; }); diff --git a/vendor-bin/rector/composer.json b/vendor-bin/rector/composer.json new file mode 100644 index 00000000000..7fd8cfbe5c4 --- /dev/null +++ b/vendor-bin/rector/composer.json @@ -0,0 +1,6 @@ +{ + "require-dev": { + "rector/rector": "^2.6", + "nextcloud/rector": "^0.5.2" + } +} diff --git a/vendor-bin/rector/composer.lock b/vendor-bin/rector/composer.lock new file mode 100644 index 00000000000..b8072224b57 --- /dev/null +++ b/vendor-bin/rector/composer.lock @@ -0,0 +1,621 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "d29cb1fd345dfbc89d8aebbf19f0e747", + "packages": [], + "packages-dev": [ + { + "name": "nextcloud/ocp", + "version": "v34.0.2", + "source": { + "type": "git", + "url": "https://github.com/nextcloud-deps/ocp.git", + "reference": "81cbb2c594afe0fa978885bf7accd0440199520a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/81cbb2c594afe0fa978885bf7accd0440199520a", + "reference": "81cbb2c594afe0fa978885bf7accd0440199520a", + "shasum": "" + }, + "require": { + "php": "~8.2 || ~8.3 || ~8.4 || ~8.5", + "psr/clock": "^1.0", + "psr/container": "^2.0.2", + "psr/event-dispatcher": "^1.0", + "psr/http-client": "^1.0.3", + "psr/log": "^3.0.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-stable34": "34.0.0-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + }, + { + "name": "Joas Schilling", + "email": "coding@schilljs.com" + } + ], + "description": "Composer package containing Nextcloud's public OCP API and the unstable NCU API", + "support": { + "issues": "https://github.com/nextcloud-deps/ocp/issues", + "source": "https://github.com/nextcloud-deps/ocp/tree/v34.0.2" + }, + "time": "2026-07-16T01:28:13+00:00" + }, + { + "name": "nextcloud/rector", + "version": "v0.5.2", + "source": { + "type": "git", + "url": "https://github.com/nextcloud-libraries/rector.git", + "reference": "9967d62256cd7507f1104491fb2c427456481b56" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud-libraries/rector/zipball/9967d62256cd7507f1104491fb2c427456481b56", + "reference": "9967d62256cd7507f1104491fb2c427456481b56", + "shasum": "" + }, + "require": { + "nextcloud/ocp": ">=27", + "php": "^8.1", + "rector/rector": "^2.0.4", + "webmozart/assert": "^1.11" + }, + "require-dev": { + "phpunit/phpunit": "^10.5", + "ramsey/devtools": "^2.0" + }, + "type": "library", + "extra": { + "captainhook": { + "force-install": true + }, + "ramsey/devtools": { + "memory-limit": "-1", + "command-prefix": "dev" + }, + "ramsey/conventional-commits": { + "configFile": "conventional-commits.json" + } + }, + "autoload": { + "psr-4": { + "OCP\\": "vendor/nextcloud/ocp/OCP", + "Nextcloud\\Rector\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at", + "homepage": "https://wuc.me" + } + ], + "description": "Rector upgrade rules for Nextcloud", + "keywords": [ + "nextcloud", + "refactoring" + ], + "support": { + "issues": "https://github.com/nextcloud-libraries/rector/issues", + "source": "https://github.com/nextcloud-libraries/rector/tree/v0.5.2" + }, + "time": "2026-06-15T06:39:12+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "2.2.8", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e285254e60f33c21902efef4a926ca0987c06804", + "reference": "e285254e60f33c21902efef4a926ca0987c06804", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ondřej Mirtes" + }, + { + "name": "Markus Staab" + }, + { + "name": "Vincent Langlet" + } + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2026-08-04T22:21:45+00:00" + }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Clock\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", + "keywords": [ + "clock", + "now", + "psr", + "psr-20", + "time" + ], + "support": { + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" + }, + "time": "2022-11-25T14:36:26+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "psr/event-dispatcher", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/event-dispatcher.git", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\EventDispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Standard interfaces for event handling.", + "keywords": [ + "events", + "psr", + "psr-14" + ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, + "time": "2019-01-08T18:20:26+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "psr/log", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.2" + }, + "time": "2024-09-11T13:17:53+00:00" + }, + { + "name": "rector/rector", + "version": "2.6.1", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "b8e68f058bca43e01a2e1caa51ef022d6551ed95" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/b8e68f058bca43e01a2e1caa51ef022d6551ed95", + "reference": "b8e68f058bca43e01a2e1caa51ef022d6551ed95", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.2.6" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.6.1" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2026-08-03T17:30:34+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.12.1", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "9be6926d8b485f55b9229203f962b51ed377ba68" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/9be6926d8b485f55b9229203f962b51ed377ba68", + "reference": "9be6926d8b485f55b9229203f962b51ed377ba68", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-date": "*", + "ext-filter": "*", + "php": "^7.2 || ^8.0" + }, + "suggest": { + "ext-intl": "", + "ext-simplexml": "", + "ext-spl": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.12.1" + }, + "time": "2025-10-29T15:56:20+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.9.0" +}