From ffcfa299686f0cf0ae60d6d10c9ef918f0fea36f Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Fri, 21 Jul 2023 18:00:14 +0300 Subject: [PATCH] code style changes --- src/Controller/PasteController.php | 50 +++++----- src/Entity/Paste.php | 144 +++++++++++++++++------------ src/Form/Type/PasteForm.php | 41 +++++--- src/Repository/PasteRepository.php | 24 ++--- 4 files changed, 148 insertions(+), 111 deletions(-) diff --git a/src/Controller/PasteController.php b/src/Controller/PasteController.php index 812c4e3..6ab962c 100644 --- a/src/Controller/PasteController.php +++ b/src/Controller/PasteController.php @@ -1,53 +1,53 @@ createForm(PasteForm::class, $paste); + public function new(Request $request, PasteRepository $pasteRepository): Response + { + $paste = new Paste(); + $form = $this->createForm(PasteForm::class, $paste); - $form->handleRequest($request); + $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $paste = $form->getData(); - $paste->setIp($request->getClientIp()); - $paste->setPublishDate(new \DateTime()); + $paste = $form->getData(); + $paste->setIp($request->getClientIp()); + $paste->setPublishDate(new \DateTime()); if ($paste->isPrivate()) { - $paste->setSecret(hash('sha1', random_bytes(25))); + $paste->setSecret(hash('sha1', random_bytes(25))); } - $pasteRepository->save($paste); + $pasteRepository->save($paste); - return $this->redirectToRoute($request->attributes->get('_route')); - + return $this->redirectToRoute($request->attributes->get('_route')); } return $this->render('paste.html.twig', [ 'form' => $form, - ]); + ]); } #[Route('/{id}/{secret}')] - public function show_paste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response { + public function showPaste(PasteRepository $pasteRepository, Request $request, string $id, ?string $secret=NULL): Response + { $paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]); - $form = $this->createForm(PasteForm::class, $paste); + $form = $this->createForm(PasteForm::class, $paste); return $this->render('paste.html.twig', [ 'form' => $form, - ]); - + ]); } } diff --git a/src/Entity/Paste.php b/src/Entity/Paste.php index e0b589b..d4c9c59 100644 --- a/src/Entity/Paste.php +++ b/src/Entity/Paste.php @@ -1,12 +1,12 @@ id; + public function getId(): int + { + return $this->id; } - public function setId(int $id): void { - $this->id = $id; + public function setId(int $id): void + { + $this->id = $id; } - public function getText(): string { - return $this->text; + public function getText(): string + { + return $this->text; } - public function setText(string $text): void { - $this->text = $text; + public function setText(string $text): void + { + $this->text = $text; } - public function getLanguage(): ?string { - return $this->language; + public function getLanguage(): ?string + { + return $this->language; } - public function setLanguage(?string $language): void { - $this->language = $language; + public function setLanguage(?string $language): void + { + $this->language = $language; } - public function getDescription(): ?string { - return $this->description; + public function getDescription(): ?string + { + return $this->description; } - public function setDescription(?string $description): void { - $this->description = $description; + public function setDescription(?string $description): void + { + $this->description = $description; } - public function getFilename(): ?string { - return $this->filename; + public function getFilename(): ?string + { + return $this->filename; } - public function setFilename(?string $filename): void { - $this->filename = $filename; + public function setFilename(?string $filename): void + { + $this->filename = $filename; } - public function getAuthor(): string { - return $this->author; + public function getAuthor(): string + { + return $this->author; } - public function setAuthor(string $author): void { - $this->author = $author; + public function setAuthor(string $author): void + { + $this->author = $author; } - public function getPublishDate(): \DateTime { - return $this->publishDate; + public function getPublishDate(): \DateTime + { + return $this->publishDate; } - public function setPublishDate(\DateTime $date): void { - $this->publishDate = $date; + public function setPublishDate(\DateTime $date): void + { + $this->publishDate = $date; } - public function getExpirationDate(): ?\DateTime { - return $this->expirationDate; + public function getExpirationDate(): ?\DateTime + { + return $this->expirationDate; } - public function setExpirationDate(?\DateTime $date): void { - $this->expirationDate = $date; + public function setExpirationDate(?\DateTime $date): void + { + $this->expirationDate = $date; } - public function getIp(): string { - return $this->ip; + public function getIp(): string + { + return $this->ip; } - public function setIP(string $ip): void { - $this->ip = $ip; + public function setIP(string $ip): void + { + $this->ip = $ip; } - public function getSecret(): ?string { - return $this->secret; + public function getSecret(): ?string + { + return $this->secret; } - public function setSecret(?string $secret): void { - $this->secret = $secret; + public function setSecret(?string $secret): void + { + $this->secret = $secret; } - public function isPrivate(): bool { - return $this->private; + public function isPrivate(): bool + { + return $this->private; } - public function setPrivate(bool $private): void { - $this->private = $private; + public function setPrivate(bool $private): void + { + $this->private = $private; } } \ No newline at end of file diff --git a/src/Form/Type/PasteForm.php b/src/Form/Type/PasteForm.php index 042188d..8485aef 100644 --- a/src/Form/Type/PasteForm.php +++ b/src/Form/Type/PasteForm.php @@ -1,30 +1,43 @@ add('language', ChoiceType::class, ['choices' => ['Python' => 'python', 'PHP' => 'php', 'Plain text' => NULL]]) + ->add('language', ChoiceType::class, [ + 'choices' => [ + 'Python' => 'python', + 'PHP' => 'php', + 'Plain text' => NULL, + ] + ] + ) ->add('description', TextType::class, ['required' => false]) ->add('text', TextareaType::class) ->add('author', TextType::class, ['attr' => ['maxlength' =>128]]) ->add('filename', TextType::class, ['required' => false, 'attr' => ['maxlength' =>128]]) - ->add('expirationDate', DateTimeType::class, ['required' => false, 'date_widget' => 'single_text', 'input' => 'datetime']) + ->add('expirationDate', DateTimeType::class, [ + 'required' => false, + 'date_widget' => 'single_text', + 'input' => 'datetime', + ] + ) ->add('private', CheckboxType::class, ['required' => false]) ->add('save', SubmitType::class) - ; + ; } } \ No newline at end of file diff --git a/src/Repository/PasteRepository.php b/src/Repository/PasteRepository.php index 1065282..74ee7d5 100644 --- a/src/Repository/PasteRepository.php +++ b/src/Repository/PasteRepository.php @@ -1,21 +1,23 @@ getEntityManager(); - $entityManager->persist($paste); - $entityManager->flush(); + public function save(Paste $paste): void + { + $entityManager = $this->getEntityManager(); + $entityManager->persist($paste); + $entityManager->flush(); } } \ No newline at end of file