diff --git a/composer.json b/composer.json index 69c8c9fdde6..c282adb445f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.3|^8.0" + "php": "^7.4|^8.0" }, "scripts": { "lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l", diff --git a/composer.lock b/composer.lock index 45963ded209..92d9ed21ea2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b7304857559254ddd2054e835c029ff1", + "content-hash": "5fbae4730c1f4bec14f467f9f9d375f6", "packages": [], "packages-dev": [ { @@ -13,17 +13,17 @@ "source": { "type": "git", "url": "https://github.com/ChristophWurst/nextcloud_composer.git", - "reference": "56056903c03bf8c29b2a2822153951c8f783a85a" + "reference": "42b53effee9e232a9cf091760ee448d98eb2fae0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/56056903c03bf8c29b2a2822153951c8f783a85a", - "reference": "56056903c03bf8c29b2a2822153951c8f783a85a", + "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/42b53effee9e232a9cf091760ee448d98eb2fae0", + "reference": "42b53effee9e232a9cf091760ee448d98eb2fae0", "shasum": "" }, "require": { "php": "^7.4 || ~8.0 || ~8.1", - "psr/container": "^1.0", + "psr/container": "^1.1.1", "psr/event-dispatcher": "^1.0", "psr/log": "^1.1" }, @@ -31,7 +31,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "24.0.0-dev" + "dev-master": "25.0.0-dev" } }, "notification-url": "https://packagist.org/downloads/", @@ -49,7 +49,7 @@ "issues": "https://github.com/ChristophWurst/nextcloud_composer/issues", "source": "https://github.com/ChristophWurst/nextcloud_composer/tree/master" }, - "time": "2022-03-01T01:41:01+00:00" + "time": "2022-07-13T02:14:57+00:00" }, { "name": "composer/pcre", @@ -4590,7 +4590,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.3|^8.0" + "php": "^7.4|^8.0" }, "platform-dev": { "ext-mbstring": "*" diff --git a/lib/Command/ResetDocument.php b/lib/Command/ResetDocument.php index 6e972f08e5e..1fb18ecf564 100644 --- a/lib/Command/ResetDocument.php +++ b/lib/Command/ResetDocument.php @@ -33,10 +33,10 @@ use Symfony\Component\Console\Output\OutputInterface; class ResetDocument extends Command { - protected $documentService; - protected $documentMapper; - protected $stepMapper; - protected $sessionMapper; + protected DocumentService $documentService; + protected DocumentMapper $documentMapper; + protected StepMapper $stepMapper; + protected SessionMapper $sessionMapper; public function __construct(DocumentService $documentService, DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper) { parent::__construct(); diff --git a/lib/Controller/DirectSessionController.php b/lib/Controller/DirectSessionController.php index 366362cedea..aad732e57b2 100644 --- a/lib/Controller/DirectSessionController.php +++ b/lib/Controller/DirectSessionController.php @@ -51,27 +51,17 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; use OCP\DirectEditing\IManager; -use OCP\Share\IManager as ShareManager; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; use OCP\Share\IShare; class DirectSessionController extends Controller { + private IShare $share; + private ApiService $apiService; + private IManager $directManager; - /** @var ShareManager */ - private $shareManager; - - /** @var IShare */ - private $share; - - /** @var ApiService */ - private $apiService; - /** @var IManager */ - private $directManager; - - public function __construct(string $appName, IRequest $request, ShareManager $shareManager, ApiService $apiService, IManager $directManager) { + public function __construct(string $appName, IRequest $request, ApiService $apiService, IManager $directManager) { parent::__construct($appName, $request); - $this->shareManager = $shareManager; $this->apiService = $apiService; $this->directManager = $directManager; } diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index 4ccd5b3139c..b8b456392ab 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -27,7 +27,7 @@ use Exception; use OCA\Text\Service\SessionService; -use OCA\Text\UploadException; +use OCA\Text\Exception\UploadException; use OCP\AppFramework\Http; use OCA\Text\Service\ImageService; use OCP\AppFramework\Controller; @@ -52,26 +52,11 @@ class ImageController extends Controller { 'image/webp', ]; - /** - * @var ImageService - */ - private $imageService; - /** - * @var LoggerInterface - */ - private $logger; - /** - * @var SessionService - */ - private $sessionService; - /** - * @var IL10N - */ - private $l10n; - /** - * @var IMimeTypeDetector - */ - private $mimeTypeDetector; + private ImageService $imageService; + private LoggerInterface $logger; + private SessionService $sessionService; + private IL10N $l10n; + private IMimeTypeDetector $mimeTypeDetector; public function __construct(string $appName, IRequest $request, @@ -163,9 +148,6 @@ public function uploadImage(int $documentId, int $sessionId, string $sessionToke } } - /** - * @return array - */ private function getUploadedFile(string $key): array { $file = $this->request->getUploadedFile($key); $error = null; diff --git a/lib/Controller/PublicSessionController.php b/lib/Controller/PublicSessionController.php index 4eed2cad0f7..7ab05f68d39 100644 --- a/lib/Controller/PublicSessionController.php +++ b/lib/Controller/PublicSessionController.php @@ -36,15 +36,9 @@ use OCP\Share\IShare; class PublicSessionController extends PublicShareController { - - /** @var ShareManager */ - private $shareManager; - - /** @var IShare */ - private $share; - - /** @var ApiService */ - private $apiService; + private ShareManager $shareManager; + private ?IShare $share; + private ApiService $apiService; public function __construct(string $appName, IRequest $request, ISession $session, ShareManager $shareManager, ApiService $apiService) { parent::__construct($appName, $request, $session); diff --git a/lib/Controller/SessionController.php b/lib/Controller/SessionController.php index 0a294106874..e7e490a1bba 100644 --- a/lib/Controller/SessionController.php +++ b/lib/Controller/SessionController.php @@ -32,11 +32,7 @@ use OCP\IRequest; class SessionController extends Controller { - - /** - * @var ApiService - */ - private $apiService; + private ApiService $apiService; public function __construct(string $appName, IRequest $request, ApiService $apiService) { parent::__construct($appName, $request); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index f4f8c87ebe0..c55b3764934 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -31,11 +31,8 @@ use OCP\IRequest; class SettingsController extends Controller { - - /** - * @var IConfig - */ - private $config; + private IConfig $config; + private ?string $userId; public const ACCEPTED_KEYS = [ 'workspace_enabled' diff --git a/lib/Controller/WorkspaceController.php b/lib/Controller/WorkspaceController.php index 961d66b0772..31ef6ace052 100644 --- a/lib/Controller/WorkspaceController.php +++ b/lib/Controller/WorkspaceController.php @@ -69,24 +69,12 @@ use Psr\Log\LoggerInterface; class WorkspaceController extends OCSController { - - /** @var IRootFolder */ - private $rootFolder; - - /** @var IManager */ - private $shareManager; - - /** @var WorkspaceService */ - private $workspaceService; - - /** @var string|null */ - private $userId; - - /** @var IDirectEditingManager */ - private $directEditingManager; - - /** @var IURLGenerator */ - private $urlGenerator; + private IRootFolder $rootFolder; + private IManager $shareManager; + private WorkspaceService $workspaceService; + private ?string $userId; + private IDirectEditingManager $directEditingManager; + private IURLGenerator $urlGenerator; /** @var IEventDispatcher */ private $eventDispatcher; diff --git a/lib/Cron/Cleanup.php b/lib/Cron/Cleanup.php index 1c16bd18c96..7faf38888de 100644 --- a/lib/Cron/Cleanup.php +++ b/lib/Cron/Cleanup.php @@ -29,31 +29,25 @@ namespace OCA\Text\Cron; use OCA\Text\Db\Session; -use OCA\Text\DocumentHasUnsavedChangesException; +use OCA\Text\Exception\DocumentHasUnsavedChangesException; use OCA\Text\Service\DocumentService; use OCA\Text\Service\ImageService; use OCA\Text\Service\SessionService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; -use OCP\ILogger; +use Psr\Log\LoggerInterface; -/** - * Class Cache - * - * @package OCA\Social\Cron - */ class Cleanup extends TimedJob { - private $sessionService; - private $documentService; - private $logger; - private $imageService; - + private SessionService $sessionService; + private DocumentService $documentService; + private LoggerInterface $logger; + private ImageService $imageService; public function __construct(ITimeFactory $time, SessionService $sessionService, DocumentService $documentService, ImageService $imageService, - ILogger $logger) { + LoggerInterface $logger) { parent::__construct($time); $this->sessionService = $sessionService; $this->documentService = $documentService; @@ -81,6 +75,8 @@ protected function run($argument) { $this->logger->debug('Resetting document ' . $session->getDocumentId() . ''); } catch (DocumentHasUnsavedChangesException $e) { $this->logger->info('Document ' . $session->getDocumentId() . ' has not been reset, as it has unsaved changes'); + } catch (\Throwable $e) { + $this->logger->error('Document ' . $session->getDocumentId() . ' has not been reset, as an error occured', ['exception' => $e]); } } $removedSessions = $this->sessionService->removeInactiveSessions(null); diff --git a/lib/Db/Document.php b/lib/Db/Document.php index 65c8e19869c..92d911f633d 100644 --- a/lib/Db/Document.php +++ b/lib/Db/Document.php @@ -25,14 +25,29 @@ use OCP\AppFramework\Db\Entity; +/** + * @method getId(): int + * @method getCurrentVersion(): int + * @method setCurrentVersion(int $version): void + * @method getLastSavedVersion(): int + * @method setLastSavedVersion(int $version): void + * @method getInitialVersion(): int + * @method setInitialVersion(int $version): void + * @method getLastSavedVersionTime(): int + * @method setLastSavedVersionTime(int $time): void + * @method getLastSavedVersionEtag(): string + * @method setLastSavedVersionEtag(string $etag): void + * @method getBaseVersionEtag(): string + * @method setBaseVersionEtag(string $etag): void + */ class Document extends Entity implements \JsonSerializable { public $id; - protected $currentVersion = 0; - protected $lastSavedVersion = 0; - protected $initialVersion = 0; - protected $lastSavedVersionTime = 0; - protected $lastSavedVersionEtag = ''; - protected $baseVersionEtag = ''; + protected int $currentVersion = 0; + protected int $lastSavedVersion = 0; + protected int $initialVersion = 0; + protected int $lastSavedVersionTime = 0; + protected string $lastSavedVersionEtag = ''; + protected string $baseVersionEtag = ''; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/Session.php b/lib/Db/Session.php index 34d518aed63..91fffa3bd40 100644 --- a/lib/Db/Session.php +++ b/lib/Db/Session.php @@ -23,23 +23,31 @@ namespace OCA\Text\Db; +use JsonSerializable; use OCP\AppFramework\Db\Entity; /** - * @method int getLastContact() - * @method setLastContact(int $getTime) - * @method getDocumentId() - * @method getUserId() + * @method string getUserId() + * @method void setUserId(?string $userId) * @method string getToken() + * @method void setToken(string $token) + * @method string getColor() + * @method void setColor(string $color) + * @method string|null getGuestName() + * @method void setGuestName(string $guestName) + * @method int getLastContact() + * @method void setLastContact(int $getTime) + * @method int getDocumentId() + * @method void setDocumentId(int $documentId) */ -class Session extends Entity implements \JsonSerializable { +class Session extends Entity implements JsonSerializable { public $id; - protected $userId; - protected $token; - protected $color; - protected $guestName; - protected $lastContact; - protected $documentId; + protected ?string $userId = null; + protected string $token = ''; + protected string $color = ''; + protected ?string $guestName = null; + protected int $lastContact = 0; + protected int $documentId = 0; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/Step.php b/lib/Db/Step.php index fec0537bdac..92ae39d2d08 100644 --- a/lib/Db/Step.php +++ b/lib/Db/Step.php @@ -23,14 +23,24 @@ namespace OCA\Text\Db; +use JsonSerializable; use OCP\AppFramework\Db\Entity; -class Step extends Entity implements \JsonSerializable { - public $id; - protected $data; - protected $version; - protected $sessionId; - protected $documentId; +/** + * @method getData(): string + * @method setData(string $data): void + * @method getVersion(): int + * @method setVersion(int $version): void + * @method getSessionId(): int + * @method setSessionId(int $sessionId): void + * @method getDocumentId(): int + * @method setDocumentId(int $documentId): void + */ +class Step extends Entity implements JsonSerializable { + protected string $data = ''; + protected int $version = 0; + protected int $sessionId = 0; + protected int $documentId = 0; public function __construct() { $this->addType('id', 'integer'); diff --git a/lib/Db/StepMapper.php b/lib/Db/StepMapper.php index f0148efff30..a977c1629b5 100644 --- a/lib/Db/StepMapper.php +++ b/lib/Db/StepMapper.php @@ -53,7 +53,6 @@ public function find($documentId, $fromVersion, $lastAckedVersion = null) { } public function deleteAll($documentId): void { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) @@ -61,7 +60,6 @@ public function deleteAll($documentId): void { } public function deleteBeforeVersion($documentId, $version): void { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) @@ -70,11 +68,11 @@ public function deleteBeforeVersion($documentId, $version): void { } public function deleteAfterVersion($documentId, $version): int { - /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); - return $qb->delete($this->getTableName()) + $result = $qb->delete($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) ->andWhere($qb->expr()->gt('version', $qb->createNamedParameter($version))) ->execute(); + return $result->rowCount(); } } diff --git a/lib/DocumentHasUnsavedChangesException.php b/lib/Exception/DocumentHasUnsavedChangesException.php similarity index 94% rename from lib/DocumentHasUnsavedChangesException.php rename to lib/Exception/DocumentHasUnsavedChangesException.php index 2a1a10cbeee..812934bc925 100644 --- a/lib/DocumentHasUnsavedChangesException.php +++ b/lib/Exception/DocumentHasUnsavedChangesException.php @@ -1,4 +1,7 @@ * @@ -21,7 +24,7 @@ * */ -namespace OCA\Text; +namespace OCA\Text\Exception; class DocumentHasUnsavedChangesException extends \Exception { } diff --git a/lib/DocumentSaveConflictException.php b/lib/Exception/DocumentSaveConflictException.php similarity index 94% rename from lib/DocumentSaveConflictException.php rename to lib/Exception/DocumentSaveConflictException.php index 7f3df377ec7..dcb2a1914ae 100644 --- a/lib/DocumentSaveConflictException.php +++ b/lib/Exception/DocumentSaveConflictException.php @@ -1,4 +1,7 @@ * @@ -21,7 +24,7 @@ * */ -namespace OCA\Text; +namespace OCA\Text\Exception; class DocumentSaveConflictException extends \Exception { } diff --git a/lib/UploadException.php b/lib/Exception/UploadException.php similarity index 94% rename from lib/UploadException.php rename to lib/Exception/UploadException.php index 99ec932012e..b65722e1933 100644 --- a/lib/UploadException.php +++ b/lib/Exception/UploadException.php @@ -1,4 +1,7 @@ * @@ -21,7 +24,7 @@ * */ -namespace OCA\Text; +namespace OCA\Text\Exception; class UploadException extends \Exception { } diff --git a/lib/VersionMismatchException.php b/lib/Exception/VersionMismatchException.php similarity index 91% rename from lib/VersionMismatchException.php rename to lib/Exception/VersionMismatchException.php index b5c50bd6b99..931823bc8ae 100644 --- a/lib/VersionMismatchException.php +++ b/lib/Exception/VersionMismatchException.php @@ -1,4 +1,7 @@ * @@ -21,12 +24,12 @@ * */ -namespace OCA\Text; +namespace OCA\Text\Exception; use OCP\AppFramework\Http; class VersionMismatchException extends \Exception { - public function getStatus() { + public function getStatus(): int { return Http::STATUS_PRECONDITION_FAILED; } } diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 8b5fbfff3ab..51a824a95a2 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -29,10 +29,10 @@ use Exception; use OC\Files\Node\File; use OCA\Text\AppInfo\Application; -use OCA\Text\DocumentHasUnsavedChangesException; -use OCA\Text\DocumentSaveConflictException; +use OCA\Text\Exception\DocumentHasUnsavedChangesException; +use OCA\Text\Exception\DocumentSaveConflictException; use OCA\Text\TextFile; -use OCA\Text\VersionMismatchException; +use OCA\Text\Exception\VersionMismatchException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -41,24 +41,24 @@ use OCP\Constants; use OCP\Files\Lock\ILock; use OCP\Files\NotFoundException; -use OCP\ILogger; use OCP\IRequest; use OCP\Lock\LockedException; +use Psr\Log\LoggerInterface; class ApiService { - protected $request; - protected $sessionService; - protected $documentService; - protected $logger; - private $imageService; - private $encodingService; + private IRequest $request; + private SessionService $sessionService; + private DocumentService $documentService; + private LoggerInterface $logger; + private ImageService $imageService; + private EncodingService $encodingService; public function __construct(IRequest $request, SessionService $sessionService, DocumentService $documentService, ImageService $imageService, EncodingService $encodingService, - ILogger $logger) { + LoggerInterface $logger) { $this->request = $request; $this->sessionService = $sessionService; $this->documentService = $documentService; @@ -101,7 +101,7 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa $document = $this->documentService->createDocument($file); } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return new DataResponse('Failed to create the document session', 500); } @@ -112,10 +112,10 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa $content = $this->encodingService->encodeToUtf8($content); if ($content === null) { - $this->logger->log(ILogger::WARN, 'Failed to encode file to UTF8. File ID: ' . $file->getId()); + $this->logger->warning('Failed to encode file to UTF8. File ID: ' . $file->getId()); } } catch (NotFoundException $e) { - $this->logger->logException($e, ['level' => ILogger::INFO]); + $this->logger->info($e->getMessage(), ['exception' => $e]); $content = null; } @@ -167,7 +167,7 @@ public function close($documentId, $sessionId, $sessionToken): DataResponse { /** * @throws NotFoundException - * @throws \OCP\AppFramework\Db\DoesNotExistException + * @throws DoesNotExistException */ public function push($documentId, $sessionId, $sessionToken, $version, $steps, $token = null): DataResponse { $session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); @@ -198,12 +198,12 @@ public function sync($documentId, $sessionId, $sessionToken, $version = 0, $auto $session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); $file = $this->documentService->getFileForSession($session, $token); } catch (NotFoundException $e) { - $this->logger->logException($e, ['level' => ILogger::INFO]); + $this->logger->info($e->getMessage(), ['exception' => $e]); return new DataResponse([ 'message' => 'File not found' ], 404); } catch (DoesNotExistException $e) { - $this->logger->logException($e, ['level' => ILogger::INFO]); + $this->logger->info($e->getMessage(), ['exception' => $e]); return new DataResponse([ 'message' => 'Document no longer exists' ], 404); @@ -220,7 +220,7 @@ public function sync($documentId, $sessionId, $sessionToken, $version = 0, $auto } catch (NotFoundException $e) { return new DataResponse([], 404); } catch (Exception $e) { - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return new DataResponse([ 'message' => 'Failed to autosave document' ], 500); @@ -230,7 +230,7 @@ public function sync($documentId, $sessionId, $sessionToken, $version = 0, $auto } /** - * @throws \OCP\AppFramework\Db\DoesNotExistException + * @throws DoesNotExistException */ public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName): DataResponse { if (!$this->sessionService->isValidSession($documentId, $sessionId, $sessionToken)) { diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 6d372826f64..84f3b1a0be9 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -40,14 +40,15 @@ use OCP\IRequest; use OCP\Lock\ILockingProvider; use OCP\PreConditionNotMetException; +use Psr\Log\LoggerInterface; use function json_encode; use OCA\Text\Db\Document; use OCA\Text\Db\DocumentMapper; use OCA\Text\Db\Step; use OCA\Text\Db\StepMapper; -use OCA\Text\DocumentHasUnsavedChangesException; -use OCA\Text\DocumentSaveConflictException; -use OCA\Text\VersionMismatchException; +use OCA\Text\Exception\DocumentHasUnsavedChangesException; +use OCA\Text\Exception\DocumentSaveConflictException; +use OCA\Text\Exception\VersionMismatchException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\Entity; use OCP\Constants; @@ -62,7 +63,6 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\ICache; use OCP\ICacheFactory; -use OCP\ILogger; use OCP\Lock\LockedException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager as ShareManager; @@ -77,7 +77,7 @@ class DocumentService { private ?string $userId; private DocumentMapper $documentMapper; private SessionMapper $sessionMapper; - private ILogger $logger; + private LoggerInterface $logger; private ShareManager $shareManager; private StepMapper $stepMapper; private IRootFolder $rootFolder; @@ -85,9 +85,9 @@ class DocumentService { private IAppData $appData; private ILockingProvider $lockingProvider; private ILockManager $lockManager; - private $userMountCache; + private IUserMountCache $userMountCache; - public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, ILogger $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockingProvider $lockingProvider, ILockManager $lockManager, IUserMountCache $userMountCache) { + public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, LoggerInterface $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockingProvider $lockingProvider, ILockManager $lockManager, IUserMountCache $userMountCache) { $this->documentMapper = $documentMapper; $this->stepMapper = $stepMapper; $this->sessionMapper = $sessionMapper; @@ -228,7 +228,7 @@ public function addStep($documentId, $sessionId, $steps, $version): array { throw $e; } catch (\Throwable $e) { if ($document !== null && $oldVersion !== null) { - $this->logger->logException($e, ['message' => 'This should never happen. An error occured when storing the version, trying to recover the last stable one']); + $this->logger->error('This should never happen. An error occurred when storing the version, trying to recover the last stable one', ['exception' => $e]); $document->setCurrentVersion($oldVersion); $this->documentMapper->update($document); $this->cache->set('document-version-' . $document->getId(), $oldVersion); @@ -507,7 +507,7 @@ private function ensureDocumentsFolder(): bool { $this->appData->newFolder('documents'); } catch (\RuntimeException $e) { // Do not fail hard - $this->logger->logException($e); + $this->logger->error($e->getMessage(), ['exception' => $e]); return false; } diff --git a/lib/Service/WorkspaceService.php b/lib/Service/WorkspaceService.php index f44b1a2068a..e8039731f18 100644 --- a/lib/Service/WorkspaceService.php +++ b/lib/Service/WorkspaceService.php @@ -3,35 +3,32 @@ namespace OCA\Text\Service; +use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\NotFoundException; -use OCP\Files\StorageNotAvailableException; use OCP\IL10N; class WorkspaceService { + private IL10N $l10n; + private const SUPPORTED_STATIC_FILENAMES = [ 'README.md', 'Readme.md', 'readme.md' ]; - /** @var IL10N */ - private $l10n; - public function __construct(IL10N $l10n) { $this->l10n = $l10n; } - /** - * @param Folder $folder - * @throws StorageNotAvailableException - * @return \OCP\Files\File - */ - public function getFile(Folder $folder) { + public function getFile(Folder $folder): ?File { foreach ($this->getSupportedFilenames() as $filename) { if ($folder->nodeExists($filename)) { try { - return $folder->get($filename); + $file = $folder->get($filename); + if ($file instanceof File) { + return $file; + } } catch (NotFoundException $e) { } } diff --git a/lib/TextFile.php b/lib/TextFile.php index 9d632dcfef3..87420fcae55 100644 --- a/lib/TextFile.php +++ b/lib/TextFile.php @@ -34,34 +34,31 @@ * Wrapper around a ISimpleFile object to ensure that it is correctly encoded (UTF-8) for the text app. */ class TextFile implements ISimpleFile { - - /** @var ISimpleFile */ - private $file; - /** @var EncodingService */ - private $encodingService; + private ISimpleFile $file; + private EncodingService $encodingService; public function __construct(ISimpleFile $file, EncodingService $encodingService) { $this->file = $file; $this->encodingService = $encodingService; } - public function getName() { + public function getName(): string { return $this->file->getName(); } - public function getSize() { + public function getSize(): int { return $this->file->getSize(); } - public function getETag() { + public function getETag(): string { return $this->file->getETag(); } - public function getMTime() { + public function getMTime(): int { return $this->file->getMTime(); } - public function getContent() { + public function getContent(): string { $content = $this->encodingService->encodeToUtf8($this->file->getContent()); if ($content === null) { throw new NotFoundException('File not compatible with text because it could not be encoded to UTF-8.'); @@ -70,15 +67,15 @@ public function getContent() { return $content; } - public function putContent($data) { - return $this->file->putContent($data); + public function putContent($data): void { + $this->file->putContent($data); } - public function delete() { + public function delete(): void { $this->file->delete(); } - public function getMimeType() { + public function getMimeType(): string { return 'text/plain;encoding=utf-8'; } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 465ca2a6fe9..73e39a94682 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -15,14 +15,6 @@ InvalidTokenException - - - $this->userId - - - $this->userId - - DataResponse @@ -44,12 +36,6 @@ ServerPlugin - - - - int - - array @@ -85,26 +71,6 @@ \OC\User\NoUserException - - getCurrentVersion - getCurrentVersion - getCurrentVersion - getCurrentVersion - getCurrentVersion - getLastSavedVersion - getLastSavedVersion - getLastSavedVersionEtag - getLastSavedVersionTime - setCurrentVersion - setCurrentVersion - setData - setDocumentId - setLastSavedVersion - setLastSavedVersionEtag - setLastSavedVersionTime - setSessionId - setVersion - @@ -131,31 +97,6 @@ \OC\User\NoUserException - - - $color->b - $color->g - $color->r - $this->avatarManager->getGuestAvatar($uniqueGuestId)->avatarBackgroundColor($uniqueGuestId) - - - setColor - setColor - setDocumentId - setGuestName - setGuestName - setToken - setUserId - - - - - \OCP\Files\File - - - null - - $jobList