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