diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 31ed68a49..5c0cc9d22 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -29,7 +29,7 @@ use OCA\Deck\Notification\Notifier; use OCP\AppFramework\App; use OCA\Deck\Middleware\SharingMiddleware; use OCP\IGroup; -use OCP\IGroupManager; + use OCP\IUser; use OCP\IUserManager; @@ -39,6 +39,7 @@ class Application extends App { * Application constructor. * * @param array $urlParams + * @throws \OCP\AppFramework\QueryException */ public function __construct(array $urlParams = array()) { parent::__construct('deck', $urlParams); @@ -46,13 +47,13 @@ class Application extends App { $container = $this->getContainer(); $server = $container->getServer(); - $container->registerService('SharingMiddleware', function($container) use ($server) { + $container->registerService('SharingMiddleware', function() use ($server) { return new SharingMiddleware( $server->getLogger(), $server->getConfig() ); }); - $container->registerMiddleware('SharingMiddleware'); + $container->registerMiddleWare('SharingMiddleware'); $container->registerService('databaseType', function($container) { return $container->getServer()->getConfig()->getSystemValue('dbtype', 'sqlite'); @@ -88,7 +89,6 @@ class Application extends App { $container = $this->getContainer(); $container->query('OCP\INavigationManager')->add(function() use ($container) { $urlGenerator = $container->query('OCP\IURLGenerator'); - $l10n = $container->query('OCP\IL10N'); return [ 'id' => 'deck', 'order' => 10, diff --git a/lib/ArchivedItemException.php b/lib/ArchivedItemException.php index 352c9452f..e3e9cef61 100644 --- a/lib/ArchivedItemException.php +++ b/lib/ArchivedItemException.php @@ -28,7 +28,7 @@ class ArchivedItemException extends \Exception { * Constructor * @param string $msg the error message */ - public function __construct($msg = "Operation not allowed. Item is archived.") { + public function __construct($msg = 'Operation not allowed. Item is archived.') { parent::__construct($msg); } } \ No newline at end of file diff --git a/lib/Controller/BoardController.php b/lib/Controller/BoardController.php index f497455d0..a0ed9790a 100644 --- a/lib/Controller/BoardController.php +++ b/lib/Controller/BoardController.php @@ -94,6 +94,7 @@ class BoardController extends Controller { * @param $id * @param $title * @param $color + * @param $archived * @return \OCP\AppFramework\Db\Entity */ public function update($id, $title, $color, $archived) { diff --git a/lib/Controller/CardController.php b/lib/Controller/CardController.php index 4e9b52739..7b44fd85a 100644 --- a/lib/Controller/CardController.php +++ b/lib/Controller/CardController.php @@ -88,6 +88,7 @@ class CardController extends Controller { * @param $type * @param $order * @param $description + * @param $duedate * @return \OCP\AppFramework\Db\Entity */ public function update($id, $title, $stackId, $type, $order, $description, $duedate) { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 738daac31..cf634006f 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -25,20 +25,15 @@ namespace OCA\Deck\Controller; use OCP\IRequest; use OCP\AppFramework\Http\TemplateResponse; - use OCP\AppFramework\Controller; -use OCP\IL10N; class PageController extends Controller { - private $userId; - private $l10n; - public function __construct($AppName, IRequest $request, IL10N $l10n, $userId) { + public function __construct($AppName, IRequest $request, $userId) { parent::__construct($AppName, $request); $this->userId = $userId; - $this->l10n = $l10n; } /** diff --git a/lib/Db/Acl.php b/lib/Db/Acl.php index 33c03138f..e4e282b41 100644 --- a/lib/Db/Acl.php +++ b/lib/Db/Acl.php @@ -23,7 +23,7 @@ namespace OCA\Deck\Db; -class Acl extends RelationalEntity implements \JsonSerializable { +class Acl extends RelationalEntity { const PERMISSION_READ = 0; const PERMISSION_EDIT = 1; @@ -33,7 +33,6 @@ class Acl extends RelationalEntity implements \JsonSerializable { const PERMISSION_TYPE_USER = 0; const PERMISSION_TYPE_GROUP = 1; - public $id; protected $participant; protected $type; protected $boardId; @@ -56,13 +55,13 @@ class Acl extends RelationalEntity implements \JsonSerializable { public function getPermission($permission) { switch ($permission) { - case Acl::PERMISSION_READ: + case self::PERMISSION_READ: return true; - case Acl::PERMISSION_EDIT: + case self::PERMISSION_EDIT: return $this->getPermissionEdit(); - case Acl::PERMISSION_SHARE: + case self::PERMISSION_SHARE: return $this->getPermissionShare(); - case Acl::PERMISSION_MANAGE: + case self::PERMISSION_MANAGE: return $this->getPermissionManage(); } return false; @@ -75,21 +74,22 @@ class Acl extends RelationalEntity implements \JsonSerializable { } public function getTypeString() { - if ($this->type === Acl::PERMISSION_TYPE_GROUP) { + if ($this->type === self::PERMISSION_TYPE_GROUP) { return 'group'; } return 'user'; } public function setType($type) { - if(is_numeric($type)) { - return parent::setType($type); + if (is_numeric($type)) { + parent::setType($type); + return; } // FIXME: Remove when all javascript uses numeric types if ($type === 'group' || $type === '1') { - $typeInt = Acl::PERMISSION_TYPE_GROUP; + $typeInt = self::PERMISSION_TYPE_GROUP; } else { - $typeInt = Acl::PERMISSION_TYPE_USER; + $typeInt = self::PERMISSION_TYPE_USER; } $this->markFieldUpdated('type'); $this->type = $typeInt; diff --git a/lib/Db/Board.php b/lib/Db/Board.php index e5531fea8..3447b82e1 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -23,11 +23,8 @@ namespace OCA\Deck\Db; -use JsonSerializable; +class Board extends RelationalEntity { -class Board extends RelationalEntity implements JsonSerializable { - - public $id; protected $title; protected $owner; protected $color; diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 55127cc58..fad091488 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -58,6 +58,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { * @param bool $withLabels * @param bool $withAcl * @return \OCP\AppFramework\Db\Entity + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws DoesNotExistException */ public function find($id, $withLabels = false, $withAcl = false) { @@ -116,7 +117,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { } $sql = 'SELECT boards.id, title, owner, color, archived, deleted_at, 2 as shared FROM `*PREFIX*deck_boards` as boards ' . 'INNER JOIN `*PREFIX*deck_board_acl` as acl ON boards.id=acl.board_id WHERE owner != ? AND type=? AND ('; - for ($i = 0; $i < count($groups); $i++) { + for ($i = 0, $iMax = count($groups); $i < $iMax; $i++) { $sql .= 'acl.participant = ? '; if (count($groups) > 1 && $i < count($groups) - 1) { $sql .= ' OR '; @@ -134,7 +135,7 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { public function findAll() { $sql = 'SELECT id from *PREFIX*deck_boards;'; - return $this->findEntities($sql, []); + return $this->findEntities($sql); } public function findToDelete() { @@ -184,19 +185,17 @@ class BoardMapper extends DeckMapper implements IPermissionMapper { $user = $userManager->get($participant); if($user !== null) { return new User($user); - } else { - \OC::$server->getLogger()->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); - return null; } + \OC::$server->getLogger()->debug('User ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); + return null; } if($acl->getType() === Acl::PERMISSION_TYPE_GROUP) { $group = $groupManager->get($participant); if($group !== null) { return new Group($group); - } else { - \OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); - return null; } + \OC::$server->getLogger()->debug('Group ' . $acl->getId() . ' not found when mapping acl ' . $acl->getParticipant()); + return null; } throw new \Exception('Unknown permission type for mapping Acl'); }); diff --git a/lib/Db/Card.php b/lib/Db/Card.php index 885339d74..59e4d857a 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -21,15 +21,12 @@ * */ -// db/author.php namespace OCA\Deck\Db; use DateTime; -use JsonSerializable; -class Card extends RelationalEntity implements JsonSerializable { +class Card extends RelationalEntity { - public $id; protected $title; protected $description; protected $stackId; @@ -40,7 +37,7 @@ class Card extends RelationalEntity implements JsonSerializable { protected $owner; protected $order; protected $archived = false; - protected $duedate = null; + protected $duedate; protected $notified = false; private $databaseType = 'sqlite'; @@ -67,8 +64,9 @@ class Card extends RelationalEntity implements JsonSerializable { } public function getDuedate($isoFormat = false) { - if($this->duedate === null) + if($this->duedate === null) { return null; + } $dt = new DateTime($this->duedate); if (!$isoFormat && $this->databaseType === 'mysql') { return $dt->format('Y-m-d H:i:s'); @@ -82,14 +80,14 @@ class Card extends RelationalEntity implements JsonSerializable { $due = strtotime($this->duedate); $today = new DateTime(); - $today->setTime( 0, 0, 0 ); + $today->setTime( 0, 0); $match_date = new DateTime($this->duedate); - $match_date->setTime( 0, 0, 0 ); + $match_date->setTime( 0, 0); $diff = $today->diff( $match_date ); - $diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval + $diffDays = (integer)$diff->format('%R%a'); // Extract days count in interval if($due !== false) { if ($diffDays === 1) { diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index f509b3e89..22e17bc56 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -63,14 +63,16 @@ class CardMapper extends DeckMapper implements IPermissionMapper { public function update(Entity $entity, $updateModified = true) { $entity->setDatabaseType($this->databaseType); - if ($updateModified) + if ($updateModified) { $entity->setLastModified(time()); + } // make sure we only reset the notification flag if the duedate changes - if (in_array('duedate', $entity->getUpdatedFields())) { + if (in_array('duedate', $entity->getUpdatedFields(), true)) { $existing = $this->find($entity->getId()); - if ($existing->getDuedate() !== $entity->getDuedate()) + if ($existing->getDuedate() !== $entity->getDuedate()) { $entity->setNotified(false); + } // remove pending notifications $notification = $this->notificationManager->createNotification(); $notification @@ -87,9 +89,12 @@ class CardMapper extends DeckMapper implements IPermissionMapper { $cardUpdate->setNotified(true); return parent::update($cardUpdate); } + /** * @param $id * @return RelationalEntity if not found + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException + * @throws \OCP\AppFramework\Db\DoesNotExistException */ public function find($id) { $sql = 'SELECT * FROM `*PREFIX*deck_cards` ' . @@ -105,27 +110,23 @@ class CardMapper extends DeckMapper implements IPermissionMapper { public function findAll($stackId, $limit = null, $offset = null) { $sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id` = ? AND NOT archived ORDER BY `order`'; - $entities = $this->findEntities($sql, [$stackId], $limit, $offset); - return $entities; + return $this->findEntities($sql, [$stackId], $limit, $offset); } public function findAllArchived($stackId, $limit = null, $offset = null) { $sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id`=? AND archived ORDER BY `last_modified`'; - $entities = $this->findEntities($sql, [$stackId], $limit, $offset); - return $entities; + return $this->findEntities($sql, [$stackId], $limit, $offset); } public function findAllByStack($stackId, $limit = null, $offset = null) { $sql = 'SELECT id FROM `*PREFIX*deck_cards` WHERE `stack_id` = ?'; - $entities = $this->findEntities($sql, [$stackId], $limit, $offset); - return $entities; + return $this->findEntities($sql, [$stackId], $limit, $offset); } public function findOverdue() { $sql = 'SELECT id,title,duedate,notified from `*PREFIX*deck_cards` WHERE duedate < NOW()'; - $entities = $this->findEntities($sql); - return $entities; + return $this->findEntities($sql); } public function delete(Entity $entity) { diff --git a/lib/Db/DeckMapper.php b/lib/Db/DeckMapper.php index fcda3fa77..98295d37d 100644 --- a/lib/Db/DeckMapper.php +++ b/lib/Db/DeckMapper.php @@ -30,6 +30,8 @@ abstract class DeckMapper extends Mapper { /** * @param $id * @return \OCP\AppFramework\Db\Entity if not found + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException + * @throws \OCP\AppFramework\Db\DoesNotExistException */ public function find($id) { $sql = 'SELECT * FROM `' . $this->tableName . '` ' . 'WHERE `id` = ?'; diff --git a/lib/Db/Label.php b/lib/Db/Label.php index 5ea31d467..650af4162 100644 --- a/lib/Db/Label.php +++ b/lib/Db/Label.php @@ -21,14 +21,10 @@ * */ -// db/author.php namespace OCA\Deck\Db; -use JsonSerializable; +class Label extends RelationalEntity { -class Label extends RelationalEntity implements JsonSerializable { - - public $id; protected $title; protected $color; protected $boardId; diff --git a/lib/Db/LabelMapper.php b/lib/Db/LabelMapper.php index fe465cb40..206507b41 100644 --- a/lib/Db/LabelMapper.php +++ b/lib/Db/LabelMapper.php @@ -49,10 +49,9 @@ class LabelMapper extends DeckMapper implements IPermissionMapper { return $this->findEntities($sql, [$cardId], $limit, $offset); } public function findAssignedLabelsForBoard($boardId, $limit = null, $offset = null) { - $sql = "SELECT c.id as card_id, l.id as id, l.title as title, l.color as color FROM `*PREFIX*deck_cards` as c " . - " INNER JOIN `*PREFIX*deck_assigned_labels` as al ON al.card_id = c.id INNER JOIN `*PREFIX*deck_labels` as l ON al.label_id = l.id WHERE board_id=? ORDER BY l.id"; - $entities = $this->findEntities($sql, [$boardId], $limit, $offset); - return $entities; + $sql = 'SELECT c.id as card_id, l.id as id, l.title as title, l.color as color FROM `*PREFIX*deck_cards` as c ' . + ' INNER JOIN `*PREFIX*deck_assigned_labels` as al ON al.card_id = c.id INNER JOIN `*PREFIX*deck_labels` as l ON al.label_id = l.id WHERE board_id=? ORDER BY l.id'; + return $this->findEntities($sql, [$boardId], $limit, $offset); } public function getAssignedLabelsForBoard($boardId) { diff --git a/lib/Db/RelationalEntity.php b/lib/Db/RelationalEntity.php index 80895c963..1dc619758 100644 --- a/lib/Db/RelationalEntity.php +++ b/lib/Db/RelationalEntity.php @@ -35,7 +35,7 @@ class RelationalEntity extends Entity implements \JsonSerializable { * @param $property string Name of the property */ public function addRelation($property) { - if (!in_array($property, $this->_relations)) { + if (!in_array($property, $this->_relations, true)) { $this->_relations[] = $property; } } @@ -55,20 +55,21 @@ class RelationalEntity extends Entity implements \JsonSerializable { * @since 7.0.0 */ protected function markFieldUpdated($attribute) { - if (!in_array($attribute, $this->_relations)) { + if (!in_array($attribute, $this->_relations, true)) { parent::markFieldUpdated($attribute); } } /** * @return array serialized data + * @throws \ReflectionException */ public function jsonSerialize() { $properties = get_object_vars($this); $reflection = new \ReflectionClass($this); $json = []; foreach ($properties as $property => $value) { - if (substr($property, 0, 1) !== '_' && $reflection->hasProperty($property)) { + if (strpos($property, '_') !== 0 && $reflection->hasProperty($property)) { $propertyReflection = $reflection->getProperty($property); if (!$propertyReflection->isPrivate()) { $json[$property] = $this->getter($property); @@ -119,16 +120,15 @@ class RelationalEntity extends Entity implements \JsonSerializable { public function __call($methodName, $args){ $attr = lcfirst( substr($methodName, 7) ); - if(strpos($methodName, 'resolve') === 0 && array_key_exists($attr, $this->_resolvedProperties)) { + if(array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'resolve') === 0) { if($this->_resolvedProperties[$attr] !== null) { return $this->_resolvedProperties[$attr]; - } else { - return $this->getter($attr); } + return $this->getter($attr); } $attr = lcfirst( substr($methodName, 3) ); - if(strpos($methodName, 'set') === 0 && array_key_exists($attr, $this->_resolvedProperties)) { + if(array_key_exists($attr, $this->_resolvedProperties) && strpos($methodName, 'set') === 0) { if(!is_scalar($args[0])) { $args[0] = $args[0]['primaryKey']; } diff --git a/lib/Db/RelationalObject.php b/lib/Db/RelationalObject.php index d5a6fc18e..7b7291964 100644 --- a/lib/Db/RelationalObject.php +++ b/lib/Db/RelationalObject.php @@ -48,6 +48,8 @@ class RelationalObject implements \JsonSerializable { /** * This method should be overwritten if object doesn't implement \JsonSerializable + * + * @throws \Exception */ public function getObjectSerialization() { if($this->object instanceof \JsonSerializable) { diff --git a/lib/Db/Stack.php b/lib/Db/Stack.php index 9ca46db64..8a3d00ffb 100644 --- a/lib/Db/Stack.php +++ b/lib/Db/Stack.php @@ -23,12 +23,8 @@ namespace OCA\Deck\Db; -use JsonSerializable; +class Stack extends RelationalEntity { - -class Stack extends RelationalEntity implements JsonSerializable { - - public $id; protected $title; protected $boardId; protected $cards = array(); diff --git a/lib/Db/StackMapper.php b/lib/Db/StackMapper.php index b7d3de23f..526438459 100644 --- a/lib/Db/StackMapper.php +++ b/lib/Db/StackMapper.php @@ -40,6 +40,8 @@ class StackMapper extends DeckMapper implements IPermissionMapper { /** * @param $id * @return \OCP\AppFramework\Db\Entity if not found + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException + * @throws \OCP\AppFramework\Db\DoesNotExistException */ public function find($id) { $sql = 'SELECT * FROM `*PREFIX*deck_stacks` ' . diff --git a/lib/Middleware/SharingMiddleware.php b/lib/Middleware/SharingMiddleware.php index c1df3aef9..496ee0a57 100644 --- a/lib/Middleware/SharingMiddleware.php +++ b/lib/Middleware/SharingMiddleware.php @@ -64,8 +64,8 @@ class SharingMiddleware extends Middleware { $this->logger->logException($exception); } return new JSONResponse([ - "status" => $exception->getStatus(), - "message" => $exception->getMessage() + 'status' => $exception->getStatus(), + 'message' => $exception->getMessage() ], $exception->getStatus()); } throw $exception; diff --git a/lib/NoPermissionException.php b/lib/NoPermissionException.php index 982b8127a..8484ad5e5 100644 --- a/lib/NoPermissionException.php +++ b/lib/NoPermissionException.php @@ -29,7 +29,7 @@ class NoPermissionException extends StatusException { public function __construct($message, $controller = null, $method = null) { parent::__construct($message); if ($controller && $method) { - $this->message = get_class($controller) . "#" . $method . ": " . $message; + $this->message = get_class($controller) . '#' . $method . ': ' . $message; } } diff --git a/lib/NotFoundException.php b/lib/NotFoundException.php index c50d3a53b..52a2d6d91 100644 --- a/lib/NotFoundException.php +++ b/lib/NotFoundException.php @@ -26,7 +26,7 @@ namespace OCA\Deck; class NotFoundException extends StatusException { - public function __construct($message = "") { + public function __construct($message = '') { parent::__construct($message); } diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index 5903308a6..ea9aff0be 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -99,6 +99,7 @@ class NotificationHelper { * * @param $boardId * @param $acl + * @throws \InvalidArgumentException */ public function sendBoardShared($boardId, $acl) { $board = $this->getBoard($boardId); @@ -118,6 +119,7 @@ class NotificationHelper { /** * @param $boardId * @return Board + * @throws \OCP\AppFramework\Db\DoesNotExistException */ private function getBoard($boardId) { if (!array_key_exists($boardId, $this->boards)) { diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index e85d5a6d5..6976f2c05 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -30,7 +30,6 @@ use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\INotification; use OCP\Notification\INotifier; -use OCP\RichObjectStrings\Definitions; class Notifier implements INotifier { /** @var IFactory */ diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 83786fba1..7b515588d 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -108,10 +108,9 @@ class BoardService { public function isArchived($mapper, $id) { try { + $boardId = $id; if ($mapper instanceof IPermissionMapper) { $boardId = $mapper->findBoardId($id); - } else { - $boardId = $id; } if ($boardId === null) { return false; @@ -125,10 +124,9 @@ class BoardService { public function isDeleted($mapper, $id) { try { + $boardId = $id; if ($mapper instanceof IPermissionMapper) { $boardId = $mapper->findBoardId($id); - } else { - $boardId = $id; } if ($boardId === null) { return false; @@ -189,7 +187,7 @@ class BoardService { $this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ); $board = $this->find($id); $board->setDeletedAt(0); - $this->boardMapper->update($board); + return $this->boardMapper->update($board); } public function deleteForce($id) { diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 5cfaa4097..9ffdbf0ed 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -46,8 +46,7 @@ class CardService { public function find($cardId) { $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ); - $card = $this->cardMapper->find($cardId); - return $card; + return $this->cardMapper->find($cardId); } public function create($title, $stackId, $type, $order, $owner) { diff --git a/lib/Service/PermissionService.php b/lib/Service/PermissionService.php index 99f918506..5d301456c 100644 --- a/lib/Service/PermissionService.php +++ b/lib/Service/PermissionService.php @@ -115,10 +115,9 @@ class PermissionService { */ public function checkPermission($mapper, $id, $permission) { try { + $boardId = $id; if ($mapper instanceof IPermissionMapper) { $boardId = $mapper->findBoardId($id); - } else { - $boardId = $id; } if ($boardId === null) { // Throw NoPermission to not leak information about existing entries @@ -146,13 +145,11 @@ class PermissionService { /** * @param $boardId * @return bool + * @throws \OCP\AppFramework\Db\DoesNotExistException */ public function userIsBoardOwner($boardId) { $board = $this->boardMapper->find($boardId); - if ($board && $this->userId === $board->getOwner()) { - return true; - } - return false; + return $board && $this->userId === $board->getOwner(); } /**