Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich committed Nov 11, 2023
1 parent aebc221 commit ff3c263
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public function __construct(
private readonly ActivityPubManager $manager,
private readonly MagazineRepository $magazineRepository,
private readonly UrlGeneratorInterface $urlGenerator
) { }
) {
}

public function __invoke(Magazine $magazine, Request $request): JsonResponse
{
Expand Down Expand Up @@ -48,10 +49,10 @@ private function getCollectionItems(Magazine $magazine): array
$items[] = $this->manager->getActorProfileId($actor);
}

$routeName = "ap_magazine_moderators";
$routeName = 'ap_magazine_moderators';
$routeParams = ['name' => $magazine->name];

return [
return [
'@context' => ActivityPubActivityInterface::CONTEXT_URL,
'type' => 'OrderedCollection',
'id' => $this->urlGenerator->generate($routeName, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Magazine/MagazineModController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class MagazineModController extends AbstractController
public function __invoke(Magazine $magazine, MagazineRepository $repository, Request $request): Response
{
$moderatorsWithoutOwner = [];
foreach ($repository->findModerators($magazine, $this->getPageNb($request)) as /** @var $mod Moderator */ $mod) {
foreach ($repository->findModerators($magazine, $this->getPageNb($request)) as /* @var $mod Moderator */ $mod) {
// only include the owner if it is a local magazine, for remote magazines the owner is always the admin
if(!$mod->isOwner or $magazine->apId == null) {
if (!$mod->isOwner or null === $magazine->apId) {
$moderatorsWithoutOwner[] = $mod;
}
}

return $this->render(
'magazine/moderators.html.twig',
[
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Magazine.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function isSubscribed(User $user): bool

public function updateSubscriptionsCount(): void
{
if($this->apFollowersCount != null) {
if (null !== $this->apFollowersCount) {
$this->subscriptionsCount = $this->apFollowersCount;
} else {
$this->subscriptionsCount = $this->subscriptions->count();
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function isFollowing(User $user): bool

public function updateFollowCounts(): void
{
if($this->apFollowersCount != null) {
if (null !== $this->apFollowersCount) {
$this->followersCount = $this->apFollowersCount;
} else {
$this->followersCount = $this->followers->count();
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ActivityPub/ApHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function (ItemInterface $item) use ($apAddress) {
]);
} catch (\Exception $e) {
$msg = "AP Get fail: {$apAddress}, ";
if($response != null) {
if (null !== $response) {
$msg .= $response->getContent(false);
}
throw new InvalidApPostException($msg);
Expand Down
41 changes: 22 additions & 19 deletions src/Service/ActivityPubManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function createCcFromBody(string $body): array
*
* @param string $actorUrlOrHandle actor URL or actor handle
*
* @return null|User|Magazine or Magazine or null on error
* @return User|Magazine|null or Magazine or null on error
*/
public function findActorOrCreate(string $actorUrlOrHandle): null|User|Magazine
{
Expand Down Expand Up @@ -283,14 +283,15 @@ public function updateUser(string $actorUrl): ?User
$user->cover = $newImage;
}

if($user->apFollowersUrl != null) {
if (null !== $user->apFollowersUrl) {
try {
$followersObj = $this->apHttpClient->getCollectionObject($user->apFollowersUrl);
if(isset($followersObj['totalItems']) and is_int($followersObj['totalItems'])) {
if (isset($followersObj['totalItems']) and \is_int($followersObj['totalItems'])) {
$user->apFollowersCount = $followersObj['totalItems'];
$user->updateFollowCounts();
}
} catch (InvalidApPostException $ignored) { }
} catch (InvalidApPostException $ignored) {
}
}

// Write to DB
Expand Down Expand Up @@ -388,48 +389,49 @@ public function updateMagazine(string $actorUrl): ?Magazine
$magazine->apFetchedAt = new \DateTime();
$magazine->isAdult = (bool) $actor['sensitive'];

if ($magazine->apFollowersUrl != null) {
if (null !== $magazine->apFollowersUrl) {
try {
$this->logger->info("updating remote followers of magazine $actorUrl");
$followersObj = $this->apHttpClient->getCollectionObject($magazine->apFollowersUrl);
if(isset($followersObj['totalItems']) and is_int($followersObj['totalItems'])) {
if (isset($followersObj['totalItems']) and \is_int($followersObj['totalItems'])) {
$magazine->apFollowersCount = $followersObj['totalItems'];
$magazine->updateSubscriptionsCount();
}
} catch (InvalidApPostException $ignored) { }
} catch (InvalidApPostException $ignored) {
}
}

if ($magazine->apAttributedToUrl != null) {
if (null !== $magazine->apAttributedToUrl) {
try {
$this->logger->info("fetching moderators of remote magazine $actorUrl");
$attributedObj = $this->apHttpClient->getCollectionObject($magazine->apAttributedToUrl);
$items = null;
if (isset($attributedObj['items']) and is_array($attributedObj['items'])) {
if (isset($attributedObj['items']) and \is_array($attributedObj['items'])) {
$items = $attributedObj['items'];
} else if(isset($attributedObj['orderedItems']) and is_array($attributedObj['orderedItems'])) {
} elseif (isset($attributedObj['orderedItems']) and \is_array($attributedObj['orderedItems'])) {
$items = $attributedObj['orderedItems'];
}

if($items != null) {
if (null !== $items) {
$moderatorsToRemove = [];
foreach($magazine->moderators as /** @var $mod Moderator */ $mod) {
if(!$mod->isOwner) {
foreach ($magazine->moderators as /* @var $mod Moderator */ $mod) {
if (!$mod->isOwner) {
$moderatorsToRemove[] = $mod->user;
}
}
$indexesNotToRemove = [];

foreach ($items as $item) {
if (is_string($item)) {
if (\is_string($item)) {
$user = $this->findActorOrCreate($item);
if ($user instanceof User) {
foreach ($moderatorsToRemove as $key => $existMod) {
if ($existMod->username == $user->username) {
if ($existMod->username === $user->username) {
$indexesNotToRemove[] = $key;
break;
}
}
if(!$magazine->userIsModerator($user)) {
if (!$magazine->userIsModerator($user)) {
$magazine->addModerator(new Moderator($magazine, $user, false, true));
}
}
Expand All @@ -441,15 +443,16 @@ public function updateMagazine(string $actorUrl): ?Magazine
}

foreach ($moderatorsToRemove as $modToRemove) {
if ($modToRemove == null) {
if (null === $modToRemove) {
continue;
}
$magazine->removeUserAsModerator($modToRemove);
}
} else {
$this->logger->warning("could not update the moderators of $actorUrl, the response doesn't have a 'items' or 'orderedItems' property or it is not an array");
}
} catch (InvalidApPostException $ignored) { }
} catch (InvalidApPostException $ignored) {
}
}

$this->entityManager->flush();
Expand Down Expand Up @@ -548,7 +551,7 @@ public function handleExternalVideos(array $attachment): ?array
*
* @param string $actorUrl actor URL
*
* @return null|Magazine|User null on error
* @return Magazine|User|null null on error
*/
public function updateActor(string $actorUrl): null|Magazine|User
{
Expand Down

0 comments on commit ff3c263

Please sign in to comment.