diff --git a/src/Command/SnipUpdateContentCommand.php b/src/Command/SnipUpdateContentCommand.php index 0f07322..cd233ea 100644 --- a/src/Command/SnipUpdateContentCommand.php +++ b/src/Command/SnipUpdateContentCommand.php @@ -26,17 +26,16 @@ class SnipUpdateContentCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); +// $io = new SymfonyStyle($input, $output); $qb = $this->snipContentRepository->createQueryBuilder('s'); $qb->where('s.text IS NOT NULL'); - $c = 0; /** @var SnipContent $snipContent */ foreach ($qb->getQuery()->getResult() as $snipContent) { - $text = $snipContent->getText(); + $text = $snipContent->text; $text = Lexer::reconstruct(Lexer::tokenize($text)); - $snipContent->setText($text); + $snipContent->text = $text; $this->snipContentRepository->save($snipContent); } diff --git a/src/Controller/SnipContentController.php b/src/Controller/SnipContentController.php index d282ad3..d1ebf9e 100644 --- a/src/Controller/SnipContentController.php +++ b/src/Controller/SnipContentController.php @@ -18,10 +18,10 @@ class SnipContentController extends AbstractController #[Route('/compare/{to}/{from}', name: '_compare')] public function compare(SnipContent $to, ?SnipContent $from = null): Response { - $this->denyAccessUnlessGranted(SnipVoter::VIEW, $to->getSnip()); + $this->denyAccessUnlessGranted(SnipVoter::VIEW, $to->snip); if ($from === null) { - $from = $to->getParent(); + $from = $to->parent; } $diff = MyersDiff::buildDiffLines( @@ -30,8 +30,8 @@ class SnipContentController extends AbstractController ); return $this->render('content/compare.html.twig', [ - 'snip' => $to->getSnip(), + 'snip' => $to->snip, 'diff' => $diff, ]); } -} \ No newline at end of file +} diff --git a/src/Controller/VersionController.php b/src/Controller/VersionController.php index 8fc2ef1..5ac1cca 100644 --- a/src/Controller/VersionController.php +++ b/src/Controller/VersionController.php @@ -33,7 +33,7 @@ class VersionController extends AbstractController $this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip); $this->contentService->setVersion($snip, $version); - $this->addFlash('success', 'Snip version set to ' . $version->getId()); + $this->addFlash('success', 'Snip version set to ' . $version->id); return $this->redirectToRoute('snip_single', ['snip' => $snip->id]); } } diff --git a/src/Entity/Snip.php b/src/Entity/Snip.php index ce97942..d74ca8c 100644 --- a/src/Entity/Snip.php +++ b/src/Entity/Snip.php @@ -66,7 +66,7 @@ class Snip { if (!$this->snipContents->contains($snipContent)) { $this->snipContents->add($snipContent); - $snipContent->setSnip($this); + $snipContent->snip = $this; } return $this; @@ -76,8 +76,8 @@ class Snip { if ($this->snipContents->removeElement($snipContent)) { // set the owning side to null (unless already changed) - if ($snipContent->getSnip() === $this) { - $snipContent->setSnip(null); + if ($snipContent->snip === $this) { + $snipContent->snip = null; } } diff --git a/src/Entity/SnipContent.php b/src/Entity/SnipContent.php index 1cc8305..fc1ae51 100644 --- a/src/Entity/SnipContent.php +++ b/src/Entity/SnipContent.php @@ -17,124 +17,30 @@ class SnipContent #[ORM\Column(type: UlidType::NAME, unique: true)] #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')] - private ?Ulid $id = null; + public ?Ulid $id = null; #[ORM\ManyToOne(inversedBy: 'snipContents')] #[ORM\JoinColumn(nullable: false)] - private ?Snip $snip = null; + public ?Snip $snip = null; #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] - private ?self $parent = null; + public ?self $parent = null; - #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] - private Collection $children; + /** @var Collection */ + #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] + public Collection $children; #[ORM\Column(type: Types::TEXT, nullable: true)] - private ?string $text = null; + public ?string $text = null; #[ORM\Column(nullable: true)] - private ?array $diff = null; + public ?array $diff = null; #[ORM\Column(length: 255, nullable: true)] - private ?string $name = null; + public ?string $name = null; public function __construct() { $this->children = new ArrayCollection(); } - - public function getId(): ?Ulid - { - return $this->id; - } - - public function getSnip(): ?Snip - { - return $this->snip; - } - - public function setSnip(?Snip $snip): self - { - $this->snip = $snip; - - return $this; - } - - public function getParent(): ?self - { - return $this->parent; - } - - public function setParent(?self $parent): self - { - $this->parent = $parent; - - return $this; - } - - /** - * @return Collection - */ - public function getChildren(): Collection - { - return $this->children; - } - - public function addChild(self $child): self - { - if (!$this->children->contains($child)) { - $this->children->add($child); - $child->setParent($this); - } - - return $this; - } - - public function removeChild(self $child): self - { - if ($this->children->removeElement($child)) { - // set the owning side to null (unless already changed) - if ($child->getParent() === $this) { - $child->setParent(null); - } - } - - return $this; - } - - public function getText(): ?string - { - return $this->text; - } - - public function setText(?string $text): self - { - $this->text = $text; - - return $this; - } - - public function getDiff(): ?array - { - return $this->diff; - } - - public function setDiff(?array $diff): static - { - $this->diff = $diff; - - return $this; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(?string $name): static - { - $this->name = $name; - - return $this; - } } diff --git a/src/Service/SnipContent/SnipContentService.php b/src/Service/SnipContent/SnipContentService.php index 88cf107..303f759 100644 --- a/src/Service/SnipContent/SnipContentService.php +++ b/src/Service/SnipContent/SnipContentService.php @@ -22,13 +22,12 @@ readonly class SnipContentService // Create new snipContent entity with previous one as parent $content = new SnipContent(); - $content - ->setText($contents) - ->setSnip($snip) - ->setName($contentName) - ; + $content->text = $contents; + $content->snip = $snip; + $content->name = $contentName; + if ($parentContent !== null) { - $content->setParent($parentContent); + $content->parent = $parentContent; $this->contentToRelative($parentContent); } @@ -45,17 +44,17 @@ readonly class SnipContentService if ($snipContent === null) { return ''; } - if ($snipContent->getText()) { - return $snipContent->getText(); + if ($snipContent->text) { + return $snipContent->text; } - $parentContent = $snipContent->getParent(); - if ($parentContent === null && $snipContent->getDiff() === null) { + $parentContent = $snipContent->parent; + if ($parentContent === null && $snipContent->diff === null) { return '---Something went very wrong, cant rebuild the text---'; } return MyersDiff::rebuildBFromCompact( - self::rebuildText($parentContent), $snipContent->getDiff() + self::rebuildText($parentContent), $snipContent->diff ); } @@ -72,25 +71,25 @@ readonly class SnipContentService public function contentToRelative(SnipContent $content): void { - if ($content->getText() === null || $content->getParent() === null) { + if ($content->text === null || $content->parent === null) { return; } - $contentText = $content->getText(); - $parentText = self::rebuildText($content->getParent()); + $contentText = $content->text; + $parentText = self::rebuildText($content->parent); $diff = MyersDiff::calculate($parentText, $contentText); - $content->setDiff($diff); - $content->setText(null); + $content->diff = $diff; + $content->text = null; $this->em->persist($content); $this->em->flush(); } public function contentToAbsolute(SnipContent $content): void { - if ($content->getDiff() === null) { + if ($content->diff === null) { return; } - $content->setText(self::rebuildText($content)); - $content->setDiff(null); + $content->text = self::rebuildText($content); + $content->diff = null; $this->em->persist($content); $this->em->flush(); } diff --git a/src/Service/SnipParser/Generic/IncludeReferenceStage.php b/src/Service/SnipParser/Generic/IncludeReferenceStage.php index 5813221..5dcbe99 100644 --- a/src/Service/SnipParser/Generic/IncludeReferenceStage.php +++ b/src/Service/SnipParser/Generic/IncludeReferenceStage.php @@ -37,7 +37,7 @@ class IncludeReferenceStage implements StageInterface $content = null; } if ($content) { - $snip = $content->getSnip(); + $snip = $content->snip; } else { $snip = $this->snipRepository->find($id); if ($snip) { diff --git a/src/Service/SnipParser/Twig/SnipLoader.php b/src/Service/SnipParser/Twig/SnipLoader.php index f60af21..f9f7853 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)->activeVersion->getId(); + return $this->getFromKey($name)->activeVersion->id; } public function isFresh(string $name, int $time): bool