Skip to content

Commit 096f893

Browse files
committed
fix(activity): Update more activity providers to use new exceptions
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 0dc2363 commit 096f893

9 files changed

Lines changed: 41 additions & 46 deletions

File tree

apps/comments/lib/Activity/Provider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
5454
if ($this->activityManager->isFormattingFilteredObject()) {
5555
try {
5656
return $this->parseShortVersion($event);
57-
} catch (\InvalidArgumentException $e) {
57+
} catch (UnknownActivityException) {
5858
// Ignore and simply use the long version...
5959
}
6060
}
@@ -66,7 +66,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
6666
}
6767

6868
/**
69-
* @throws \InvalidArgumentException
69+
* @throws UnknownActivityException
7070
*/
7171
protected function parseShortVersion(IEvent $event): IEvent {
7272
$subjectParameters = $this->getSubjectParameters($event);
@@ -81,14 +81,14 @@ protected function parseShortVersion(IEvent $event): IEvent {
8181
]);
8282
}
8383
} else {
84-
throw new \InvalidArgumentException();
84+
throw new UnknownActivityException();
8585
}
8686

8787
return $event;
8888
}
8989

9090
/**
91-
* @throws \InvalidArgumentException
91+
* @throws UnknownActivityException
9292
*/
9393
protected function parseLongVersion(IEvent $event): IEvent {
9494
$subjectParameters = $this->getSubjectParameters($event);
@@ -113,7 +113,7 @@ protected function parseLongVersion(IEvent $event): IEvent {
113113
]);
114114
}
115115
} else {
116-
throw new \InvalidArgumentException();
116+
throw new UnknownActivityException();
117117
}
118118

119119
return $event;

apps/files/lib/Activity/FavoriteProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
6464
if ($this->activityManager->isFormattingFilteredObject()) {
6565
try {
6666
return $this->parseShortVersion($event);
67-
} catch (\InvalidArgumentException $e) {
67+
} catch (UnknownActivityException) {
6868
// Ignore and simply use the long version...
6969
}
7070
}
@@ -75,10 +75,10 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
7575
/**
7676
* @param IEvent $event
7777
* @return IEvent
78-
* @throws \InvalidArgumentException
78+
* @throws UnknownActivityException
7979
* @since 11.0.0
8080
*/
81-
public function parseShortVersion(IEvent $event) {
81+
public function parseShortVersion(IEvent $event): IEvent {
8282
if ($event->getSubject() === self::SUBJECT_ADDED) {
8383
$event->setParsedSubject($this->l->t('Added to favorites'));
8484
if ($this->activityManager->getRequirePNG()) {
@@ -95,7 +95,7 @@ public function parseShortVersion(IEvent $event) {
9595
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
9696
}
9797
} else {
98-
throw new \InvalidArgumentException();
98+
throw new UnknownActivityException();
9999
}
100100

101101
return $event;
@@ -105,10 +105,10 @@ public function parseShortVersion(IEvent $event) {
105105
* @param IEvent $event
106106
* @param IEvent|null $previousEvent
107107
* @return IEvent
108-
* @throws \InvalidArgumentException
108+
* @throws UnknownActivityException
109109
* @since 11.0.0
110110
*/
111-
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
111+
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
112112
if ($event->getSubject() === self::SUBJECT_ADDED) {
113113
$subject = $this->l->t('You added {file} to your favorites');
114114
if ($this->activityManager->getRequirePNG()) {
@@ -125,7 +125,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
125125
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
126126
}
127127
} else {
128-
throw new \InvalidArgumentException();
128+
throw new UnknownActivityException();
129129
}
130130

131131
$this->setSubjects($event, $subject);

apps/files/lib/Activity/Provider.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
9494
if ($this->activityManager->isFormattingFilteredObject()) {
9595
try {
9696
return $this->parseShortVersion($event, $previousEvent);
97-
} catch (\InvalidArgumentException $e) {
97+
} catch (UnknownActivityException) {
9898
// Ignore and simply use the long version...
9999
}
100100
}
@@ -114,10 +114,10 @@ protected function setIcon(IEvent $event, string $icon, string $app = 'files') {
114114
* @param IEvent $event
115115
* @param IEvent|null $previousEvent
116116
* @return IEvent
117-
* @throws \InvalidArgumentException
117+
* @throws UnknownActivityException
118118
* @since 11.0.0
119119
*/
120-
public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null) {
120+
public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
121121
$parsedParameters = $this->getParameters($event);
122122

123123
if ($event->getSubject() === 'created_by') {
@@ -139,7 +139,7 @@ public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null)
139139
$subject = $this->l->t('Moved by {user}');
140140
$this->setIcon($event, 'change');
141141
} else {
142-
throw new \InvalidArgumentException();
142+
throw new UnknownActivityException();
143143
}
144144

145145
if (!isset($parsedParameters['user'])) {
@@ -156,10 +156,10 @@ public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null)
156156
* @param IEvent $event
157157
* @param IEvent|null $previousEvent
158158
* @return IEvent
159-
* @throws \InvalidArgumentException
159+
* @throws UnknownActivityException
160160
* @since 11.0.0
161161
*/
162-
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
162+
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
163163
$this->fileIsEncrypted = false;
164164
$parsedParameters = $this->getParameters($event);
165165

@@ -253,7 +253,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
253253
$subject = $this->l->t('{user} moved {oldfile} to {newfile}');
254254
$this->setIcon($event, 'change');
255255
} else {
256-
throw new \InvalidArgumentException();
256+
throw new UnknownActivityException();
257257
}
258258

259259
if ($this->fileIsEncrypted) {
@@ -292,9 +292,9 @@ protected function setSubjects(IEvent $event, string $subject, array $parameters
292292
/**
293293
* @param IEvent $event
294294
* @return array
295-
* @throws \InvalidArgumentException
295+
* @throws UnknownActivityException
296296
*/
297-
protected function getParameters(IEvent $event) {
297+
protected function getParameters(IEvent $event): array {
298298
$parameters = $event->getSubjectParameters();
299299
switch ($event->getSubject()) {
300300
case 'created_self':
@@ -347,9 +347,9 @@ protected function getParameters(IEvent $event) {
347347
* @param array|string $parameter
348348
* @param IEvent|null $event
349349
* @return array
350-
* @throws \InvalidArgumentException
350+
* @throws UnknownActivityException
351351
*/
352-
protected function getFile($parameter, ?IEvent $event = null) {
352+
protected function getFile($parameter, ?IEvent $event = null): array {
353353
if (is_array($parameter)) {
354354
$path = reset($parameter);
355355
$id = (string)key($parameter);
@@ -358,7 +358,7 @@ protected function getFile($parameter, ?IEvent $event = null) {
358358
$path = $parameter;
359359
$id = $event->getObjectId();
360360
} else {
361-
throw new \InvalidArgumentException('Could not generate file parameter');
361+
throw new UnknownActivityException('Could not generate file parameter');
362362
}
363363

364364
$encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path);

apps/files/tests/Activity/ProviderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace OCA\Files\Tests\Activity;
77

88
use OCA\Files\Activity\Provider;
9+
use OCP\Activity\Exceptions\UnknownActivityException;
910
use OCP\Activity\IEvent;
1011
use OCP\Activity\IEventMerger;
1112
use OCP\Activity\IManager;
@@ -132,7 +133,7 @@ public function testGetFile($parameter, $eventId, $id, $name, $path): void {
132133

133134

134135
public function testGetFileThrows(): void {
135-
$this->expectException(\InvalidArgumentException::class);
136+
$this->expectException(UnknownActivityException::class);
136137

137138
$provider = $this->getProvider();
138139
self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]);

apps/settings/lib/Activity/GroupProvider.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
103103
return $event;
104104
}
105105

106-
/**
107-
* @throws \InvalidArgumentException
108-
*/
109106
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
110107
$event->setRichSubject($subject, $parameters);
111108
}

apps/settings/lib/Activity/Provider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
118118
/**
119119
* @param IEvent $event
120120
* @return array
121-
* @throws \InvalidArgumentException
121+
* @throws UnknownActivityException
122122
*/
123123
protected function getParameters(IEvent $event): array {
124124
$subject = $event->getSubject();
@@ -162,12 +162,9 @@ protected function getParameters(IEvent $event): array {
162162
];
163163
}
164164

165-
throw new \InvalidArgumentException('Unknown subject');
165+
throw new UnknownActivityException('Unknown subject');
166166
}
167167

168-
/**
169-
* @throws \InvalidArgumentException
170-
*/
171168
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
172169
$event->setRichSubject($subject, $parameters);
173170
}

apps/settings/tests/Activity/SecurityProviderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace OCA\Settings\Tests;
77

8-
use InvalidArgumentException;
98
use OCA\Settings\Activity\SecurityProvider;
9+
use OCP\Activity\Exceptions\UnknownActivityException;
1010
use OCP\Activity\IEvent;
1111
use OCP\Activity\IManager;
1212
use OCP\IL10N;
@@ -45,7 +45,7 @@ public function testParseUnrelated(): void {
4545
$event->expects($this->once())
4646
->method('getType')
4747
->willReturn('comments');
48-
$this->expectException(InvalidArgumentException::class);
48+
$this->expectException(UnknownActivityException::class);
4949

5050
$this->provider->parse($lang, $event);
5151
}
@@ -112,7 +112,7 @@ public function testParseInvalidSubject(): void {
112112
->method('getSubject')
113113
->willReturn('unrelated');
114114

115-
$this->expectException(InvalidArgumentException::class);
115+
$this->expectException(UnknownActivityException::class);
116116
$this->provider->parse($lang, $event);
117117
}
118118
}

apps/systemtags/lib/Activity/Provider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
6868
if ($this->activityManager->isFormattingFilteredObject()) {
6969
try {
7070
return $this->parseShortVersion($event);
71-
} catch (\InvalidArgumentException $e) {
71+
} catch (UnknownActivityException) {
7272
// Ignore and simply use the long version...
7373
}
7474
}
@@ -79,10 +79,10 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
7979
/**
8080
* @param IEvent $event
8181
* @return IEvent
82-
* @throws \InvalidArgumentException
82+
* @throws UnknownActivityException
8383
* @since 11.0.0
8484
*/
85-
public function parseShortVersion(IEvent $event) {
85+
public function parseShortVersion(IEvent $event): IEvent {
8686
$parsedParameters = $this->getParameters($event);
8787

8888
if ($this->activityManager->getRequirePNG()) {
@@ -142,7 +142,7 @@ public function parseShortVersion(IEvent $event) {
142142
]);
143143
}
144144
} else {
145-
throw new \InvalidArgumentException();
145+
throw new UnknownActivityException();
146146
}
147147

148148
return $event;
@@ -151,10 +151,10 @@ public function parseShortVersion(IEvent $event) {
151151
/**
152152
* @param IEvent $event
153153
* @return IEvent
154-
* @throws \InvalidArgumentException
154+
* @throws UnknownActivityException
155155
* @since 11.0.0
156156
*/
157-
public function parseLongVersion(IEvent $event) {
157+
public function parseLongVersion(IEvent $event): IEvent {
158158
$parsedParameters = $this->getParameters($event);
159159

160160
if ($this->activityManager->getRequirePNG()) {
@@ -249,7 +249,7 @@ public function parseLongVersion(IEvent $event) {
249249
->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters);
250250
}
251251
} else {
252-
throw new \InvalidArgumentException();
252+
throw new UnknownActivityException();
253253
}
254254

255255
return $event;

apps/twofactor_backupcodes/tests/Unit/Activity/ProviderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;
1010

11-
use InvalidArgumentException;
1211
use OCA\TwoFactorBackupCodes\Activity\Provider;
12+
use OCP\Activity\Exceptions\UnknownActivityException;
1313
use OCP\Activity\IEvent;
1414
use OCP\Activity\IManager;
1515
use OCP\IL10N;
@@ -47,7 +47,7 @@ public function testParseUnrelated(): void {
4747
$event->expects($this->once())
4848
->method('getApp')
4949
->willReturn('comments');
50-
$this->expectException(InvalidArgumentException::class);
50+
$this->expectException(UnknownActivityException::class);
5151

5252
$this->provider->parse($lang, $event);
5353
}
@@ -109,7 +109,7 @@ public function testParseInvalidSubject(): void {
109109
->method('getSubject')
110110
->willReturn('unrelated');
111111

112-
$this->expectException(InvalidArgumentException::class);
112+
$this->expectException(UnknownActivityException::class);
113113
$this->provider->parse($lang, $event);
114114
}
115115
}

0 commit comments

Comments
 (0)