Completed
Pull Request — master (#3693)
by Joas
12:15
created
apps/comments/lib/Notification/Notifier.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -32,126 +32,126 @@
 block discarded – undo
32 32
 
33 33
 class Notifier implements INotifier {
34 34
 
35
-	/** @var IFactory */
36
-	protected $l10nFactory;
35
+    /** @var IFactory */
36
+    protected $l10nFactory;
37 37
 
38
-	/** @var IRootFolder  */
39
-	protected $rootFolder;
38
+    /** @var IRootFolder  */
39
+    protected $rootFolder;
40 40
 
41
-	/** @var ICommentsManager  */
42
-	protected $commentsManager;
41
+    /** @var ICommentsManager  */
42
+    protected $commentsManager;
43 43
 
44
-	/** @var IURLGenerator */
45
-	protected $url;
44
+    /** @var IURLGenerator */
45
+    protected $url;
46 46
 
47
-	/** @var IUserManager */
48
-	protected $userManager;
47
+    /** @var IUserManager */
48
+    protected $userManager;
49 49
 
50
-	public function __construct(
51
-		IFactory $l10nFactory,
52
-		IRootFolder $rootFolder,
53
-		ICommentsManager $commentsManager,
54
-		IURLGenerator $url,
55
-		IUserManager $userManager
56
-	) {
57
-		$this->l10nFactory = $l10nFactory;
58
-		$this->rootFolder = $rootFolder;
59
-		$this->commentsManager = $commentsManager;
60
-		$this->url = $url;
61
-		$this->userManager = $userManager;
62
-	}
50
+    public function __construct(
51
+        IFactory $l10nFactory,
52
+        IRootFolder $rootFolder,
53
+        ICommentsManager $commentsManager,
54
+        IURLGenerator $url,
55
+        IUserManager $userManager
56
+    ) {
57
+        $this->l10nFactory = $l10nFactory;
58
+        $this->rootFolder = $rootFolder;
59
+        $this->commentsManager = $commentsManager;
60
+        $this->url = $url;
61
+        $this->userManager = $userManager;
62
+    }
63 63
 
64
-	/**
65
-	 * @param INotification $notification
66
-	 * @param string $languageCode The code of the language that should be used to prepare the notification
67
-	 * @return INotification
68
-	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
69
-	 */
70
-	public function prepare(INotification $notification, $languageCode) {
71
-		if($notification->getApp() !== 'comments') {
72
-			throw new \InvalidArgumentException();
73
-		}
74
-		try {
75
-			$comment = $this->commentsManager->get($notification->getObjectId());
76
-		} catch(NotFoundException $e) {
77
-			// needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all
78
-			throw new \InvalidArgumentException('Comment not found', 0, $e);
79
-		}
80
-		$l = $this->l10nFactory->get('comments', $languageCode);
81
-		$displayName = $comment->getActorId();
82
-		$isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER;
83
-		if($comment->getActorType() === 'users') {
84
-			$commenter = $this->userManager->get($comment->getActorId());
85
-			if(!is_null($commenter)) {
86
-				$displayName = $commenter->getDisplayName();
87
-			}
88
-		}
64
+    /**
65
+     * @param INotification $notification
66
+     * @param string $languageCode The code of the language that should be used to prepare the notification
67
+     * @return INotification
68
+     * @throws \InvalidArgumentException When the notification was not prepared by a notifier
69
+     */
70
+    public function prepare(INotification $notification, $languageCode) {
71
+        if($notification->getApp() !== 'comments') {
72
+            throw new \InvalidArgumentException();
73
+        }
74
+        try {
75
+            $comment = $this->commentsManager->get($notification->getObjectId());
76
+        } catch(NotFoundException $e) {
77
+            // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all
78
+            throw new \InvalidArgumentException('Comment not found', 0, $e);
79
+        }
80
+        $l = $this->l10nFactory->get('comments', $languageCode);
81
+        $displayName = $comment->getActorId();
82
+        $isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER;
83
+        if($comment->getActorType() === 'users') {
84
+            $commenter = $this->userManager->get($comment->getActorId());
85
+            if(!is_null($commenter)) {
86
+                $displayName = $commenter->getDisplayName();
87
+            }
88
+        }
89 89
 
90
-		switch($notification->getSubject()) {
91
-			case 'mention':
92
-				$parameters = $notification->getSubjectParameters();
93
-				if($parameters[0] !== 'files') {
94
-					throw new \InvalidArgumentException('Unsupported comment object');
95
-				}
96
-				$userFolder = $this->rootFolder->getUserFolder($notification->getUser());
97
-				$nodes = $userFolder->getById($parameters[1]);
98
-				if(empty($nodes)) {
99
-					throw new \InvalidArgumentException('Cannot resolve file id to Node instance');
100
-				}
101
-				$node = $nodes[0];
90
+        switch($notification->getSubject()) {
91
+            case 'mention':
92
+                $parameters = $notification->getSubjectParameters();
93
+                if($parameters[0] !== 'files') {
94
+                    throw new \InvalidArgumentException('Unsupported comment object');
95
+                }
96
+                $userFolder = $this->rootFolder->getUserFolder($notification->getUser());
97
+                $nodes = $userFolder->getById($parameters[1]);
98
+                if(empty($nodes)) {
99
+                    throw new \InvalidArgumentException('Cannot resolve file id to Node instance');
100
+                }
101
+                $node = $nodes[0];
102 102
 
103
-				if ($isDeletedActor) {
104
-					$notification->setParsedSubject($l->t(
105
-							'A (now) deleted user mentioned you in a comment on “%s”',
106
-							[$node->getName()]
107
-						))
108
-						->setRichSubject(
109
-							$l->t('A (now) deleted user mentioned you in a comment on “{file}”'),
110
-							[
111
-								'file' => [
112
-									'type' => 'file',
113
-									'id' => $comment->getObjectId(),
114
-									'name' => $node->getName(),
115
-									'path' => $node->getPath(),
116
-									'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]),
117
-								],
118
-							]
119
-						);
120
-				} else {
121
-					$notification->setParsedSubject($l->t(
122
-							'%1$s mentioned you in a comment on “%2$s”',
123
-							[$displayName, $node->getName()]
124
-						))
125
-						->setRichSubject(
126
-							$l->t('{user} mentioned you in a comment on “{file}”'),
127
-							[
128
-								'user' => [
129
-									'type' => 'user',
130
-									'id' => $comment->getActorId(),
131
-									'name' => $displayName,
132
-								],
133
-								'file' => [
134
-									'type' => 'file',
135
-									'id' => $comment->getObjectId(),
136
-									'name' => $node->getName(),
137
-									'path' => $node->getPath(),
138
-									'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]),
139
-								],
140
-							]
141
-						);
142
-				}
143
-				$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')))
144
-					->setLink($this->url->linkToRouteAbsolute(
145
-						'comments.Notifications.view',
146
-						['id' => $comment->getId()])
147
-					);
103
+                if ($isDeletedActor) {
104
+                    $notification->setParsedSubject($l->t(
105
+                            'A (now) deleted user mentioned you in a comment on “%s”',
106
+                            [$node->getName()]
107
+                        ))
108
+                        ->setRichSubject(
109
+                            $l->t('A (now) deleted user mentioned you in a comment on “{file}”'),
110
+                            [
111
+                                'file' => [
112
+                                    'type' => 'file',
113
+                                    'id' => $comment->getObjectId(),
114
+                                    'name' => $node->getName(),
115
+                                    'path' => $node->getPath(),
116
+                                    'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]),
117
+                                ],
118
+                            ]
119
+                        );
120
+                } else {
121
+                    $notification->setParsedSubject($l->t(
122
+                            '%1$s mentioned you in a comment on “%2$s”',
123
+                            [$displayName, $node->getName()]
124
+                        ))
125
+                        ->setRichSubject(
126
+                            $l->t('{user} mentioned you in a comment on “{file}”'),
127
+                            [
128
+                                'user' => [
129
+                                    'type' => 'user',
130
+                                    'id' => $comment->getActorId(),
131
+                                    'name' => $displayName,
132
+                                ],
133
+                                'file' => [
134
+                                    'type' => 'file',
135
+                                    'id' => $comment->getObjectId(),
136
+                                    'name' => $node->getName(),
137
+                                    'path' => $node->getPath(),
138
+                                    'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]),
139
+                                ],
140
+                            ]
141
+                        );
142
+                }
143
+                $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')))
144
+                    ->setLink($this->url->linkToRouteAbsolute(
145
+                        'comments.Notifications.view',
146
+                        ['id' => $comment->getId()])
147
+                    );
148 148
 
149
-				return $notification;
150
-				break;
149
+                return $notification;
150
+                break;
151 151
 
152
-			default:
153
-				throw new \InvalidArgumentException('Invalid subject');
154
-		}
152
+            default:
153
+                throw new \InvalidArgumentException('Invalid subject');
154
+        }
155 155
 
156
-	}
156
+    }
157 157
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -68,34 +68,34 @@
 block discarded – undo
68 68
 	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
69 69
 	 */
70 70
 	public function prepare(INotification $notification, $languageCode) {
71
-		if($notification->getApp() !== 'comments') {
71
+		if ($notification->getApp() !== 'comments') {
72 72
 			throw new \InvalidArgumentException();
73 73
 		}
74 74
 		try {
75 75
 			$comment = $this->commentsManager->get($notification->getObjectId());
76
-		} catch(NotFoundException $e) {
76
+		} catch (NotFoundException $e) {
77 77
 			// needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all
78 78
 			throw new \InvalidArgumentException('Comment not found', 0, $e);
79 79
 		}
80 80
 		$l = $this->l10nFactory->get('comments', $languageCode);
81 81
 		$displayName = $comment->getActorId();
82 82
 		$isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER;
83
-		if($comment->getActorType() === 'users') {
83
+		if ($comment->getActorType() === 'users') {
84 84
 			$commenter = $this->userManager->get($comment->getActorId());
85
-			if(!is_null($commenter)) {
85
+			if (!is_null($commenter)) {
86 86
 				$displayName = $commenter->getDisplayName();
87 87
 			}
88 88
 		}
89 89
 
90
-		switch($notification->getSubject()) {
90
+		switch ($notification->getSubject()) {
91 91
 			case 'mention':
92 92
 				$parameters = $notification->getSubjectParameters();
93
-				if($parameters[0] !== 'files') {
93
+				if ($parameters[0] !== 'files') {
94 94
 					throw new \InvalidArgumentException('Unsupported comment object');
95 95
 				}
96 96
 				$userFolder = $this->rootFolder->getUserFolder($notification->getUser());
97 97
 				$nodes = $userFolder->getById($parameters[1]);
98
-				if(empty($nodes)) {
98
+				if (empty($nodes)) {
99 99
 					throw new \InvalidArgumentException('Cannot resolve file id to Node instance');
100 100
 				}
101 101
 				$node = $nodes[0];
Please login to merge, or discard this patch.