code style changes

This commit is contained in:
mitsuha_s 2023-07-21 18:00:14 +03:00
parent 561b016e38
commit ffcfa29968
4 changed files with 148 additions and 111 deletions

View file

@ -15,7 +15,8 @@ use Symfony\Component\HttpFoundation\Request;
class PasteController extends AbstractController
{
#[Route('/')]
public function new(Request $request, PasteRepository $pasteRepository): Response {
public function new(Request $request, PasteRepository $pasteRepository): Response
{
$paste = new Paste();
$form = $this->createForm(PasteForm::class, $paste);
@ -32,7 +33,6 @@ class PasteController extends AbstractController
$pasteRepository->save($paste);
return $this->redirectToRoute($request->attributes->get('_route'));
}
return $this->render('paste.html.twig', [
@ -41,13 +41,13 @@ class PasteController extends AbstractController
}
#[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);
return $this->render('paste.html.twig', [
'form' => $form,
]);
}
}

View file

@ -51,91 +51,113 @@ class Paste
#[ORM\Column(length: 40, nullable: true)]
private ?string $secret;
public function getId(): int {
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void {
public function setId(int $id): void
{
$this->id = $id;
}
public function getText(): string {
public function getText(): string
{
return $this->text;
}
public function setText(string $text): void {
public function setText(string $text): void
{
$this->text = $text;
}
public function getLanguage(): ?string {
public function getLanguage(): ?string
{
return $this->language;
}
public function setLanguage(?string $language): void {
public function setLanguage(?string $language): void
{
$this->language = $language;
}
public function getDescription(): ?string {
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): void {
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getFilename(): ?string {
public function getFilename(): ?string
{
return $this->filename;
}
public function setFilename(?string $filename): void {
public function setFilename(?string $filename): void
{
$this->filename = $filename;
}
public function getAuthor(): string {
public function getAuthor(): string
{
return $this->author;
}
public function setAuthor(string $author): void {
public function setAuthor(string $author): void
{
$this->author = $author;
}
public function getPublishDate(): \DateTime {
public function getPublishDate(): \DateTime
{
return $this->publishDate;
}
public function setPublishDate(\DateTime $date): void {
public function setPublishDate(\DateTime $date): void
{
$this->publishDate = $date;
}
public function getExpirationDate(): ?\DateTime {
public function getExpirationDate(): ?\DateTime
{
return $this->expirationDate;
}
public function setExpirationDate(?\DateTime $date): void {
public function setExpirationDate(?\DateTime $date): void
{
$this->expirationDate = $date;
}
public function getIp(): string {
public function getIp(): string
{
return $this->ip;
}
public function setIP(string $ip): void {
public function setIP(string $ip): void
{
$this->ip = $ip;
}
public function getSecret(): ?string {
public function getSecret(): ?string
{
return $this->secret;
}
public function setSecret(?string $secret): void {
public function setSecret(?string $secret): void
{
$this->secret = $secret;
}
public function isPrivate(): bool {
public function isPrivate(): bool
{
return $this->private;
}
public function setPrivate(bool $private): void {
public function setPrivate(bool $private): void
{
$this->private = $private;
}
}

View file

@ -15,14 +15,27 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
class PasteForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void {
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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)
;

View file

@ -9,11 +9,13 @@ use Doctrine\Persistence\ManagerRegistry;
class PasteRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry) {
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Paste::class);
}
public function save(Paste $paste): void {
public function save(Paste $paste): void
{
$entityManager = $this->getEntityManager();
$entityManager->persist($paste);
$entityManager->flush();