WIP: feature_paste #1

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

View file

@ -13,7 +13,7 @@ final class Version20230720115905 extends AbstractMigration
public function up(Schema $schema): void
skobkin marked this conversation as resolved
Review

Do you need it here if it's empty?

Do you need it here if it's empty?
{
$this->addSql('CREATE SEQUENCE paste_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE paste (id INT NOT NULL, text TEXT NOT NULL, language VARCHAR(25), description TEXT, filename VARCHAR(128), author VARCHAR(128) NOT NULL, publish_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, expiration_date TIMESTAMP(0) WITHOUT TIME ZONE, ip VARCHAR(15) NOT NULL, secret VARCHAR(40), PRIMARY KEY(id))');
$this->addSql('CREATE TABLE paste (id INT NOT NULL, text TEXT NOT NULL, language VARCHAR(25), description TEXT, filename VARCHAR(128), author VARCHAR(128), publish_date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, expiration_date TIMESTAMP(0) WITHOUT TIME ZONE, ip VARCHAR(15) NOT NULL, secret VARCHAR(40), PRIMARY KEY(id))');
}
public function down(Schema $schema): void

View file

@ -37,7 +37,7 @@ class PasteController extends AbstractController
}
#[Route('/{id}/{secret}')]
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
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.
$pasteData = new PasteFormData($paste);

View file

@ -15,11 +15,10 @@ class PasteFormData
public ?string $language = null;
public ?string $description = null;
public ?string $filename = null;
#[Assert\NotBlank]
public string $author = 'anonymous';
public ?string $author = null;
public ?\DateTimeImmutable $expirationDate;
skobkin marked this conversation as resolved
Review

Why string and Assert\NotBlank?

Why `string` and `Assert\NotBlank`?
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.
if ($paste === null)
{
skobkin marked this conversation as resolved
Review

Or you can make constructor private, use property promotion and add fromPaste() method to create it from the entity.

Or you can make constructor `private`, use property promotion and add `fromPaste()` method to create it from the entity.
@ -30,7 +29,7 @@ class PasteFormData
$this->language = $paste->language;
$this->description = $paste->description;
$this->filename = $paste->filename;
$this->author = $paste->author;
$this->author = $paste->author !== null ? $paste->author : 'anonymous';
$this->expirationDate = $paste->expirationDate;
}
}

View file

@ -23,8 +23,8 @@ class Paste
public readonly ?string $description,
#[ORM\Column(type: 'string', length: 128, nullable: true)]
public readonly ?string $filename,

What type? Why 25 exactly?

What type? Why 25 exactly?
Review

Why 128?

Why 128?
#[ORM\Column(type: 'string', length: 128, nullable: false)]
public readonly string $author,
#[ORM\Column(type: 'string', length: 128, nullable: true)]
public readonly ?string $author,
skobkin marked this conversation as resolved Outdated

Why not nullable?

Why not nullable?
#[ORM\Column(type: 'datetime_immutable', nullable: false)]
public readonly \DateTimeImmutable $publishDate,
#[ORM\Column(type: 'datetime_immutable', nullable: true)]

View file

@ -28,7 +28,7 @@ class PasteForm extends AbstractType
)
->add('description', TextType::class, ['required' => false])
->add('text', TextareaType::class)
->add('author', TextType::class, ['attr' => ['maxlength' =>128]])
->add('author', TextType::class, ['attr' => ['maxlength' => 128], 'required' => false])
skobkin marked this conversation as resolved Outdated

required => false?

`required => false`?
->add('filename', TextType::class, ['required' => false, 'attr' => ['maxlength' =>128]])
Review

Why 128?

Why 128?
->add('expirationDate', DateTimeType::class, [
'required' => false,