Fix phpstorm inspection issues

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-17 00:41:53 +02:00
committed by Julius Härtl
parent 320f2bf5c8
commit c45bb71084
25 changed files with 77 additions and 93 deletions

View File

@@ -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,

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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;
}
/**

View File

@@ -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;

View File

@@ -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;

View File

@@ -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');
});

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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` = ?';

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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'];
}

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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` ' .

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -26,7 +26,7 @@ namespace OCA\Deck;
class NotFoundException extends StatusException {
public function __construct($message = "") {
public function __construct($message = '') {
parent::__construct($message);
}

View File

@@ -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)) {

View File

@@ -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 */

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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();
}
/**