Skip to content

Commit

Permalink
fix(activity): Update more activity providers to use new exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Sep 18, 2024
1 parent a1c2a65 commit 09fd00c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 46 deletions.
10 changes: 5 additions & 5 deletions apps/comments/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
} catch (\InvalidArgumentException $e) {
} catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
Expand All @@ -66,7 +66,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
}

/**
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
protected function parseShortVersion(IEvent $event): IEvent {
$subjectParameters = $this->getSubjectParameters($event);
Expand All @@ -81,14 +81,14 @@ protected function parseShortVersion(IEvent $event): IEvent {
]);
}
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

return $event;
}

/**
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
protected function parseLongVersion(IEvent $event): IEvent {
$subjectParameters = $this->getSubjectParameters($event);
Expand All @@ -113,7 +113,7 @@ protected function parseLongVersion(IEvent $event): IEvent {
]);
}
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

return $event;
Expand Down
14 changes: 7 additions & 7 deletions apps/files/lib/Activity/FavoriteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
} catch (\InvalidArgumentException $e) {
} catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
Expand All @@ -75,10 +75,10 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
/**
* @param IEvent $event
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event) {
public function parseShortVersion(IEvent $event): IEvent {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$event->setParsedSubject($this->l->t('Added to favorites'));
if ($this->activityManager->getRequirePNG()) {
Expand All @@ -95,7 +95,7 @@ public function parseShortVersion(IEvent $event) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

return $event;
Expand All @@ -105,10 +105,10 @@ public function parseShortVersion(IEvent $event) {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
if ($event->getSubject() === self::SUBJECT_ADDED) {
$subject = $this->l->t('You added {file} to your favorites');
if ($this->activityManager->getRequirePNG()) {
Expand All @@ -125,7 +125,7 @@ public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg')));
}
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

$this->setSubjects($event, $subject);
Expand Down
24 changes: 12 additions & 12 deletions apps/files/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event, $previousEvent);
} catch (\InvalidArgumentException $e) {
} catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
Expand All @@ -114,10 +114,10 @@ protected function setIcon(IEvent $event, string $icon, string $app = 'files') {
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null) {
public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
$parsedParameters = $this->getParameters($event);

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

if (!isset($parsedParameters['user'])) {
Expand All @@ -156,10 +156,10 @@ public function parseShortVersion(IEvent $event, ?IEvent $previousEvent = null)
* @param IEvent $event
* @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null): IEvent {
$this->fileIsEncrypted = false;
$parsedParameters = $this->getParameters($event);

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

if ($this->fileIsEncrypted) {
Expand Down Expand Up @@ -292,9 +292,9 @@ protected function setSubjects(IEvent $event, string $subject, array $parameters
/**
* @param IEvent $event
* @return array
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
protected function getParameters(IEvent $event) {
protected function getParameters(IEvent $event): array {
$parameters = $event->getSubjectParameters();
switch ($event->getSubject()) {
case 'created_self':
Expand Down Expand Up @@ -347,9 +347,9 @@ protected function getParameters(IEvent $event) {
* @param array|string $parameter
* @param IEvent|null $event
* @return array
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
protected function getFile($parameter, ?IEvent $event = null) {
protected function getFile($parameter, ?IEvent $event = null): array {
if (is_array($parameter)) {
$path = reset($parameter);
$id = (string)key($parameter);
Expand All @@ -358,7 +358,7 @@ protected function getFile($parameter, ?IEvent $event = null) {
$path = $parameter;
$id = $event->getObjectId();
} else {
throw new \InvalidArgumentException('Could not generate file parameter');
throw new UnknownActivityException('Could not generate file parameter');
}

$encryptionContainer = $this->getEndToEndEncryptionContainer($id, $path);
Expand Down
3 changes: 2 additions & 1 deletion apps/files/tests/Activity/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace OCA\Files\Tests\Activity;

use OCA\Files\Activity\Provider;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -132,7 +133,7 @@ public function testGetFile($parameter, $eventId, $id, $name, $path): void {


public function testGetFileThrows(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectException(UnknownActivityException::class);

$provider = $this->getProvider();
self::invokePrivate($provider, 'getFile', ['/Foo/Bar.txt', null]);
Expand Down
3 changes: 0 additions & 3 deletions apps/settings/lib/Activity/GroupProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
return $event;
}

/**
* @throws \InvalidArgumentException
*/
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$event->setRichSubject($subject, $parameters);
}
Expand Down
7 changes: 2 additions & 5 deletions apps/settings/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null):
/**
* @param IEvent $event
* @return array
* @throws \InvalidArgumentException
* @throws UnknownActivityException
*/
protected function getParameters(IEvent $event): array {
$subject = $event->getSubject();
Expand Down Expand Up @@ -162,12 +162,9 @@ protected function getParameters(IEvent $event): array {
];
}

throw new \InvalidArgumentException('Unknown subject');
throw new UnknownActivityException('Unknown subject');
}

/**
* @throws \InvalidArgumentException
*/
protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$event->setRichSubject($subject, $parameters);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/settings/tests/Activity/SecurityProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
namespace OCA\Settings\Tests;

use InvalidArgumentException;
use OCA\Settings\Activity\SecurityProvider;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IL10N;
Expand Down Expand Up @@ -45,7 +45,7 @@ public function testParseUnrelated(): void {
$event->expects($this->once())
->method('getType')
->willReturn('comments');
$this->expectException(InvalidArgumentException::class);
$this->expectException(UnknownActivityException::class);

$this->provider->parse($lang, $event);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testParseInvalidSubject(): void {
->method('getSubject')
->willReturn('unrelated');

$this->expectException(InvalidArgumentException::class);
$this->expectException(UnknownActivityException::class);
$this->provider->parse($lang, $event);
}
}
14 changes: 7 additions & 7 deletions apps/systemtags/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
if ($this->activityManager->isFormattingFilteredObject()) {
try {
return $this->parseShortVersion($event);
} catch (\InvalidArgumentException $e) {
} catch (UnknownActivityException) {
// Ignore and simply use the long version...
}
}
Expand All @@ -79,10 +79,10 @@ public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
/**
* @param IEvent $event
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event) {
public function parseShortVersion(IEvent $event): IEvent {
$parsedParameters = $this->getParameters($event);

if ($this->activityManager->getRequirePNG()) {
Expand Down Expand Up @@ -142,7 +142,7 @@ public function parseShortVersion(IEvent $event) {
]);
}
} else {
throw new \InvalidArgumentException();
throw new UnknownActivityException();
}

return $event;
Expand All @@ -151,10 +151,10 @@ public function parseShortVersion(IEvent $event) {
/**
* @param IEvent $event
* @return IEvent
* @throws \InvalidArgumentException
* @throws UnknownActivityException
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event) {
public function parseLongVersion(IEvent $event): IEvent {
$parsedParameters = $this->getParameters($event);

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

return $event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;

use InvalidArgumentException;
use OCA\TwoFactorBackupCodes\Activity\Provider;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IL10N;
Expand Down Expand Up @@ -47,7 +47,7 @@ public function testParseUnrelated(): void {
$event->expects($this->once())
->method('getApp')
->willReturn('comments');
$this->expectException(InvalidArgumentException::class);
$this->expectException(UnknownActivityException::class);

$this->provider->parse($lang, $event);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testParseInvalidSubject(): void {
->method('getSubject')
->willReturn('unrelated');

$this->expectException(InvalidArgumentException::class);
$this->expectException(UnknownActivityException::class);
$this->provider->parse($lang, $event);
}
}

0 comments on commit 09fd00c

Please sign in to comment.