WIP: feature_paste #1

Draft
Miroslavsckaya wants to merge 24 commits from feature_paste into master
3 changed files with 3 additions and 5 deletions
Showing only changes of commit 6a2f15d1d6 - Show all commits

View file

@ -24,9 +24,8 @@ class PasteController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$pasteData = $form->getData(); $pasteData = $form->getData();
skobkin marked this conversation as resolved Outdated

You can just set it in the constructor.

You can just set it in the constructor.
$pasteData->ip = $request->getClientIp();
skobkin marked this conversation as resolved Outdated

Do you need IP in PasteData?

Do you need IP in `PasteData`?
$paste = Paste::fromFormData($pasteData); $paste = Paste::fromFormDataAndIp($pasteData, $request->getClientIp());
$pasteRepository->save($paste, true); $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($request->attributes->get('_route'));

View file

@ -18,7 +18,6 @@ class PasteFormData
#[Assert\NotBlank] #[Assert\NotBlank]
public string $author = 'anonymous'; public string $author = 'anonymous';
public ?\DateTimeImmutable $expirationDate; public ?\DateTimeImmutable $expirationDate;
skobkin marked this conversation as resolved
Review

Why string and Assert\NotBlank?

Why `string` and `Assert\NotBlank`?
public string $ip;
public function __construct(?Paste $paste=null) public function __construct(?Paste $paste=null)
skobkin marked this conversation as resolved
Review

Is this validation being processed BEFORE storing the data in the DTO?
If not, it's pointless as with bool field earlier.

Is this validation being processed BEFORE storing the data in the DTO? If not, it's pointless as with `bool` field earlier.
{ {

View file

@ -35,7 +35,7 @@ class Paste
public readonly ?string $secret, public readonly ?string $secret,
) {} ) {}
skobkin marked this conversation as resolved Outdated

Why double quotes?

Why double quotes?
public static function fromFormData(PasteFormData $pasteFormData): Paste public static function fromFormDataAndIp(PasteFormData $pasteFormData, $ip): Paste
Review

You can use self as return type hint too.

You can use `self` as return type hint too.
{ {
return new self( return new self(
skobkin marked this conversation as resolved Outdated

Why mutable date? Do you plan to change publish date?

Why mutable date? Do you plan to change publish date?
$pasteFormData->text, $pasteFormData->text,
@ -45,7 +45,7 @@ class Paste
$pasteFormData->author, $pasteFormData->author,
new \DateTimeImmutable(), new \DateTimeImmutable(),
$pasteFormData->expirationDate, $pasteFormData->expirationDate,
$pasteFormData->ip, $ip,
$pasteFormData->private ? \hash('sha1', \random_bytes(25)) : null, $pasteFormData->private ? \hash('sha1', \random_bytes(25)) : null,
); );
} }