From 9bbe4b91379b9bb342bb1e5ceb9c7c816dc7b260 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Fri, 28 Oct 2016 00:45:03 +0200 Subject: [PATCH] PHPdoc and small fixes --- lib/{Service => }/CardArchivedException.php | 2 +- lib/Controller/BoardController.php | 95 ++++++++++------ lib/Controller/CardController.php | 120 +++++++++++++------- lib/Controller/LabelController.php | 36 ++++-- lib/Controller/ShareController.php | 9 +- lib/Controller/StackController.php | 71 ++++++++---- lib/Db/Board.php | 2 +- lib/Db/BoardMapper.php | 25 ++-- lib/Db/CardMapper.php | 9 +- lib/Db/DeckMapper.php | 4 +- lib/Db/IPermissionMapper.php | 2 - lib/Db/LabelMapper.php | 2 +- lib/Db/StackMapper.php | 8 +- lib/Middleware/SharingMiddleware.php | 1 + lib/NotFoundException.php | 2 +- lib/Service/BoardService.php | 1 - lib/Service/LabelService.php | 2 - lib/Service/ServicePermissionException.php | 34 ------ lib/Service/StackService.php | 25 ++-- 19 files changed, 261 insertions(+), 189 deletions(-) rename lib/{Service => }/CardArchivedException.php (96%) delete mode 100644 lib/Service/ServicePermissionException.php diff --git a/lib/Service/CardArchivedException.php b/lib/CardArchivedException.php similarity index 96% rename from lib/Service/CardArchivedException.php rename to lib/CardArchivedException.php index 0a5ce8ffe..06d3b92d8 100644 --- a/lib/Service/CardArchivedException.php +++ b/lib/CardArchivedException.php @@ -28,7 +28,7 @@ class CardArchivedException extends \Exception { * Constructor * @param string $msg the error message */ - public function __construct($msg){ + public function __construct($msg=""){ parent::__construct($msg); } } \ No newline at end of file diff --git a/lib/Controller/BoardController.php b/lib/Controller/BoardController.php index f0390bc82..67d13c92f 100644 --- a/lib/Controller/BoardController.php +++ b/lib/Controller/BoardController.php @@ -49,10 +49,10 @@ class BoardController extends Controller { $this->userManager = $userManager; $this->groupManager = $groupManager; $this->boardService = $cardService; - $this->userInfo = $this->getBoardPrequisites(); + $this->userInfo = $this->getBoardPrerequisites(); } - private function getBoardPrequisites() { + private function getBoardPrerequisites() { $groups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId)); return [ 'user' => $this->userId, @@ -68,66 +68,93 @@ class BoardController extends Controller { return $this->boardService->findAll($this->userInfo); } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $boardId + * @return \OCP\AppFramework\Db\Entity + */ public function read($boardId) { return $this->boardService->find($this->userId, $boardId); } - /** - * @NoAdminRequired + /** + * @NoAdminRequired * @RequireNoPermission - */ + * @param $title + * @param $color + * @return \OCP\AppFramework\Db\Entity + */ public function create($title, $color) { return $this->boardService->create($title, $this->userId, $color); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $id + * @param $title + * @param $color + * @return \OCP\AppFramework\Db\Entity + */ public function update($id, $title, $color) { return $this->boardService->update($id, $title, $this->userId, $color); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $boardId + * @return \OCP\AppFramework\Db\Entity + */ public function delete($boardId) { return $this->boardService->delete($this->userId, $boardId); } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $boardId + * @return + */ public function labels($boardId) { return $this->boardService->labels($boardId); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $boardId + * @param $type + * @param $participant + * @param $write + * @param $invite + * @param $manage + * @return \OCP\AppFramework\Db\Entity + */ public function addAcl($boardId, $type, $participant, $write, $invite, $manage) { return $this->boardService->addAcl($boardId, $type, $participant, $write, $invite, $manage); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $id + * @param $permissionWrite + * @param $permissionInvite + * @param $permissionManage + * @return \OCP\AppFramework\Db\Entity + */ public function updateAcl($id, $permissionWrite, $permissionInvite, $permissionManage) { return $this->boardService->updateAcl($id, $permissionWrite, $permissionInvite, $permissionManage); } - - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $aclId + * @return \OCP\AppFramework\Db\Entity + */ public function deleteAcl($aclId) { return $this->boardService->deleteAcl($aclId); } diff --git a/lib/Controller/CardController.php b/lib/Controller/CardController.php index 73d63d6ae..2c979b3f9 100644 --- a/lib/Controller/CardController.php +++ b/lib/Controller/CardController.php @@ -39,74 +39,114 @@ class CardController extends Controller { $this->userId = $userId; $this->cardService = $cardService; } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $cardId + * @return \OCP\AppFramework\Db\Entity + */ public function read($cardId) { return $this->cardService->find($this->userId, $cardId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @param $stackId + * @param $order + * @return array + */ public function reorder($cardId, $stackId, $order) { return $this->cardService->reorder($cardId, $stackId, $order); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @param $title + * @return \OCP\AppFramework\Db\Entity + */ public function rename($cardId, $title) { return $this->cardService->rename($cardId, $title); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $title + * @param $stackId + * @param $type + * @param int $order + * @return \OCP\AppFramework\Db\Entity + */ public function create($title, $stackId, $type, $order=999) { return $this->cardService->create($title, $stackId, $type, $order, $this->userId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $id + * @param $title + * @param $stackId + * @param $type + * @param $order + * @param $description + * @return \OCP\AppFramework\Db\Entity + */ public function update($id, $title, $stackId, $type, $order, $description) { return $this->cardService->update($id, $title, $stackId, $type, $order, $description, $this->userId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @return \OCP\AppFramework\Db\Entity + */ public function delete($cardId) { return $this->cardService->delete($this->userId, $cardId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @return \OCP\AppFramework\Db\Entity + */ public function archive($cardId) { return $this->cardService->archive($cardId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @return \OCP\AppFramework\Db\Entity + */ public function unarchive($cardId) { return $this->cardService->unarchive($cardId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @param $labelId + */ public function assignLabel($cardId, $labelId) { return $this->cardService->assignLabel($this->userId, $cardId, $labelId); } - /** - * @NoAdminRequired - * @RequireEditPermission - */ + + /** + * @NoAdminRequired + * @RequireEditPermission + * @param $cardId + * @param $labelId + */ public function removeLabel($cardId, $labelId) { return $this->cardService->removeLabel($this->userId, $cardId, $labelId); } diff --git a/lib/Controller/LabelController.php b/lib/Controller/LabelController.php index 1c0c76efe..bf9367921 100644 --- a/lib/Controller/LabelController.php +++ b/lib/Controller/LabelController.php @@ -42,24 +42,36 @@ class LabelController extends Controller { $this->labelService = $labelService; } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $title + * @param $color + * @param $boardId + * @return \OCP\AppFramework\Db\Entity + */ public function create($title, $color, $boardId) { return $this->labelService->create($title, $this->userId, $color, $boardId); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $id + * @param $title + * @param $color + * @return \OCP\AppFramework\Db\Entity + */ public function update($id, $title, $color) { return $this->labelService->update($id, $title, $this->userId, $color); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $labelId + * @return \OCP\AppFramework\Db\Entity + */ public function delete($labelId) { return $this->labelService->delete($this->userId, $labelId); } diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index baba2cf81..ee6981fd1 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -47,10 +47,13 @@ class ShareController extends Controller { $this->userId = $userId; } - /** - * @NoAdminRequired + + /** + * @NoAdminRequired * @RequireNoPermission - */ + * @param $search + * @return array + */ public function searchUser($search) { $limit = 3; $offset = null; diff --git a/lib/Controller/StackController.php b/lib/Controller/StackController.php index 1e5237ac8..486dd4d49 100644 --- a/lib/Controller/StackController.php +++ b/lib/Controller/StackController.php @@ -41,45 +41,68 @@ class StackController extends Controller { $this->userId = $userId; $this->stackService = $cardService; } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $boardId + * @return array + */ public function index($boardId) { return $this->stackService->findAll($boardId); } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $boardId + * @return array + */ public function archived($boardId) { return $this->stackService->findAllArchived($boardId); } - /** - * @NoAdminRequired - * @RequireReadPermission - */ + + /** + * @NoAdminRequired + * @RequireReadPermission + * @param $boardId + * @return + */ public function read($boardId) { return $this->stackService->find($this->userId, $boardId); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $title + * @param $boardId + * @param int $order + * @return \OCP\AppFramework\Db\Entity + */ public function create($title, $boardId, $order=999) { return $this->stackService->create($title, $boardId, $order); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $id + * @param $title + * @param $boardId + * @param $order + * @return \OCP\AppFramework\Db\Entity + */ public function update($id, $title, $boardId, $order) { return $this->stackService->update($id, $title, $boardId, $order); } - /** - * @NoAdminRequired - * @RequireManagePermission - */ + + /** + * @NoAdminRequired + * @RequireManagePermission + * @param $stackId + * @return \OCP\AppFramework\Db\Entity + */ public function delete($stackId) { return $this->stackService->delete($this->userId, $stackId); } diff --git a/lib/Db/Board.php b/lib/Db/Board.php index ec7130ffe..29ac40312 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -25,7 +25,7 @@ namespace OCA\Deck\Db; use JsonSerializable; -class Board extends \OCA\Deck\Db\Entity implements JsonSerializable { +class Board extends Entity implements JsonSerializable { public $id; protected $title; diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index e0cb71e06..87b7bbd68 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -40,10 +40,10 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { } - /** - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result - */ + /** + * @param $id + * @return \OCP\AppFramework\Db\Entity if not found + */ public function find($id) { $sql = 'SELECT id, title, owner, color, archived FROM `*PREFIX*deck_boards` ' . 'WHERE `id` = ?'; @@ -79,13 +79,16 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { } return $entries; } - /** - * Find all boards for a given user - * @param $groups - * @param null $limit - * @param null $offset - * @return array - */ + + /** + * Find all boards for a given user + * + * @param $userId + * @param $groups + * @param null $limit + * @param null $offset + * @return array + */ public function findAllByGroups($userId, $groups, $limit=null, $offset=null) { if(count($groups)<=0) { return []; diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index b5df682f3..cff37c459 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -54,10 +54,10 @@ class CardMapper extends Mapper implements IPermissionMapper { } - /** - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result - */ + /** + * @param $id + * @return Entity if not found + */ public function find($id) { $sql = 'SELECT * FROM `*PREFIX*deck_cards` ' . 'WHERE `id` = ?'; @@ -68,7 +68,6 @@ class CardMapper extends Mapper implements IPermissionMapper { } public function findAll($stackId, $limit=null, $offset=null) { - // TODO: Exclude fields like text $sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id` = ? AND NOT archived ORDER BY `order`'; $entities = $this->findEntities($sql, [$stackId], $limit, $offset); diff --git a/lib/Db/DeckMapper.php b/lib/Db/DeckMapper.php index a5ce17104..919d46a89 100644 --- a/lib/Db/DeckMapper.php +++ b/lib/Db/DeckMapper.php @@ -28,8 +28,8 @@ use OCP\AppFramework\Db\Mapper; abstract class DeckMapper extends Mapper { /** - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result + * @param $id + * @return \OCP\AppFramework\Db\Entity if not found */ public function find($id) { $sql = 'SELECT * FROM `' . $this->tableName . '` ' . 'WHERE `id` = ?'; diff --git a/lib/Db/IPermissionMapper.php b/lib/Db/IPermissionMapper.php index ba8d7f204..c41509176 100644 --- a/lib/Db/IPermissionMapper.php +++ b/lib/Db/IPermissionMapper.php @@ -27,8 +27,6 @@ namespace OCA\Deck\Db; interface IPermissionMapper { - // FIXME: Optimize implementations as e.g. BoardMapper::isOwner doesn't need to select all fields - /** * Check if $userId is owner of Entity with $id * diff --git a/lib/Db/LabelMapper.php b/lib/Db/LabelMapper.php index 34036474a..d489e2c9b 100644 --- a/lib/Db/LabelMapper.php +++ b/lib/Db/LabelMapper.php @@ -60,7 +60,7 @@ class LabelMapper extends DeckMapper implements IPermissionMapper { $labels = $this->findAssignedLabelsForBoard($boardId); $result = array(); foreach ($labels as $label) { - if(!is_array($result[$label->getCardId()])) { + if(!array_key_exists($label->getCardId(), $result)) { $result[$label->getCardId()] = array(); } $result[$label->getCardId()][] = $label; diff --git a/lib/Db/StackMapper.php b/lib/Db/StackMapper.php index e8ba0e86e..adc5a9665 100644 --- a/lib/Db/StackMapper.php +++ b/lib/Db/StackMapper.php @@ -38,10 +38,10 @@ class StackMapper extends Mapper implements IPermissionMapper { } - /** - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result - */ + /** + * @param $id + * @return Entity if not found + */ public function find($id) { $sql = 'SELECT * FROM `*PREFIX*deck_stacks` ' . 'WHERE `id` = ?'; diff --git a/lib/Middleware/SharingMiddleware.php b/lib/Middleware/SharingMiddleware.php index 5d057b8c1..8ef5e931a 100644 --- a/lib/Middleware/SharingMiddleware.php +++ b/lib/Middleware/SharingMiddleware.php @@ -191,6 +191,7 @@ class SharingMiddleware extends Middleware { * @param $mapper * @param $id * @return bool + * @throws NotFoundException */ public function checkMapperPermission($permission, $userId, $mapper, $id) { // check if current user is owner diff --git a/lib/NotFoundException.php b/lib/NotFoundException.php index 90f2d9558..11a6b12ae 100644 --- a/lib/NotFoundException.php +++ b/lib/NotFoundException.php @@ -26,7 +26,7 @@ namespace OCA\Deck; class NotFoundException extends \Exception { - public function __construct($message) { + public function __construct($message="") { parent::__construct($message); } } \ No newline at end of file diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 8bbaa14e1..d3ce08081 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -29,7 +29,6 @@ use OCA\Deck\Db\Label; use OCP\ILogger; use OCP\IL10N; -use OCP\AppFramework\Utility\ITimeFactory; use \OCA\Deck\Db\Board; use \OCA\Deck\Db\BoardMapper; diff --git a/lib/Service/LabelService.php b/lib/Service/LabelService.php index fb1ac145e..57507daeb 100644 --- a/lib/Service/LabelService.php +++ b/lib/Service/LabelService.php @@ -27,8 +27,6 @@ use OCA\Deck\Db\Label; use OCP\ILogger; use OCP\IL10N; -use OCP\AppFramework\Utility\ITimeFactory; - use \OCA\Deck\Db\LabelMapper; diff --git a/lib/Service/ServicePermissionException.php b/lib/Service/ServicePermissionException.php deleted file mode 100644 index eb28a6ec8..000000000 --- a/lib/Service/ServicePermissionException.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * @author Julius Härtl - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -namespace OCA\Deck\Service; - -class ServicePermissionException extends \Exception { - /** - * Constructor - * @param string $msg the error message - */ - public function __construct($msg){ - parent::__construct($msg); - } -} \ No newline at end of file diff --git a/lib/Service/StackService.php b/lib/Service/StackService.php index ab8a0cfc9..63774646d 100644 --- a/lib/Service/StackService.php +++ b/lib/Service/StackService.php @@ -54,13 +54,14 @@ class StackService { public function findAll($boardId) { $stacks = $this->stackMapper->findAll($boardId); $labels = $this->labelMapper->getAssignedLabelsForBoard($boardId); - - foreach ($stacks as $idx => $s) { - $cards = $this->cardMapper->findAll($s->id); - foreach ($cards as $idxc => $card) { - $cards[$idxc]->setLabels($labels[$card->id]); + foreach ($stacks as $stackIndex => $stack) { + $cards = $this->cardMapper->findAll($stack->id); + foreach ($cards as $cardIndex => $card) { + if(array_key_exists($card->id, $labels)) { + $cards[$cardIndex]->setLabels($labels[$card->id]); + } } - $stacks[$idx]->setCards($cards); + $stacks[$stackIndex]->setCards($cards); } return $stacks; } @@ -68,12 +69,14 @@ class StackService { public function findAllArchived($boardId) { $stacks = $this->stackMapper->findAll($boardId); $labels = $this->labelMapper->getAssignedLabelsForBoard($boardId); - foreach ($stacks as $idx => $s) { - $cards = $this->cardMapper->findAllArchived($s->id); - foreach ($cards as $idxc => $card) { - $cards[$idxc]->setLabels($labels[$card->id]); + foreach ($stacks as $stackIndex => $stack) { + $cards = $this->cardMapper->findAllArchived($stack->id); + foreach ($cards as $cardIndex => $card) { + if(array_key_exists($card->id, $labels)) { + $cards[$cardIndex]->setLabels($labels[$card->id]); + } } - $stacks[$idx]->setCards($cards); + $stacks[$stackIndex]->setCards($cards); } return $stacks; }