Skip to content

Commit

Permalink
fix(cs:fix)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Feb 2, 2024
1 parent ebc52b0 commit 6ced56a
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Db/TreeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Events/MoveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Middleware/ExceptionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace OCA\Bookmarks\Middleware;

use \OCP\AppFramework\Middleware;
use OCA\Bookmarks\Controller\BookmarkController;
use OCA\Bookmarks\Controller\FoldersController;
use OCA\Bookmarks\Controller\InternalBookmarkController;
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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/QueryParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/BookmarkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
*/
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/BookmarksParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FaviconPreviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Service/HtmlImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -113,7 +113,7 @@ public function importFile($userId, string $file, int $rootFolder = null): array
*
* @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 = [];
$errors = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Previewers/DefaultBookmarkPreviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Previewers/ScreeenlyBookmarkPreviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -97,7 +97,7 @@ public function fetchImage($url): ?Image {
}

// Some HTPP Error occured :/
if (200 !== $response->getStatusCode()) {
if ($response->getStatusCode() !== 200) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Previewers/WebshotBookmarkPreviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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);

// 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();
Expand Down

0 comments on commit 6ced56a

Please sign in to comment.