diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-04-10 14:19:56 +0200 |
commit | caff1023ea72bb2ea94130e18a2a6e2ccf819e5f (patch) | |
tree | 186d494c2aea5dea7255d3584ef5d595fc6e6194 /apps/comments/lib | |
parent | edf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff) | |
download | nextcloud-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/comments/lib')
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Collaboration/CommentersSorter.php | 12 | ||||
-rw-r--r-- | apps/comments/lib/Controller/Notifications.php | 2 | ||||
-rw-r--r-- | apps/comments/lib/EventHandler.php | 6 | ||||
-rw-r--r-- | apps/comments/lib/Listener/LoadAdditionalScripts.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Listener/LoadSidebarScripts.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Listener.php | 18 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 8 | ||||
-rw-r--r-- | apps/comments/lib/Search/Result.php | 2 |
9 files changed, 22 insertions, 29 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index a4c01f3f620..9168948d7c8 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -42,7 +42,6 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; class Application extends App { - const APP_ID = 'comments'; public function __construct(array $urlParams = []) { diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php index 0db043f918b..80f263acb0c 100644 --- a/apps/comments/lib/Collaboration/CommentersSorter.php +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -48,12 +48,12 @@ class CommentersSorter implements ISorter { */ public function sort(array &$sortArray, array $context) { $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); - if(count($commenters) === 0) { + if (count($commenters) === 0) { return; } foreach ($sortArray as $type => &$byType) { - if(!isset($commenters[$type])) { + if (!isset($commenters[$type])) { continue; } @@ -66,7 +66,7 @@ class CommentersSorter implements ISorter { usort($workArray, function ($a, $b) use ($commenters, $type) { $r = $this->compare($a[1], $b[1], $commenters[$type]); - if($r === 0) { + if ($r === 0) { $r = $a[0] - $b[0]; } return $r; @@ -84,16 +84,16 @@ class CommentersSorter implements ISorter { */ protected function retrieveCommentsInformation($type, $id) { $comments = $this->commentsManager->getForObject($type, $id); - if(count($comments) === 0) { + if (count($comments) === 0) { return []; } $actors = []; foreach ($comments as $comment) { - if(!isset($actors[$comment->getActorType()])) { + if (!isset($actors[$comment->getActorType()])) { $actors[$comment->getActorType()] = []; } - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { $actors[$comment->getActorType()][$comment->getActorId()] = 1; } else { $actors[$comment->getActorType()][$comment->getActorId()]++; diff --git a/apps/comments/lib/Controller/Notifications.php b/apps/comments/lib/Controller/Notifications.php index 6610b56b689..030a221a03c 100644 --- a/apps/comments/lib/Controller/Notifications.php +++ b/apps/comments/lib/Controller/Notifications.php @@ -108,7 +108,7 @@ class Notifications extends Controller { try { $comment = $this->commentsManager->get($id); - if($comment->getObjectType() !== 'files') { + if ($comment->getObjectType() !== 'files') { return new NotFoundResponse(); } $userFolder = $this->rootFolder->getUserFolder($currentUser->getUID()); diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/EventHandler.php index 4364550a222..3d78ad43129 100644 --- a/apps/comments/lib/EventHandler.php +++ b/apps/comments/lib/EventHandler.php @@ -49,13 +49,13 @@ class EventHandler implements ICommentsEventHandler { * @param CommentsEvent $event */ public function handle(CommentsEvent $event) { - if($event->getComment()->getObjectType() !== 'files') { + if ($event->getComment()->getObjectType() !== 'files') { // this is a 'files'-specific Handler return; } $eventType = $event->getEvent(); - if($eventType === CommentsEvent::EVENT_ADD + if ($eventType === CommentsEvent::EVENT_ADD ) { $this->notificationHandler($event); $this->activityHandler($event); @@ -67,7 +67,7 @@ class EventHandler implements ICommentsEventHandler { CommentsEvent::EVENT_UPDATE, CommentsEvent::EVENT_DELETE, ]; - if(in_array($eventType, $applicableEvents)) { + if (in_array($eventType, $applicableEvents)) { $this->notificationHandler($event); return; } diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php index ddaf288394b..2ab67a45ab5 100644 --- a/apps/comments/lib/Listener/LoadAdditionalScripts.php +++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php @@ -43,5 +43,4 @@ class LoadAdditionalScripts implements IEventListener { // we properly split it between files list and sidebar Util::addScript(Application::APP_ID, 'comments'); } - } diff --git a/apps/comments/lib/Listener/LoadSidebarScripts.php b/apps/comments/lib/Listener/LoadSidebarScripts.php index 209c62dc406..29d1f2eb394 100644 --- a/apps/comments/lib/Listener/LoadSidebarScripts.php +++ b/apps/comments/lib/Listener/LoadSidebarScripts.php @@ -42,5 +42,4 @@ class LoadSidebarScripts implements IEventListener { // we properly split it between files list and sidebar Util::addScript(Application::APP_ID, 'comments'); } - } diff --git a/apps/comments/lib/Notification/Listener.php b/apps/comments/lib/Notification/Listener.php index ba645ac5779..f157dd4cd31 100644 --- a/apps/comments/lib/Notification/Listener.php +++ b/apps/comments/lib/Notification/Listener.php @@ -45,7 +45,6 @@ class Listener { IManager $notificationManager, IUserManager $userManager ) { - $this->notificationManager = $notificationManager; $this->userManager = $userManager; } @@ -57,15 +56,15 @@ class Listener { $comment = $event->getComment(); $mentions = $this->extractMentions($comment->getMentions()); - if(empty($mentions)) { + if (empty($mentions)) { // no one to notify return; } $notification = $this->instantiateNotification($comment); - foreach($mentions as $uid) { - if(($comment->getActorType() === 'users' && $uid === $comment->getActorId()) + foreach ($mentions as $uid) { + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) || !$this->userManager->userExists($uid) ) { // do not notify unknown users or yourself @@ -73,9 +72,8 @@ class Listener { } $notification->setUser($uid); - if($event->getEvent() === CommentsEvent::EVENT_DELETE - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) - { + if ($event->getEvent() === CommentsEvent::EVENT_DELETE + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { $this->notificationManager->markProcessed($notification); } else { $this->notificationManager->notify($notification); @@ -107,12 +105,12 @@ class Listener { * @return string[] containing the mentions, e.g. ['alice', 'bob'] */ public function extractMentions(array $mentions) { - if(empty($mentions)) { + if (empty($mentions)) { return []; } $uids = []; - foreach($mentions as $mention) { - if($mention['type'] === 'user') { + foreach ($mentions as $mention) { + if ($mention['type'] === 'user') { $uids[] = $mention['id']; } } diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php index 3b502c0c504..01a003eb8dc 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -96,12 +96,12 @@ class Notifier implements INotifier { * @since 9.0.0 */ public function prepare(INotification $notification, string $languageCode): INotification { - if($notification->getApp() !== 'comments') { + if ($notification->getApp() !== 'comments') { throw new \InvalidArgumentException(); } try { $comment = $this->commentsManager->get($notification->getObjectId()); - } catch(NotFoundException $e) { + } catch (NotFoundException $e) { // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all throw new \InvalidArgumentException('Comment not found', 0, $e); } @@ -118,12 +118,12 @@ class Notifier implements INotifier { switch ($notification->getSubject()) { case 'mention': $parameters = $notification->getSubjectParameters(); - if($parameters[0] !== 'files') { + if ($parameters[0] !== 'files') { throw new \InvalidArgumentException('Unsupported comment object'); } $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); $nodes = $userFolder->getById((int)$parameters[1]); - if(empty($nodes)) { + if (empty($nodes)) { throw new AlreadyProcessedException(); } $node = $nodes[0]; diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php index 36b0303fc4e..9f0e6936320 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -29,7 +29,6 @@ use OCP\Files\NotFoundException; use OCP\Search\Result as BaseResult; class Result extends BaseResult { - public $type = 'comment'; public $comment; public $authorId; @@ -108,5 +107,4 @@ class Result extends BaseResult { return $prefix . mb_substr($message, $start, $end - $start) . $suffix; } - } |