Type hint IPermissionMapper

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-11-04 19:52:16 +01:00
parent 9b366857ab
commit f031717a54
8 changed files with 17 additions and 17 deletions

View File

@@ -35,19 +35,19 @@ class AclMapper extends DeckMapper implements IPermissionMapper {
return $this->findEntities($sql, [$boardId], $limit, $offset);
}
public function isOwner($userId, $aclId) {
public function isOwner($userId, $aclId): bool {
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_board_acl` WHERE id = ?)';
$stmt = $this->execute($sql, [$aclId]);
$row = $stmt->fetch();
return ($row['owner'] === $userId);
}
public function findBoardId($aclId) {
public function findBoardId($aclId): ?int {
$entity = $this->find($aclId);
return $entity->getBoardId();
}
public function findByParticipant($type, $participant) {
public function findByParticipant($type, $participant): array {
$sql = 'SELECT * from *PREFIX*deck_board_acl WHERE type = ? AND participant = ?';
return $this->findEntities($sql, [$type, $participant]);
}

View File

@@ -79,11 +79,11 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
}
public function isOwner($userId, $cardId) {
public function isOwner($userId, $cardId): bool {
return $this->cardMapper->isOwner($userId, $cardId);
}
public function findBoardId($cardId) {
public function findBoardId($cardId): ?int {
return $this->cardMapper->findBoardId($cardId);
}

View File

@@ -156,7 +156,7 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
* @param $id int|string unique entity identifier
* @return boolean
*/
public function isOwner($userId, $id) {
public function isOwner($userId, $id): bool {
try {
$attachment = $this->find($id);
return $this->cardMapper->isOwner($userId, $attachment->getCardId());
@@ -172,7 +172,7 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper {
* @param $id int|string unique entity identifier
* @return int|null id of Board
*/
public function findBoardId($id) {
public function findBoardId($id): ?int {
try {
$attachment = $this->find($id);
} catch (\Exception $e) {

View File

@@ -220,12 +220,12 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
return parent::delete($entity);
}
public function isOwner($userId, $boardId) {
public function isOwner($userId, $boardId): bool {
$board = $this->find($boardId);
return ($board->getOwner() === $userId);
}
public function findBoardId($id) {
public function findBoardId($id): ?int {
return $id;
}

View File

@@ -308,7 +308,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
$qb->execute();
}
public function isOwner($userId, $cardId) {
public function isOwner($userId, $cardId): bool {
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $cardId, \PDO::PARAM_INT);
@@ -317,7 +317,7 @@ class CardMapper extends QBMapper implements IPermissionMapper {
return ($row['owner'] === $userId);
}
public function findBoardId($cardId) {
public function findBoardId($cardId): ?int {
$sql = 'SELECT id FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id IN (SELECT stack_id FROM `*PREFIX*deck_cards` WHERE id = ?))';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $cardId, \PDO::PARAM_INT);

View File

@@ -33,7 +33,7 @@ interface IPermissionMapper {
* @param $id int|string unique entity identifier
* @return boolean
*/
public function isOwner($userId, $id);
public function isOwner($userId, $id): bool;
/**
* Query boardId for Entity of given $id
@@ -41,5 +41,5 @@ interface IPermissionMapper {
* @param $id int|string unique entity identifier
* @return int|null id of Board
*/
public function findBoardId($id);
public function findBoardId($id): ?int;
}

View File

@@ -92,14 +92,14 @@ class LabelMapper extends DeckMapper implements IPermissionMapper {
$stmt->execute();
}
public function isOwner($userId, $labelId) {
public function isOwner($userId, $labelId): bool {
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_labels` WHERE id = ?)';
$stmt = $this->execute($sql, [$labelId]);
$row = $stmt->fetch();
return ($row['owner'] === $userId);
}
public function findBoardId($labelId) {
public function findBoardId($labelId): ?int {
$entity = $this->find($labelId);
return $entity->getBoardId();
}

View File

@@ -67,14 +67,14 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
return parent::delete($entity);
}
public function isOwner($userId, $stackId) {
public function isOwner($userId, $stackId): bool {
$sql = 'SELECT owner FROM `*PREFIX*deck_boards` WHERE `id` IN (SELECT board_id FROM `*PREFIX*deck_stacks` WHERE id = ?)';
$stmt = $this->execute($sql, [$stackId]);
$row = $stmt->fetch();
return ($row['owner'] === $userId);
}
public function findBoardId($stackId) {
public function findBoardId($stackId): ?int {
$entity = $this->find($stackId);
return $entity->getBoardId();
}