From 6ced56ac21688854cbf2ede41bfeceae7ea76797 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 2 Feb 2024 20:04:13 +0100 Subject: [PATCH] fix(cs:fix) Signed-off-by: Marcel Klehr --- lib/Activity/Provider.php | 2 +- lib/Db/TreeMapper.php | 12 ++++++------ lib/Events/MoveEvent.php | 2 +- lib/Middleware/ExceptionMiddleware.php | 2 +- lib/QueryParameters.php | 2 +- lib/Service/Authorizer.php | 4 ++-- lib/Service/BookmarkService.php | 6 +++--- lib/Service/BookmarksParser.php | 10 +++++----- lib/Service/FaviconPreviewer.php | 2 +- lib/Service/HtmlImporter.php | 4 ++-- lib/Service/Previewers/DefaultBookmarkPreviewer.php | 2 +- .../Previewers/ScreeenlyBookmarkPreviewer.php | 4 ++-- .../ScreenshotMachineBookmarkPreviewer.php | 2 +- lib/Service/Previewers/WebshotBookmarkPreviewer.php | 4 ++-- 14 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php index 18f49fcf2f..71cd4c3059 100644 --- a/lib/Activity/Provider.php +++ b/lib/Activity/Provider.php @@ -54,7 +54,7 @@ public function __construct(IFactory $languageFactory, IURLGenerator $url, IUser /** * @inheritDoc */ - public function parse($language, IEvent $event, IEvent $previousEvent = null) { + public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { if ($event->getApp() !== 'bookmarks') { throw new InvalidArgumentException(); } diff --git a/lib/Db/TreeMapper.php b/lib/Db/TreeMapper.php index f32923fcd9..6fa789a6b6 100644 --- a/lib/Db/TreeMapper.php +++ b/lib/Db/TreeMapper.php @@ -178,7 +178,7 @@ protected function findEntityWithType(IQueryBuilder $query, string $type): Entit * @param IQueryBuilder|null $queryBuilder * @return IQueryBuilder */ - protected function selectFromType(string $type, array $cols = [], IQueryBuilder $queryBuilder = null): IQueryBuilder { + protected function selectFromType(string $type, array $cols = [], ?IQueryBuilder $queryBuilder = null): IQueryBuilder { $qb = $queryBuilder ?? $this->db->getQueryBuilder(); $qb->resetQueryPart('from'); $qb @@ -318,7 +318,7 @@ public function hasDescendant(int $folderId, string $type, int $descendantId): b $ancestors = array_flatten(array_map(function (Entity $ancestor) { return $this->findParentsOf(self::TYPE_FOLDER, $ancestor->getId()); }, $ancestors)); - if (0 === count($ancestors)) { + if (count($ancestors) === 0) { return false; } } @@ -336,7 +336,7 @@ public function hasDescendant(int $folderId, string $type, int $descendantId): b * @throws MultipleObjectsReturnedException * @throws UnsupportedOperation */ - public function deleteEntry(string $type, int $id, int $folderId = null): void { + public function deleteEntry(string $type, int $id, ?int $folderId = null): void { $this->eventDispatcher->dispatch(BeforeDeleteEvent::class, new BeforeDeleteEvent($type, $id)); if ($type === self::TYPE_FOLDER) { @@ -439,7 +439,7 @@ public function deleteShare(int $shareId): void { * @throws MultipleObjectsReturnedException * @throws UnsupportedOperation */ - public function move(string $type, int $itemId, int $newParentFolderId, int $index = null): void { + public function move(string $type, int $itemId, int $newParentFolderId, ?int $index = null): void { if ($type === self::TYPE_BOOKMARK) { throw new UnsupportedOperation('Cannot move Bookmark'); } @@ -515,7 +515,7 @@ public function setToFolders(string $type, int $itemId, array $folders): void { if ($type !== self::TYPE_BOOKMARK) { throw new UnsupportedOperation('Only bookmarks can be in multiple folders'); } - if (0 === count($folders)) { + if (count($folders) === 0) { return; } @@ -537,7 +537,7 @@ public function setToFolders(string $type, int $itemId, array $folders): void { * @param int|null $index * @throws UnsupportedOperation|Exception */ - public function addToFolders(string $type, int $itemId, array $folders, int $index = null): void { + public function addToFolders(string $type, int $itemId, array $folders, ?int $index = null): void { if ($type !== self::TYPE_BOOKMARK) { throw new UnsupportedOperation('Only bookmarks can be in multiple folders'); } diff --git a/lib/Events/MoveEvent.php b/lib/Events/MoveEvent.php index 8b20bf79da..3eb37fa036 100644 --- a/lib/Events/MoveEvent.php +++ b/lib/Events/MoveEvent.php @@ -19,7 +19,7 @@ class MoveEvent extends ChangeEvent { * @param int|null $oldParent * @param int|null $newParent */ - public function __construct(string $type, int $id, int $oldParent = null, int $newParent = null) { + public function __construct(string $type, int $id, ?int $oldParent = null, ?int $newParent = null) { parent::__construct($type, $id); $this->oldParent = $oldParent; $this->newParent = $newParent; diff --git a/lib/Middleware/ExceptionMiddleware.php b/lib/Middleware/ExceptionMiddleware.php index b1de343e00..c96f8cd602 100644 --- a/lib/Middleware/ExceptionMiddleware.php +++ b/lib/Middleware/ExceptionMiddleware.php @@ -7,7 +7,6 @@ namespace OCA\Bookmarks\Middleware; -use \OCP\AppFramework\Middleware; use OCA\Bookmarks\Controller\BookmarkController; use OCA\Bookmarks\Controller\FoldersController; use OCA\Bookmarks\Controller\InternalBookmarkController; @@ -15,6 +14,7 @@ use OCA\Bookmarks\Exception\UnauthenticatedError; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Middleware; class ExceptionMiddleware extends Middleware { public function afterException($controller, $methodName, \Exception $exception): DataResponse { diff --git a/lib/QueryParameters.php b/lib/QueryParameters.php index f12e87cc55..80fbca7944 100644 --- a/lib/QueryParameters.php +++ b/lib/QueryParameters.php @@ -100,7 +100,7 @@ public function setOffset(int $offset): self { * @param array|null $columns * @return string|null */ - public function getSortBy(string $default = null, array $columns = null): ?string { + public function getSortBy(?string $default = null, ?array $columns = null): ?string { if (isset($default) && !isset($this->sortBy)) { return $default; } diff --git a/lib/Service/Authorizer.php b/lib/Service/Authorizer.php index 0178e189ce..7a2aa2660c 100644 --- a/lib/Service/Authorizer.php +++ b/lib/Service/Authorizer.php @@ -78,7 +78,7 @@ public function setCredentials(IRequest $request): void { $this->setUserId($this->userSession->getUser()->getUID()); return; } - if (false === $this->userSession->login($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW'])) { + if ($this->userSession->login($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW']) === false) { return; } $this->setUserId($this->userSession->getUser()->getUID()); @@ -90,7 +90,7 @@ public function setCredentials(IRequest $request): void { return; } [$username, $password] = explode(':', base64_decode($credentials)); - if (false === $this->userSession->login($username, $password)) { + if ($this->userSession->login($username, $password) === false) { return; } $this->setUserId($this->userSession->getUser()->getUID()); diff --git a/lib/Service/BookmarkService.php b/lib/Service/BookmarkService.php index 50463c1e2e..7c7e7862fa 100644 --- a/lib/Service/BookmarkService.php +++ b/lib/Service/BookmarkService.php @@ -131,7 +131,7 @@ public function __construct(BookmarkMapper $bookmarkMapper, FolderMapper $folder * @throws UrlParseError * @throws UserLimitExceededError */ - public function create(string $userId, string $url = '', string $title = null, string $description = null, array $tags = null, $folders = []): Bookmark { + public function create(string $userId, string $url = '', ?string $title = null, ?string $description = null, ?array $tags = null, $folders = []): Bookmark { $bookmark = null; $ownFolders = array_filter($folders, function ($folderId) use ($userId) { /** @@ -174,7 +174,7 @@ public function create(string $userId, string $url = '', string $title = null, s * @throws UserLimitExceededError * @throws UnsupportedOperation */ - private function _addBookmark($userId, $url, string $title = null, $description = null, array $tags = null, array $folders = []): Bookmark { + private function _addBookmark($userId, $url, ?string $title = null, $description = null, ?array $tags = null, array $folders = []): Bookmark { $bookmark = null; try { @@ -268,7 +268,7 @@ private function _addBookmark($userId, $url, string $title = null, $description * @throws UrlParseError * @throws UserLimitExceededError */ - public function update(string $userId, $id, string $url = null, string $title = null, string $description = null, array $tags = null, array $folders = null): ?Bookmark { + public function update(string $userId, $id, ?string $url = null, ?string $title = null, ?string $description = null, ?array $tags = null, ?array $folders = null): ?Bookmark { /** * @var $bookmark Bookmark */ diff --git a/lib/Service/BookmarksParser.php b/lib/Service/BookmarksParser.php index 2cb74fa907..8798075f12 100644 --- a/lib/Service/BookmarksParser.php +++ b/lib/Service/BookmarksParser.php @@ -96,7 +96,7 @@ public function __construct($useInternalErrors = true) { * @return boolean */ public static function isValid($doctype): bool { - return self::DOCTYPE === $doctype; + return $doctype === self::DOCTYPE; } /** @@ -117,7 +117,7 @@ public function parse($input, $ignorePersonalToolbarFolder = true, $includeFolde if (empty($input)) { throw new HtmlParseError("The input shouldn't be empty"); } - if (false === $document->loadHTML($input, LIBXML_PARSEHUGE)) { + if ($document->loadHTML($input, LIBXML_PARSEHUGE) === false) { throw new HtmlParseError('The HTML value does not appear to be valid Netscape Bookmark File Format HTML.'); } $this->xpath = new DOMXPath($document); @@ -138,7 +138,7 @@ public function parse($input, $ignorePersonalToolbarFolder = true, $includeFolde * * @param DOMNode|null $node */ - private function traverse(DOMNode $node = null): void { + private function traverse(?DOMNode $node = null): void { $query = './*'; $entries = $this->xpath->query($query, $node ?: null); if (!$entries) { @@ -268,7 +268,7 @@ private function getAttributes(DOMNode $node): array { if ($this->useDateTimeObjects) { if (isset($attributes['add_date'])) { $added = new DateTime(); - if (self::THOUSAND_YEARS < (int)$attributes['add_date']) { + if ((int)$attributes['add_date'] > self::THOUSAND_YEARS) { // Google exports dates in miliseconds. This way we only lose the first year of UNIX Epoch. // This is invalid once we hit 2970. So, quite a long time. $added->setTimestamp((int) ($attributes['add_date'] / 1000)); @@ -297,7 +297,7 @@ private function getAttributes(DOMNode $node): array { private function getCurrentFolderTags(): array { $tags = []; array_walk_recursive($this->currentFolder, static function ($tag, $key) use (&$tags) { - if ('name' === $key) { + if ($key === 'name') { $tags[] = $tag; } }); diff --git a/lib/Service/FaviconPreviewer.php b/lib/Service/FaviconPreviewer.php index cf6b1c5809..3e4b572eca 100644 --- a/lib/Service/FaviconPreviewer.php +++ b/lib/Service/FaviconPreviewer.php @@ -134,7 +134,7 @@ protected function fetchImage(string $url): ?Image { $contentType = $response->getHeader('Content-Type'); // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } diff --git a/lib/Service/HtmlImporter.php b/lib/Service/HtmlImporter.php index 39a61985e1..a203d3a5f4 100644 --- a/lib/Service/HtmlImporter.php +++ b/lib/Service/HtmlImporter.php @@ -90,7 +90,7 @@ public function __construct(BookmarkMapper $bookmarkMapper, FolderMapper $folder * @throws UserLimitExceededError * @throws HtmlParseError */ - public function importFile($userId, string $file, int $rootFolder = null): array { + public function importFile($userId, string $file, ?int $rootFolder = null): array { $content = file_get_contents($file); return $this->import($userId, $content, $rootFolder); } @@ -113,7 +113,7 @@ public function importFile($userId, string $file, int $rootFolder = null): array * * @psalm-return array{imported: list, errors: array} */ - public function import($userId, string $content, int $rootFolderId = null): array { + public function import($userId, string $content, ?int $rootFolderId = null): array { $imported = []; $errors = []; diff --git a/lib/Service/Previewers/DefaultBookmarkPreviewer.php b/lib/Service/Previewers/DefaultBookmarkPreviewer.php index 641748dd22..5d1398684f 100644 --- a/lib/Service/Previewers/DefaultBookmarkPreviewer.php +++ b/lib/Service/Previewers/DefaultBookmarkPreviewer.php @@ -80,7 +80,7 @@ protected function fetchImage($url): ?Image { $contentType = $response->getHeader('Content-Type'); // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } diff --git a/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php b/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php index f1c277295c..92405b57ff 100644 --- a/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php +++ b/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php @@ -67,7 +67,7 @@ public function getImage($bookmark): ?IImage { if (!isset($bookmark)) { return null; } - if ('' === $this->apiKey) { + if ($this->apiKey === '') { return null; } $url = $bookmark->getUrl(); @@ -97,7 +97,7 @@ public function fetchImage($url): ?Image { } // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } diff --git a/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php b/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php index 8f6c653713..d645dbbc8c 100644 --- a/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php +++ b/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php @@ -84,7 +84,7 @@ public function fetchImage($url): ?Image { ] ); // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } $body = $response->getBody(); diff --git a/lib/Service/Previewers/WebshotBookmarkPreviewer.php b/lib/Service/Previewers/WebshotBookmarkPreviewer.php index 93afd6bf3a..7d79cd8bcd 100644 --- a/lib/Service/Previewers/WebshotBookmarkPreviewer.php +++ b/lib/Service/Previewers/WebshotBookmarkPreviewer.php @@ -93,7 +93,7 @@ public function fetchImage($url): ?Image { 'timeout' => self::HTTP_TIMEOUT, ]); // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } $data = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR); @@ -101,7 +101,7 @@ public function fetchImage($url): ?Image { // get it $response = $this->client->get($this->apiUrl . $data->id); // Some HTPP Error occured :/ - if (200 !== $response->getStatusCode()) { + if ($response->getStatusCode() !== 200) { return null; } $body = $response->getBody();