summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Comments
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-10 14:19:56 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-10 14:19:56 +0200
commitcaff1023ea72bb2ea94130e18a2a6e2ccf819e5f (patch)
tree186d494c2aea5dea7255d3584ef5d595fc6e6194 /apps/dav/lib/Comments
parentedf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff)
downloadnextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.tar.gz
nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.zip
Format control structures, classes, methods and function
To continue this formatting madness, here's a tiny patch that adds unified formatting for control structures like if and loops as well as classes, their methods and anonymous functions. This basically forces the constructs to start on the same line. This is not exactly what PSR2 wants, but I think we can have a few exceptions with "our" style. The starting of braces on the same line is pracrically standard for our code. This also removes and empty lines from method/function bodies at the beginning and end. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib/Comments')
-rw-r--r--apps/dav/lib/Comments/CommentNode.php18
-rw-r--r--apps/dav/lib/Comments/CommentsPlugin.php24
-rw-r--r--apps/dav/lib/Comments/EntityCollection.php8
-rw-r--r--apps/dav/lib/Comments/EntityTypeCollection.php5
-rw-r--r--apps/dav/lib/Comments/RootCollection.php9
5 files changed, 29 insertions, 35 deletions
diff --git a/apps/dav/lib/Comments/CommentNode.php b/apps/dav/lib/Comments/CommentNode.php
index d24c41409ba..e02eef1cd51 100644
--- a/apps/dav/lib/Comments/CommentNode.php
+++ b/apps/dav/lib/Comments/CommentNode.php
@@ -88,8 +88,8 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
$methods = array_filter($methods, function ($name) {
return strpos($name, 'get') === 0;
});
- foreach($methods as $getter) {
- if($getter === 'getMentions') {
+ foreach ($methods as $getter) {
+ if ($getter === 'getMentions') {
continue; // special treatment
}
$name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3));
@@ -131,7 +131,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
protected function checkWriteAccessOnComment() {
$user = $this->userSession->getUser();
- if($this->comment->getActorType() !== 'users'
+ if ($this->comment->getActorType() !== 'users'
|| is_null($user)
|| $this->comment->getActorId() !== $user->getUID()
) {
@@ -195,7 +195,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
return true;
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'dav/comments']);
- if($e instanceof MessageTooLongException) {
+ if ($e instanceof MessageTooLongException) {
$msg = 'Message exceeds allowed character limit of ';
throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e);
}
@@ -239,14 +239,14 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
$properties = array_keys($this->properties);
$result = [];
- foreach($properties as $property) {
+ foreach ($properties as $property) {
$getter = $this->properties[$property];
- if(method_exists($this->comment, $getter)) {
+ if (method_exists($this->comment, $getter)) {
$result[$property] = $this->comment->$getter();
}
}
- if($this->comment->getActorType() === 'users') {
+ if ($this->comment->getActorType() === 'users') {
$user = $this->userManager->get($this->comment->getActorId());
$displayName = is_null($user) ? null : $user->getDisplayName();
$result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName;
@@ -256,13 +256,13 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
$unread = null;
$user = $this->userSession->getUser();
- if(!is_null($user)) {
+ if (!is_null($user)) {
$readUntil = $this->commentsManager->getReadMark(
$this->comment->getObjectType(),
$this->comment->getObjectId(),
$user
);
- if(is_null($readUntil)) {
+ if (is_null($readUntil)) {
$unread = 'true';
} else {
$unread = $this->comment->getCreationDateTime() > $readUntil;
diff --git a/apps/dav/lib/Comments/CommentsPlugin.php b/apps/dav/lib/Comments/CommentsPlugin.php
index 55b0bdd4b40..ebdf3fde318 100644
--- a/apps/dav/lib/Comments/CommentsPlugin.php
+++ b/apps/dav/lib/Comments/CommentsPlugin.php
@@ -85,7 +85,7 @@ class CommentsPlugin extends ServerPlugin {
*/
function initialize(Server $server) {
$this->server = $server;
- if(strpos($this->server->getRequestUri(), 'comments/') !== 0) {
+ if (strpos($this->server->getRequestUri(), 'comments/') !== 0) {
return;
}
@@ -158,7 +158,7 @@ class CommentsPlugin extends ServerPlugin {
*/
public function onReport($reportName, $report, $uri) {
$node = $this->server->tree->getNodeForPath($uri);
- if(!$node instanceof EntityCollection || $reportName !== self::REPORT_NAME) {
+ if (!$node instanceof EntityCollection || $reportName !== self::REPORT_NAME) {
throw new ReportNotSupported();
}
$args = ['limit' => 0, 'offset' => 0, 'datetime' => null];
@@ -168,31 +168,30 @@ class CommentsPlugin extends ServerPlugin {
$this::REPORT_PARAM_TIMESTAMP
];
$ns = '{' . $this::NS_OWNCLOUD . '}';
- foreach($report as $parameter) {
- if(!in_array($parameter['name'], $acceptableParameters) || empty($parameter['value'])) {
+ foreach ($report as $parameter) {
+ if (!in_array($parameter['name'], $acceptableParameters) || empty($parameter['value'])) {
continue;
}
$args[str_replace($ns, '', $parameter['name'])] = $parameter['value'];
}
- if(!is_null($args['datetime'])) {
+ if (!is_null($args['datetime'])) {
$args['datetime'] = new \DateTime($args['datetime']);
}
$results = $node->findChildren($args['limit'], $args['offset'], $args['datetime']);
$responses = [];
- foreach($results as $node) {
+ foreach ($results as $node) {
$nodePath = $this->server->getRequestUri() . '/' . $node->comment->getId();
$resultSet = $this->server->getPropertiesForPath($nodePath, CommentNode::getPropertyNames());
- if(isset($resultSet[0]) && isset($resultSet[0][200])) {
+ if (isset($resultSet[0]) && isset($resultSet[0][200])) {
$responses[] = new Response(
$this->server->getBaseUri() . $nodePath,
[200 => $resultSet[0][200]],
200
);
}
-
}
$xml = $this->server->xml->write(
@@ -228,13 +227,13 @@ class CommentsPlugin extends ServerPlugin {
$actorType = $data['actorType'];
$actorId = null;
- if($actorType === 'users') {
+ if ($actorType === 'users') {
$user = $this->userSession->getUser();
- if(!is_null($user)) {
+ if (!is_null($user)) {
$actorId = $user->getUID();
}
}
- if(is_null($actorId)) {
+ if (is_null($actorId)) {
throw new BadRequest('Invalid actor "' . $actorType .'"');
}
@@ -251,7 +250,4 @@ class CommentsPlugin extends ServerPlugin {
throw new BadRequest($msg . \OCP\Comments\IComment::MAX_MESSAGE_LENGTH, 0, $e);
}
}
-
-
-
}
diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/dav/lib/Comments/EntityCollection.php
index fadf83df063..94ee3d2a250 100644
--- a/apps/dav/lib/Comments/EntityCollection.php
+++ b/apps/dav/lib/Comments/EntityCollection.php
@@ -65,9 +65,9 @@ class EntityCollection extends RootCollection implements IProperties {
IUserSession $userSession,
ILogger $logger
) {
- foreach(['id', 'name'] as $property) {
+ foreach (['id', 'name'] as $property) {
$$property = trim($$property);
- if(empty($$property) || !is_string($$property)) {
+ if (empty($$property) || !is_string($$property)) {
throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
}
}
@@ -134,7 +134,7 @@ class EntityCollection extends RootCollection implements IProperties {
function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
$comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
$result = [];
- foreach($comments as $comment) {
+ foreach ($comments as $comment) {
$result[] = new CommentNode(
$this->commentsManager,
$comment,
@@ -187,7 +187,7 @@ class EntityCollection extends RootCollection implements IProperties {
function getProperties($properties) {
$marker = null;
$user = $this->userSession->getUser();
- if(!is_null($user)) {
+ if (!is_null($user)) {
$marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
}
return [self::PROPERTY_NAME_READ_MARKER => $marker];
diff --git a/apps/dav/lib/Comments/EntityTypeCollection.php b/apps/dav/lib/Comments/EntityTypeCollection.php
index 4d282b21184..275b41c87e0 100644
--- a/apps/dav/lib/Comments/EntityTypeCollection.php
+++ b/apps/dav/lib/Comments/EntityTypeCollection.php
@@ -69,7 +69,7 @@ class EntityTypeCollection extends RootCollection {
\Closure $childExistsFunction
) {
$name = trim($name);
- if(empty($name) || !is_string($name)) {
+ if (empty($name) || !is_string($name)) {
throw new \InvalidArgumentException('"name" parameter must be non-empty string');
}
$this->name = $name;
@@ -91,7 +91,7 @@ class EntityTypeCollection extends RootCollection {
* @throws NotFound
*/
function getChild($name) {
- if(!$this->childExists($name)) {
+ if (!$this->childExists($name)) {
throw new NotFound('Entity does not exist or is not available');
}
return new EntityCollection(
@@ -123,5 +123,4 @@ class EntityTypeCollection extends RootCollection {
function childExists($name) {
return call_user_func($this->childExistsFunction, $name);
}
-
}
diff --git a/apps/dav/lib/Comments/RootCollection.php b/apps/dav/lib/Comments/RootCollection.php
index 1a4cfbedb9e..b6703a13a11 100644
--- a/apps/dav/lib/Comments/RootCollection.php
+++ b/apps/dav/lib/Comments/RootCollection.php
@@ -70,8 +70,7 @@ class RootCollection implements ICollection {
IUserManager $userManager,
IUserSession $userSession,
EventDispatcherInterface $dispatcher,
- ILogger $logger)
- {
+ ILogger $logger) {
$this->commentsManager = $commentsManager;
$this->logger = $logger;
$this->userManager = $userManager;
@@ -87,11 +86,11 @@ class RootCollection implements ICollection {
* @throws NotAuthenticated
*/
protected function initCollections() {
- if($this->entityTypeCollections !== null) {
+ if ($this->entityTypeCollections !== null) {
return;
}
$user = $this->userSession->getUser();
- if(is_null($user)) {
+ if (is_null($user)) {
throw new NotAuthenticated();
}
@@ -145,7 +144,7 @@ class RootCollection implements ICollection {
*/
function getChild($name) {
$this->initCollections();
- if(isset($this->entityTypeCollections[$name])) {
+ if (isset($this->entityTypeCollections[$name])) {
return $this->entityTypeCollections[$name];
}
throw new NotFound('Entity type "' . $name . '" not found."');