Skip to content

Commit 9b49010

Browse files
authored
fix: diff of Doctrine annotations (#1521)
1 parent 5bbb16e commit 9b49010

File tree

2 files changed

+33
-78
lines changed

2 files changed

+33
-78
lines changed

.github/linters/.textlintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"rules": {
33
"terminology": {
44
"exclude": [
5-
"Node(?:js)?"
5+
"Node(?:js)?",
6+
"web[- ]?site(s)?"
67
]
78
}
89
}

distribution/index.md

Lines changed: 31 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ The framework also use these metadata to serialize and deserialize data from JSO
339339

340340
For the sake of simplicity, in this example we used public properties (except for the id, see below). API Platform (as well
341341
as Symfony and Doctrine) also supports accessor methods (getters/setters), use them if you want to.
342-
We used a private property and a getter for the id to enforce the fact that it is read only (we will let the DBMS generating it). API Platform also has first-grade support for UUIDs. [You should
343-
probably use them instead of auto-incremented ids](https://www.clever-cloud.com/blog/engineering/2015/05/20/why-auto-increment-is-a-terrible-idea/).
342+
We used a private property and a getter for the ID to enforce the fact that it is read only (we will let the DBMS generating it). API Platform also has first-grade support for UUIDs. [You should
343+
probably use them instead of auto-incremented IDs](https://www.clever-cloud.com/blog/engineering/2015/05/20/why-auto-increment-is-a-terrible-idea/).
344344

345345
Because API Platform provides all the infrastructure for us, our API is almost ready!
346346

@@ -369,62 +369,37 @@ Modify these files as described in these patches:
369369
use Doctrine\Common\Collections\ArrayCollection;
370370
+use Doctrine\ORM\Mapping as ORM;
371371

372-
-/** A book. */
373-
+/**
374-
+ * A book.
375-
+ *
376-
+ */
377-
#[ORM\Entity]
372+
/** A book. */
373+
+#[ORM\Entity]
378374
#[ApiResource]
379375
class Book
380376
{
381-
- /** The id of this book. */
382-
+ /**
383-
+ * The id of this book.
384-
+ */
385-
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
377+
/** The id of this book. */
378+
+ #[ORM\Id, ORM\Column, ORM\GeneratedValue]
386379
private ?int $id = null;
387380

388-
- /** The ISBN of this book (or null if doesn't have one). */
389-
+ /**
390-
+ * The ISBN of this book (or null if doesn't have one).
391-
+ */
392-
#[ORM\Column(nullable: true)]
381+
/** The ISBN of this book (or null if doesn't have one). */
382+
+ #[ORM\Column(nullable: true)]
393383
public ?string $isbn = null;
394384

395-
- /** The title of this book. */
396-
+ /**
397-
+ * The title of this book.
398-
+ */
399-
#[ORM\Column]
385+
/** The title of this book. */
386+
+ #[ORM\Column]
400387
public string $title = '';
401388

402-
- /** The description of this book. */
403-
+ /**
404-
+ * The description of this book.
405-
+ */
406-
#[ORM\Column(type="text")]
389+
/** The description of this book. */
390+
+ #[ORM\Column(type: "text")]
407391
public string $description = '';
408392

409-
- /** The author of this book. */
410-
+ /**
411-
+ * The author of this book.
412-
+ */
413-
#[ORM\Column]
393+
/** The author of this book. */
394+
+ #[ORM\Column]
414395
public string $author = '';
415396

416-
- /** The publication date of this book. */
417-
+ /**
418-
+ * The publication date of this book.
419-
+ */
420-
#[ORM\Column]
397+
/** The publication date of this book. */
398+
+ #[ORM\Column(type: "datetime")]
421399
public ?\DateTimeInterface $publicationDate = null;
422400

423-
- /** @var Review[] Available reviews for this book. */
424-
+ /**
425-
+ * @var Review[] Available reviews for this book.
426-
+ */
427-
#[ORM\OneToMany(mappedBy: 'book', targetEntity: 'Review', cascade: ['persist', 'remove'])]
401+
/** @var Review[] Available reviews for this book. */
402+
+ #[ORM\OneToMany(mappedBy: 'book', targetEntity: 'Review', cascade: ['persist', 'remove'])]
428403
public iterable $reviews;
429404

430405
public function __construct()
@@ -438,54 +413,33 @@ Modify these files as described in these patches:
438413
use ApiPlatform\Core\Annotation\ApiResource;
439414
+use Doctrine\ORM\Mapping as ORM;
440415

441-
-/** A review of a book. */
442-
+/**
443-
+ * A review of a book.
444-
+ */
445-
#[ORM\Entity]
416+
/** A review of a book. */
417+
+#[ORM\Entity]
446418
#[ApiResource]
447419
class Review
448420
{
449-
- /** The id of this review. */
450-
+ /**
451-
+ * The id of this review.
452-
+ */
421+
/** The id of this review. */
453422
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
454423
private ?int $id = null;
455424

456-
- /** The rating of this review (between 0 and 5). */
457-
+ /**
458-
+ * The rating of this review (between 0 and 5).
459-
+ */
460-
#[ORM\Column(type: "smallint")]
425+
/** The rating of this review (between 0 and 5). */
426+
+ #[ORM\Column(type: "smallint")]
461427
public int $rating = 0;
462428

463-
- /** The body of the review. */
464-
+ /**
465-
+ * The body of the review.
466-
+ */
467-
#[ORM\Column(type: "text")]
429+
/** The body of the review. */
430+
+ #[ORM\Column(type: "text")]
468431
public string $body = '';
469432

470-
- /** The author of the review. */
471-
+ /**
472-
+ * The author of the review.
473-
+ */
474-
#[ORM\Column]
433+
/** The author of the review. */
434+
+ #[ORM\Column]
475435
public string $author = '';
476436

477-
- /** The date of publication of this review.*/
478-
+ /**
479-
+ * The date of publication of this review.
480-
+ */
481-
#[ORM\Column]
437+
/** The date of publication of this review.*/
438+
+ #[ORM\Column(type: "datetime")]
482439
public ?\DateTimeInterface $publicationDate = null;
483440

484-
- /** The book this review is about. */
485-
+ /**
486-
+ * The book this review is about.
487-
+ */
488-
#[ORM\ManyToOne(targetEntity: "Book", inversedBy: "reviews")]
441+
/** The book this review is about. */
442+
+ #[ORM\ManyToOne(targetEntity: "Book", inversedBy: "reviews")]
489443
public ?Book $book = null;
490444

491445
public function getId(): ?int

0 commit comments

Comments
 (0)