WIP: feature_paste #1

Draft
Miroslavsckaya wants to merge 24 commits from feature_paste into master
Showing only changes of commit a442fe31f9 - Show all commits

View file

@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
class PasteController extends AbstractController
{
Review

I'd suggest explicitly defining which request methods we're processing here.

P.S. We'll move this to YAML in the end.

I'd suggest explicitly defining which request methods we're processing here. P.S. We'll move this to YAML in the end.
#[Route('/')]
#[Route('/', name: 'homepage')]
skobkin marked this conversation as resolved Outdated

You don't really need EntityManager here.

Make your repository implement save like I showed you and use it instead.

You don't really need `EntityManager` here. Make your repository implement `save` like I showed you and use it instead.
public function new(Request $request, PasteRepository $pasteRepository): Response
skobkin marked this conversation as resolved Outdated

I'd suggest we refactor this to to DTO usage and make our Paste entity immutable.

I'd suggest we refactor this to to DTO usage and make our `Paste` entity immutable.
{
$pasteData = new PasteFormData();
@ -28,7 +28,7 @@ class PasteController extends AbstractController
$paste = Paste::fromFormDataAndIp($pasteData, $request->getClientIp());
$pasteRepository->save($paste, true);
skobkin marked this conversation as resolved Outdated

Do we need double quotes here?

By the way, we can also do that in the constructor.

Do we need double quotes here? By the way, we can also do that in the constructor.
skobkin marked this conversation as resolved Outdated

This still could be done in the entity itself.

This still could be done in the entity itself.
return $this->redirectToRoute($request->attributes->get('_route'));
return $this->redirectToRoute('showpaste', ['id' => $paste->id, 'secret' => $paste->secret]);
}
skobkin marked this conversation as resolved Outdated

I still suggest to make Paste::fromFormData().

I still suggest to make `Paste::fromFormData()`.
return $this->render('paste.html.twig', [
@ -36,7 +36,7 @@ class PasteController extends AbstractController
]);
skobkin marked this conversation as resolved Outdated

I see you needed some space 🤔

I see you needed some space 🤔
}
#[Route('/{id}/{secret}')]
#[Route('/{id}/{secret}', name: 'showpaste')]
skobkin marked this conversation as resolved Outdated

I mean you don't need to pass creation date here at all.

I mean you don't need to pass creation date here at all.
public function showPaste(PasteRepository $pasteRepository, string $id, ?string $secret = NULL): Response
Review

show_paste at least.

`show_paste` at least.
{
$paste = $pasteRepository->findOneBy(['id' => $id, 'secret' => $secret]);
skobkin marked this conversation as resolved Outdated
  • it's a good idea to add , to the last argument too if you use multi-line formatting
  • if you're doing this in the controller, you can just do something like $pasteData->private ? \hash('sha1', \random_bytes(25)) : null. But I suggest to do that in the static method (named constructor) as I also suggested nearby.
- it's a good idea to add `,` to the last argument too if you use multi-line formatting - if you're doing this in the controller, you can just do something like `$pasteData->private ? \hash('sha1', \random_bytes(25)) : null`. But I suggest to do that in the static method (named constructor) as I also suggested nearby.