Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the LogicException when a report was rejected #915

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/Factory/ContentManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use App\Entity\Entry;
use App\Entity\EntryComment;
use App\Entity\Post;
use App\Entity\PostComment;
use App\Service\Contracts\ContentManagerInterface;
use App\Service\EntryCommentManager;
use App\Service\EntryManager;
use App\Service\PostCommentManager;
use App\Service\PostManager;
use Doctrine\ORM\EntityManagerInterface;

class ContentManagerFactory
{
Expand All @@ -22,18 +22,20 @@ public function __construct(
private readonly EntryCommentManager $entryCommentManager,
private readonly PostManager $postManager,
private readonly PostCommentManager $postCommentManager,
private readonly EntityManagerInterface $entityManager
) {
}

public function createManager(ContentInterface $subject): ContentManagerInterface
{
return match ($this->entityManager->getClassMetadata(\get_class($subject))->name) {
Entry::class => $this->entryManager,
EntryComment::class => $this->entryCommentManager,
Post::class => $this->postManager,
PostCommentManager::class => $this->postCommentManager,
default => throw new \LogicException(),
};
if ($subject instanceof Entry) {
return $this->entryManager;
} elseif ($subject instanceof EntryComment) {
return $this->entryCommentManager;
} elseif ($subject instanceof Post) {
return $this->postManager;
} elseif ($subject instanceof PostComment) {
return $this->postCommentManager;
}
throw new \LogicException("Unsupported subject type: '".\get_class($subject)."'");
}
}
Loading