diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php index 18f49fcf..71cd4c30 100644 --- a/lib/Activity/Provider.php +++ b/lib/Activity/Provider.php @@ -54,7 +54,7 @@ class Provider implements IProvider { /** * @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 f32923fc..6fa789a6 100644 --- a/lib/Db/TreeMapper.php +++ b/lib/Db/TreeMapper.php @@ -178,7 +178,7 @@ class TreeMapper extends QBMapper { * @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 @@ class TreeMapper extends QBMapper { $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 @@ class TreeMapper extends QBMapper { * @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 @@ class TreeMapper extends QBMapper { * @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 @@ class TreeMapper extends QBMapper { 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 @@ class TreeMapper extends QBMapper { * @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 8b20bf79..3eb37fa0 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 b1de343e..c96f8cd6 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\Controller\InternalFoldersController; 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 f12e87cc..80fbca79 100644 --- a/lib/QueryParameters.php +++ b/lib/QueryParameters.php @@ -100,7 +100,7 @@ class QueryParameters { * @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 0178e189..7a2aa266 100644 --- a/lib/Service/Authorizer.php +++ b/lib/Service/Authorizer.php @@ -78,7 +78,7 @@ class Authorizer { $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 @@ class Authorizer { 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 50463c1e..7c7e7862 100644 --- a/lib/Service/BookmarkService.php +++ b/lib/Service/BookmarkService.php @@ -131,7 +131,7 @@ class BookmarkService { * @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 @@ class BookmarkService { * @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 @@ class BookmarkService { * @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 2cb74fa9..8798075f 100644 --- a/lib/Service/BookmarksParser.php +++ b/lib/Service/BookmarksParser.php @@ -96,7 +96,7 @@ class BookmarksParser { * @return boolean */ public static function isValid($doctype): bool { - return self::DOCTYPE === $doctype; + return $doctype === self::DOCTYPE; } /** @@ -117,7 +117,7 @@ class BookmarksParser { 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 @@ class BookmarksParser { * * @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 @@ class BookmarksParser { 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 @@ class BookmarksParser { 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 cf6b1c58..3e4b572e 100644 --- a/lib/Service/FaviconPreviewer.php +++ b/lib/Service/FaviconPreviewer.php @@ -134,7 +134,7 @@ class FaviconPreviewer implements IBookmarkPreviewer { $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 39a61985..a203d3a5 100644 --- a/lib/Service/HtmlImporter.php +++ b/lib/Service/HtmlImporter.php @@ -90,7 +90,7 @@ class HtmlImporter { * @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 @@ class HtmlImporter { * * @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 641748dd..5d139868 100644 --- a/lib/Service/Previewers/DefaultBookmarkPreviewer.php +++ b/lib/Service/Previewers/DefaultBookmarkPreviewer.php @@ -80,7 +80,7 @@ class DefaultBookmarkPreviewer implements IBookmarkPreviewer { $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 f1c27729..92405b57 100644 --- a/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php +++ b/lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php @@ -67,7 +67,7 @@ class ScreeenlyBookmarkPreviewer implements IBookmarkPreviewer { if (!isset($bookmark)) { return null; } - if ('' === $this->apiKey) { + if ($this->apiKey === '') { return null; } $url = $bookmark->getUrl(); @@ -97,7 +97,7 @@ class ScreeenlyBookmarkPreviewer implements IBookmarkPreviewer { } // 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 8f6c6537..d645dbbc 100644 --- a/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php +++ b/lib/Service/Previewers/ScreenshotMachineBookmarkPreviewer.php @@ -84,7 +84,7 @@ class ScreenshotMachineBookmarkPreviewer implements IBookmarkPreviewer { ] ); // 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 93afd6bf..7d79cd8b 100644 --- a/lib/Service/Previewers/WebshotBookmarkPreviewer.php +++ b/lib/Service/Previewers/WebshotBookmarkPreviewer.php @@ -93,7 +93,7 @@ class WebshotBookmarkPreviewer implements IBookmarkPreviewer { '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 @@ class WebshotBookmarkPreviewer implements IBookmarkPreviewer { // 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();