fix(cs:fix)

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-02-02 20:04:13 +01:00
parent ebc52b0093
commit 6ced56ac21
14 changed files with 29 additions and 29 deletions

View File

@ -54,7 +54,7 @@ class Provider implements IProvider {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function parse($language, IEvent $event, IEvent $previousEvent = null) { public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($event->getApp() !== 'bookmarks') { if ($event->getApp() !== 'bookmarks') {
throw new InvalidArgumentException(); throw new InvalidArgumentException();
} }

View File

@ -178,7 +178,7 @@ class TreeMapper extends QBMapper {
* @param IQueryBuilder|null $queryBuilder * @param IQueryBuilder|null $queryBuilder
* @return IQueryBuilder * @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 = $queryBuilder ?? $this->db->getQueryBuilder();
$qb->resetQueryPart('from'); $qb->resetQueryPart('from');
$qb $qb
@ -318,7 +318,7 @@ class TreeMapper extends QBMapper {
$ancestors = array_flatten(array_map(function (Entity $ancestor) { $ancestors = array_flatten(array_map(function (Entity $ancestor) {
return $this->findParentsOf(self::TYPE_FOLDER, $ancestor->getId()); return $this->findParentsOf(self::TYPE_FOLDER, $ancestor->getId());
}, $ancestors)); }, $ancestors));
if (0 === count($ancestors)) { if (count($ancestors) === 0) {
return false; return false;
} }
} }
@ -336,7 +336,7 @@ class TreeMapper extends QBMapper {
* @throws MultipleObjectsReturnedException * @throws MultipleObjectsReturnedException
* @throws UnsupportedOperation * @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)); $this->eventDispatcher->dispatch(BeforeDeleteEvent::class, new BeforeDeleteEvent($type, $id));
if ($type === self::TYPE_FOLDER) { if ($type === self::TYPE_FOLDER) {
@ -439,7 +439,7 @@ class TreeMapper extends QBMapper {
* @throws MultipleObjectsReturnedException * @throws MultipleObjectsReturnedException
* @throws UnsupportedOperation * @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) { if ($type === self::TYPE_BOOKMARK) {
throw new UnsupportedOperation('Cannot move Bookmark'); throw new UnsupportedOperation('Cannot move Bookmark');
} }
@ -515,7 +515,7 @@ class TreeMapper extends QBMapper {
if ($type !== self::TYPE_BOOKMARK) { if ($type !== self::TYPE_BOOKMARK) {
throw new UnsupportedOperation('Only bookmarks can be in multiple folders'); throw new UnsupportedOperation('Only bookmarks can be in multiple folders');
} }
if (0 === count($folders)) { if (count($folders) === 0) {
return; return;
} }
@ -537,7 +537,7 @@ class TreeMapper extends QBMapper {
* @param int|null $index * @param int|null $index
* @throws UnsupportedOperation|Exception * @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) { if ($type !== self::TYPE_BOOKMARK) {
throw new UnsupportedOperation('Only bookmarks can be in multiple folders'); throw new UnsupportedOperation('Only bookmarks can be in multiple folders');
} }

View File

@ -19,7 +19,7 @@ class MoveEvent extends ChangeEvent {
* @param int|null $oldParent * @param int|null $oldParent
* @param int|null $newParent * @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); parent::__construct($type, $id);
$this->oldParent = $oldParent; $this->oldParent = $oldParent;
$this->newParent = $newParent; $this->newParent = $newParent;

View File

@ -7,7 +7,6 @@
namespace OCA\Bookmarks\Middleware; namespace OCA\Bookmarks\Middleware;
use \OCP\AppFramework\Middleware;
use OCA\Bookmarks\Controller\BookmarkController; use OCA\Bookmarks\Controller\BookmarkController;
use OCA\Bookmarks\Controller\FoldersController; use OCA\Bookmarks\Controller\FoldersController;
use OCA\Bookmarks\Controller\InternalBookmarkController; use OCA\Bookmarks\Controller\InternalBookmarkController;
@ -15,6 +14,7 @@ use OCA\Bookmarks\Controller\InternalFoldersController;
use OCA\Bookmarks\Exception\UnauthenticatedError; use OCA\Bookmarks\Exception\UnauthenticatedError;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Middleware;
class ExceptionMiddleware extends Middleware { class ExceptionMiddleware extends Middleware {
public function afterException($controller, $methodName, \Exception $exception): DataResponse { public function afterException($controller, $methodName, \Exception $exception): DataResponse {

View File

@ -100,7 +100,7 @@ class QueryParameters {
* @param array|null $columns * @param array|null $columns
* @return string|null * @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)) { if (isset($default) && !isset($this->sortBy)) {
return $default; return $default;
} }

View File

@ -78,7 +78,7 @@ class Authorizer {
$this->setUserId($this->userSession->getUser()->getUID()); $this->setUserId($this->userSession->getUser()->getUID());
return; 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; return;
} }
$this->setUserId($this->userSession->getUser()->getUID()); $this->setUserId($this->userSession->getUser()->getUID());
@ -90,7 +90,7 @@ class Authorizer {
return; return;
} }
[$username, $password] = explode(':', base64_decode($credentials)); [$username, $password] = explode(':', base64_decode($credentials));
if (false === $this->userSession->login($username, $password)) { if ($this->userSession->login($username, $password) === false) {
return; return;
} }
$this->setUserId($this->userSession->getUser()->getUID()); $this->setUserId($this->userSession->getUser()->getUID());

View File

@ -131,7 +131,7 @@ class BookmarkService {
* @throws UrlParseError * @throws UrlParseError
* @throws UserLimitExceededError * @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; $bookmark = null;
$ownFolders = array_filter($folders, function ($folderId) use ($userId) { $ownFolders = array_filter($folders, function ($folderId) use ($userId) {
/** /**
@ -174,7 +174,7 @@ class BookmarkService {
* @throws UserLimitExceededError * @throws UserLimitExceededError
* @throws UnsupportedOperation * @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; $bookmark = null;
try { try {
@ -268,7 +268,7 @@ class BookmarkService {
* @throws UrlParseError * @throws UrlParseError
* @throws UserLimitExceededError * @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 * @var $bookmark Bookmark
*/ */

View File

@ -96,7 +96,7 @@ class BookmarksParser {
* @return boolean * @return boolean
*/ */
public static function isValid($doctype): bool { public static function isValid($doctype): bool {
return self::DOCTYPE === $doctype; return $doctype === self::DOCTYPE;
} }
/** /**
@ -117,7 +117,7 @@ class BookmarksParser {
if (empty($input)) { if (empty($input)) {
throw new HtmlParseError("The input shouldn't be empty"); 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.'); throw new HtmlParseError('The HTML value does not appear to be valid Netscape Bookmark File Format HTML.');
} }
$this->xpath = new DOMXPath($document); $this->xpath = new DOMXPath($document);
@ -138,7 +138,7 @@ class BookmarksParser {
* *
* @param DOMNode|null $node * @param DOMNode|null $node
*/ */
private function traverse(DOMNode $node = null): void { private function traverse(?DOMNode $node = null): void {
$query = './*'; $query = './*';
$entries = $this->xpath->query($query, $node ?: null); $entries = $this->xpath->query($query, $node ?: null);
if (!$entries) { if (!$entries) {
@ -268,7 +268,7 @@ class BookmarksParser {
if ($this->useDateTimeObjects) { if ($this->useDateTimeObjects) {
if (isset($attributes['add_date'])) { if (isset($attributes['add_date'])) {
$added = new DateTime(); $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. // 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. // This is invalid once we hit 2970. So, quite a long time.
$added->setTimestamp((int) ($attributes['add_date'] / 1000)); $added->setTimestamp((int) ($attributes['add_date'] / 1000));
@ -297,7 +297,7 @@ class BookmarksParser {
private function getCurrentFolderTags(): array { private function getCurrentFolderTags(): array {
$tags = []; $tags = [];
array_walk_recursive($this->currentFolder, static function ($tag, $key) use (&$tags) { array_walk_recursive($this->currentFolder, static function ($tag, $key) use (&$tags) {
if ('name' === $key) { if ($key === 'name') {
$tags[] = $tag; $tags[] = $tag;
} }
}); });

View File

@ -134,7 +134,7 @@ class FaviconPreviewer implements IBookmarkPreviewer {
$contentType = $response->getHeader('Content-Type'); $contentType = $response->getHeader('Content-Type');
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }

View File

@ -90,7 +90,7 @@ class HtmlImporter {
* @throws UserLimitExceededError * @throws UserLimitExceededError
* @throws HtmlParseError * @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); $content = file_get_contents($file);
return $this->import($userId, $content, $rootFolder); return $this->import($userId, $content, $rootFolder);
} }
@ -113,7 +113,7 @@ class HtmlImporter {
* *
* @psalm-return array{imported: list<array>, errors: array<array-key, mixed|string>} * @psalm-return array{imported: list<array>, errors: array<array-key, mixed|string>}
*/ */
public function import($userId, string $content, int $rootFolderId = null): array { public function import($userId, string $content, ?int $rootFolderId = null): array {
$imported = []; $imported = [];
$errors = []; $errors = [];

View File

@ -80,7 +80,7 @@ class DefaultBookmarkPreviewer implements IBookmarkPreviewer {
$contentType = $response->getHeader('Content-Type'); $contentType = $response->getHeader('Content-Type');
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }

View File

@ -67,7 +67,7 @@ class ScreeenlyBookmarkPreviewer implements IBookmarkPreviewer {
if (!isset($bookmark)) { if (!isset($bookmark)) {
return null; return null;
} }
if ('' === $this->apiKey) { if ($this->apiKey === '') {
return null; return null;
} }
$url = $bookmark->getUrl(); $url = $bookmark->getUrl();
@ -97,7 +97,7 @@ class ScreeenlyBookmarkPreviewer implements IBookmarkPreviewer {
} }
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }

View File

@ -84,7 +84,7 @@ class ScreenshotMachineBookmarkPreviewer implements IBookmarkPreviewer {
] ]
); );
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }
$body = $response->getBody(); $body = $response->getBody();

View File

@ -93,7 +93,7 @@ class WebshotBookmarkPreviewer implements IBookmarkPreviewer {
'timeout' => self::HTTP_TIMEOUT, 'timeout' => self::HTTP_TIMEOUT,
]); ]);
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }
$data = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR); $data = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
@ -101,7 +101,7 @@ class WebshotBookmarkPreviewer implements IBookmarkPreviewer {
// get it // get it
$response = $this->client->get($this->apiUrl . $data->id); $response = $this->client->get($this->apiUrl . $data->id);
// Some HTPP Error occured :/ // Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) { if ($response->getStatusCode() !== 200) {
return null; return null;
} }
$body = $response->getBody(); $body = $response->getBody();