From 6d0d4d457751b794a4cf52f4f17844c56cb073a1 Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Sun, 19 Sep 2021 21:43:03 -0300 Subject: [PATCH] Add return types to Attach --- lib/Db/Attach.php | 6 +++--- lib/Db/AttachMapper.php | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/Db/Attach.php b/lib/Db/Attach.php index f27f67c..a542f5b 100644 --- a/lib/Db/Attach.php +++ b/lib/Db/Attach.php @@ -14,15 +14,15 @@ class Attach extends Entity implements JsonSerializable { protected $redirectUrl; protected $deepLinkUrl; - public function setPreviewUrl($previewUrl) { + public function setPreviewUrl(string $previewUrl): void { $this->previewUrl = $previewUrl; } - public function setRedirectUrl($redirectUrl) { + public function setRedirectUrl(string $redirectUrl): void { $this->redirectUrl = $redirectUrl; } - public function setDeepLinkUrl($deepLinkUrl) { + public function setDeepLinkUrl(string $deepLinkUrl): void { $this->deepLinkUrl = $deepLinkUrl; } diff --git a/lib/Db/AttachMapper.php b/lib/Db/AttachMapper.php index 158b085..42a6701 100644 --- a/lib/Db/AttachMapper.php +++ b/lib/Db/AttachMapper.php @@ -7,6 +7,8 @@ use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCA\QuickNotes\Db\Attach; + class AttachMapper extends QBMapper { public function __construct(IDBConnection $db) { @@ -20,7 +22,7 @@ class AttachMapper extends QBMapper { * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Attach */ - public function find($id, $userId) { + public function find($id, $userId): Attach { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) @@ -31,7 +33,10 @@ class AttachMapper extends QBMapper { return $this->findEntity($qb); } - public function findAll($userId) { + /** + * @return Attach[] + */ + public function findAll($userId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) @@ -48,7 +53,7 @@ class AttachMapper extends QBMapper { * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Attach */ - public function findFileAttachFromNote($userId, $noteId, $fileId) { + public function findFileAttachFromNote($userId, $noteId, $fileId): Attach { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) @@ -60,13 +65,16 @@ class AttachMapper extends QBMapper { return $this->findEntity($qb); } - public function fileAttachExists($userId, $noteId, $fileId) { + /** + * @return bool + */ + public function fileAttachExists(string $userId, int $noteId, $fileId): bool { try { - return $this->findFileAttachFromNote($userId, $noteId, $fileId); + $this->findFileAttachFromNote($userId, $noteId, $fileId); } catch (DoesNotExistException $e) { return false; } - return false; + return true; } /** @@ -75,7 +83,7 @@ class AttachMapper extends QBMapper { * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @return Attach[] */ - public function findFromNote($userId, $noteId) { + public function findFromNote($userId, $noteId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName)