diff --git a/src/Controller/Api/ApiController.php b/src/Controller/Api/ApiController.php index a23552d..3be9573 100644 --- a/src/Controller/Api/ApiController.php +++ b/src/Controller/Api/ApiController.php @@ -34,11 +34,11 @@ class ApiController extends AbstractApiController $this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip); return $this->successResponse([ - 'id' => $snip->getId(), + 'id' => $snip->id, 'content' => $snip->getActiveText(), 'createdBy' => [ - 'id' => $snip->getCreatedBy()->getId(), - 'name' => $snip->getCreatedBy()->getName(), + 'id' => $snip->createdBy->getId(), + 'name' => $snip->createdBy->getName(), ], ]); } @@ -53,7 +53,7 @@ class ApiController extends AbstractApiController { $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); - if (!($snip->getActiveVersion() === $snip->getLatestVersion())) { + if (!($snip->activeVersion === $snip->getLatestVersion())) { return $this->errorResponse('Snip is not the latest version'); } @@ -64,13 +64,13 @@ class ApiController extends AbstractApiController } return $this->successResponse([ - 'id' => $snip->getId(), - 'name' => $snip->getName(), + 'id' => $snip->id, + 'name' => $snip->name, 'content' => $snip->getActiveText(), 'createdBy' => [ - 'id' => $snip->getCreatedBy()->getId(), - 'name' => $snip->getCreatedBy()->getName(), + 'id' => $snip->createdBy->getId(), + 'name' => $snip->createdBy->getName(), ], ]); } -} \ No newline at end of file +} diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php index 3cb8806..df62fa0 100644 --- a/src/Controller/SnipController.php +++ b/src/Controller/SnipController.php @@ -85,21 +85,20 @@ class SnipController extends AbstractController * Temporary solution to prevent editing of old versions * It technically fully works, but rendering the version history needs an update first */ - $isLatest = $snip->getActiveVersion() === $snip->getLatestVersion(); + $isLatest = $snip->activeVersion === $snip->getLatestVersion(); if (!$isLatest) { $this->addFlash('error', 'Snip is not the latest version, changes will not be saved.'); } $form = $this->createForm(SnipType::class, $snip) - ->add('Save', SubmitType::class) - ; + ->add('Save', SubmitType::class); $form->get('content')->setData($snip->getActiveText()); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { if (!$isLatest) { return $this->redirectToRoute('snip_single', [ - 'snip' => $snip->getId(), + 'snip' => $snip->id, ]); } $this->repository->save($snip); @@ -112,7 +111,7 @@ class SnipController extends AbstractController $this->addFlash('success', sprintf('Snip "%s" saved', $snip)); return $this->redirectToRoute('snip_single', [ - 'snip' => $snip->getId(), + 'snip' => $snip->id, ]); } @@ -126,9 +125,8 @@ class SnipController extends AbstractController public function new(Request $request, SnipContentService $contentService): Response { $snip = new Snip(); - $snip->setCreatedAtNow() - ->setCreatedBy($this->getUser()) - ; + $snip->setCreatedAtNow(); + $snip->createdBy = $this->getUser(); $form = $this->createForm(SnipType::class, $snip); $form->add('Create', SubmitType::class); @@ -145,7 +143,7 @@ class SnipController extends AbstractController $this->addFlash('success', sprintf('Snip "%s" created', $snip)); return $this->redirectToRoute('snip_single', [ - 'snip' => $snip->getId(), + 'snip' => $snip->id, ]); } @@ -163,7 +161,7 @@ class SnipController extends AbstractController $form = $this->createForm(ConfirmationType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $snip->setActiveVersion(null); + $snip->activeVersion = null; $this->repository->save($snip); $this->repository->remove($snip); $this->addFlash('success', sprintf('Snip "%s" deleted', $snip)); @@ -180,14 +178,14 @@ class SnipController extends AbstractController public function archive(Snip $snip): Response { $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); - $snip->setArchived(!$snip->isArchived()); + $snip->archived = !$snip->archived; $this->repository->save($snip); - if ($snip->isArchived()) { + if ($snip->archived) { $this->addFlash('success', sprintf('Snip "%s" archived', $snip)); } else { $this->addFlash('success', sprintf('Snip "%s" unarchived', $snip)); } - return $this->redirectToRoute('snip_edit', ['snip' => $snip->getId()]); + return $this->redirectToRoute('snip_edit', ['snip' => $snip->id]); } -} \ No newline at end of file +} diff --git a/src/Controller/VersionController.php b/src/Controller/VersionController.php index 8aa7d2e..8fc2ef1 100644 --- a/src/Controller/VersionController.php +++ b/src/Controller/VersionController.php @@ -21,7 +21,7 @@ class VersionController extends AbstractController public function index(Snip $snip): Response { $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); - + return $this->render('version/index.html.twig', [ 'snip' => $snip, ]); @@ -34,6 +34,6 @@ class VersionController extends AbstractController $this->contentService->setVersion($snip, $version); $this->addFlash('success', 'Snip version set to ' . $version->getId()); - return $this->redirectToRoute('snip_single', ['snip' => $snip->getId()]); + return $this->redirectToRoute('snip_single', ['snip' => $snip->id]); } -} \ No newline at end of file +} diff --git a/src/Dto/SnipPostRequest.php b/src/Dto/SnipPostRequest.php index 615d9ad..b3d97ed 100644 --- a/src/Dto/SnipPostRequest.php +++ b/src/Dto/SnipPostRequest.php @@ -17,13 +17,13 @@ class SnipPostRequest public function pushToSnip(Snip $snip): void { if ($this->name !== null) { - $snip->setName($this->name); + $snip->name = $this->name; } if ($this->public !== null) { - $snip->setPublic($this->public); + $snip->public = $this->public; } if ($this->visible !== null) { - $snip->setVisible($this->visible); + $snip->visible = $this->visible; } } -} \ No newline at end of file +} diff --git a/src/Entity/Helpers/TrackedTrait.php b/src/Entity/Helpers/TrackedTrait.php index 6cdf453..e90a92b 100644 --- a/src/Entity/Helpers/TrackedTrait.php +++ b/src/Entity/Helpers/TrackedTrait.php @@ -10,47 +10,23 @@ trait TrackedTrait { #[ORM\Column] #[ORM\JoinColumn(nullable: false)] - private ?DateTime $createdAt = null; + public ?DateTime $createdAt = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: false)] - private ?User $createdBy = null; - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - - public function setCreatedBy(?User $createdBy): self - { - $this->createdBy = $createdBy; - - return $this; - } - - public function getCreatedAt(): ?DateTime - { - return $this->createdAt; - } - - public function setCreatedAt(DateTime $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } + public ?User $createdBy = null; public function setCreatedAtNowNoSeconds(): self { - $this->setCreatedAt(DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'))); + $this->createdAt = DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i')); return $this; } public function setCreatedAtNow(): self { - $this->setCreatedAt(new DateTime()); + $this->createdAt = new DateTime(); return $this; } -} \ No newline at end of file +} diff --git a/src/Entity/Snip.php b/src/Entity/Snip.php index 0720844..ce97942 100644 --- a/src/Entity/Snip.php +++ b/src/Entity/Snip.php @@ -17,34 +17,34 @@ class Snip #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] - private ?int $id = null; + public ?int $id = null; #[ORM\Column(length: 255)] - private ?string $name = null; + public ?string $name = null; #[ORM\Column] - private bool $public = false; + public bool $public = false; #[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)] - private Collection $snipContents; + public Collection $snipContents; #[ORM\OneToOne] - private ?SnipContent $activeVersion = null; + public ?SnipContent $activeVersion = null; #[ORM\Column(length: 255)] - private ?string $parser = null; + public ?string $parser = null; #[ORM\Column] - private bool $visible = true; + public bool $visible = true; #[ORM\Column] - private bool $archived = false; + public bool $archived = false; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: Tag::class, mappedBy: 'snips')] - private Collection $tags; + public Collection $tags; public function __construct() { @@ -59,44 +59,7 @@ class Snip public function getActiveText(): string { - return SnipContentService::rebuildText($this->getActiveVersion()); - } - - public function getId(): ?int - { - return $this->id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(string $name): self - { - $this->name = $name; - - return $this; - } - - public function isPublic(): ?bool - { - return $this->public; - } - - public function setPublic(bool $public): self - { - $this->public = $public; - - return $this; - } - - /** - * @return Collection - */ - public function getSnipContents(): Collection - { - return $this->snipContents; + return SnipContentService::rebuildText($this->activeVersion); } public function addSnipContent(SnipContent $snipContent): self @@ -126,62 +89,6 @@ class Snip return $this->snipContents->last() ?: null; } - public function getActiveVersion(): ?SnipContent - { - return $this->activeVersion; - } - - public function setActiveVersion(?SnipContent $activeVersion): static - { - $this->activeVersion = $activeVersion; - - return $this; - } - - public function getParser(): ?string - { - return $this->parser; - } - - public function setParser(string $parser): static - { - $this->parser = $parser; - - return $this; - } - - public function isVisible(): ?bool - { - return $this->visible; - } - - public function setVisible(bool $visible): static - { - $this->visible = $visible; - - return $this; - } - - public function isArchived(): ?bool - { - return $this->archived; - } - - public function setArchived(bool $archived): static - { - $this->archived = $archived; - - return $this; - } - - /** - * @return Collection - */ - public function getTags(): Collection - { - return $this->tags; - } - public function addTag(Tag $tag): static { if (!$this->tags->contains($tag)) { diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 30b945b..68f0342 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -16,22 +16,22 @@ class Tag #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] - private ?int $id = null; + public ?int $id = null; #[ORM\Column(length: 255)] #[Assert\NotEqualTo(SnipFilterRequest::TAG_ALL)] #[Assert\NotEqualTo(SnipFilterRequest::TAG_NONE)] - private ?string $name = null; + public ?string $name = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: false)] - private ?User $user = null; + public ?User $user = null; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: Snip::class, inversedBy: 'tags')] - private Collection $snips; + public Collection $snips; public function __construct() { @@ -43,43 +43,6 @@ class Tag return $this->name ?? ''; } - public function getId(): ?int - { - return $this->id; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(string $name): static - { - $this->name = $name; - - return $this; - } - - public function getUser(): ?User - { - return $this->user; - } - - public function setUser(?User $user): static - { - $this->user = $user; - - return $this; - } - - /** - * @return Collection - */ - public function getSnips(): Collection - { - return $this->snips; - } - public function addSnip(Snip $snip): static { if (!$this->snips->contains($snip)) { diff --git a/src/Form/TagsType.php b/src/Form/TagsType.php index 6fc9249..0138138 100644 --- a/src/Form/TagsType.php +++ b/src/Form/TagsType.php @@ -34,7 +34,7 @@ class TagsType extends AbstractType implements DataTransformerInterface } if (is_array($value)) { - $tags = array_map(fn(Tag $tag) => $tag->getName(), $value); + $tags = array_map(fn(Tag $tag) => $tag->name, $value); } else { return ''; } @@ -51,7 +51,8 @@ class TagsType extends AbstractType implements DataTransformerInterface $tagEntity = $this->repository->findOneBy(['name' => $tag, 'user' => $user]); if ($tagEntity === null) { $tagEntity = new Tag(); - $tagEntity->setName($tag)->setUser($user); + $tagEntity->name = $tag; + $tagEntity->user = $user; // Validate the new Tag entity $errors = $this->validator->validate($tagEntity); @@ -90,4 +91,4 @@ class TagsType extends AbstractType implements DataTransformerInterface { return TextType::class; } -} \ No newline at end of file +} diff --git a/src/Security/Voter/SnipVoter.php b/src/Security/Voter/SnipVoter.php index b600d49..2fa8130 100644 --- a/src/Security/Voter/SnipVoter.php +++ b/src/Security/Voter/SnipVoter.php @@ -29,14 +29,14 @@ class SnipVoter extends Voter switch ($attribute) { case self::VIEW: - if ($subject->isPublic()) { + if ($subject->public) { return true; } case self::EDIT: if (!$user instanceof UserInterface) { return false; } - if ($subject->getCreatedBy() === $user) { + if ($subject->createdBy === $user) { return true; } break; diff --git a/src/Service/SnipContent/SnipContentService.php b/src/Service/SnipContent/SnipContentService.php index e254892..88cf107 100644 --- a/src/Service/SnipContent/SnipContentService.php +++ b/src/Service/SnipContent/SnipContentService.php @@ -15,7 +15,7 @@ readonly class SnipContentService public function update(Snip $snip, string $contents, ?string $contentName): void { - $parentContent = $snip->getActiveVersion(); + $parentContent = $snip->activeVersion; if (self::rebuildText($parentContent) === $contents) { return; } @@ -35,7 +35,7 @@ readonly class SnipContentService $this->em->persist($content); $this->em->flush(); - $snip->setActiveVersion($content); + $snip->activeVersion = $content; $this->em->persist($snip); $this->em->flush(); } @@ -61,11 +61,11 @@ readonly class SnipContentService public function setVersion(Snip $snip, SnipContent $version): void { - $activeVersion = $snip->getActiveVersion(); + $activeVersion = $snip->activeVersion; $this->contentToAbsolute($version); $this->contentToRelative($activeVersion); - $snip->setActiveVersion($version); + $snip->activeVersion = $version; $this->em->persist($snip); $this->em->flush(); } @@ -94,4 +94,4 @@ readonly class SnipContentService $this->em->persist($content); $this->em->flush(); } -} \ No newline at end of file +} diff --git a/src/Service/SnipParser/Generic/IncludeReferenceStage.php b/src/Service/SnipParser/Generic/IncludeReferenceStage.php index 302261f..5813221 100644 --- a/src/Service/SnipParser/Generic/IncludeReferenceStage.php +++ b/src/Service/SnipParser/Generic/IncludeReferenceStage.php @@ -41,7 +41,7 @@ class IncludeReferenceStage implements StageInterface } else { $snip = $this->snipRepository->find($id); if ($snip) { - $content = $this->snipContentRepository->find($snip->getActiveVersion()); + $content = $this->snipContentRepository->find($snip->activeVersion); } } if ($content === null) { @@ -56,4 +56,4 @@ class IncludeReferenceStage implements StageInterface ); }, $payload); } -} \ No newline at end of file +} diff --git a/src/Service/SnipParser/Generic/UrlReferenceStage.php b/src/Service/SnipParser/Generic/UrlReferenceStage.php index 1a45e2b..08a4948 100644 --- a/src/Service/SnipParser/Generic/UrlReferenceStage.php +++ b/src/Service/SnipParser/Generic/UrlReferenceStage.php @@ -36,8 +36,8 @@ readonly class UrlReferenceStage implements StageInterface return sprintf('%s', $matches[0]); } - $url = $this->router->generate('snip_single', ['snip' => $snip->getId()]); + $url = $this->router->generate('snip_single', ['snip' => $snip->id]); return sprintf('%s', $url, $snip); }, $payload); } -} \ No newline at end of file +} diff --git a/src/Service/SnipParser/ParserFactory.php b/src/Service/SnipParser/ParserFactory.php index 005911e..4a7230f 100644 --- a/src/Service/SnipParser/ParserFactory.php +++ b/src/Service/SnipParser/ParserFactory.php @@ -29,9 +29,9 @@ readonly class ParserFactory public function getBySnip(Snip $snip): ParserInterface { - $parser = $snip->getParser(); + $parser = $snip->parser; if (null === $parser) { - throw new ServiceNotFoundException(sprintf('Unknown parser for snip "%s"', $snip->getParser())); + throw new ServiceNotFoundException(sprintf('Unknown parser for snip "%s"', $snip->parser)); } return $this->get($parser); @@ -49,4 +49,4 @@ readonly class ParserFactory { foreach ($this->getAll() as $parser) yield $parser::getName(); } -} \ No newline at end of file +} diff --git a/src/Service/SnipParser/Twig/SnipLoader.php b/src/Service/SnipParser/Twig/SnipLoader.php index 467a66c..f60af21 100644 --- a/src/Service/SnipParser/Twig/SnipLoader.php +++ b/src/Service/SnipParser/Twig/SnipLoader.php @@ -25,7 +25,7 @@ class SnipLoader implements LoaderInterface public function getCacheKey(string $name): string { - return $this->getFromKey($name)->getActiveVersion()->getId(); + return $this->getFromKey($name)->activeVersion->getId(); } public function isFresh(string $name, int $time): bool @@ -58,4 +58,4 @@ class SnipLoader implements LoaderInterface return $snip; } -} \ No newline at end of file +} diff --git a/src/Service/SnipParser/Twig/SnipTwigExtension.php b/src/Service/SnipParser/Twig/SnipTwigExtension.php index e570074..2960a0e 100644 --- a/src/Service/SnipParser/Twig/SnipTwigExtension.php +++ b/src/Service/SnipParser/Twig/SnipTwigExtension.php @@ -56,8 +56,8 @@ class SnipTwigExtension extends AbstractExtension $request = new SnipFilterRequest(SnipFilterRequest::VISIBILITY_ALL, tag: $tag); $snips = $this->snipRepo->findByRequest($user, $request); return array_map(fn(Snip $snip) => [ - 'id' => $snip->getId(), - 'name' => $snip->getName(), + 'id' => $snip->id, + 'name' => $snip->name, ], $snips); } -} \ No newline at end of file +}