From 41d6cfda3c7d7743c24700c420b449f9027c8399 Mon Sep 17 00:00:00 2001 From: Norbert Boros Date: Fri, 20 Oct 2023 07:01:23 +0100 Subject: [PATCH 1/7] Using Doctrine LifecycleCallbacks for entities This is the modern solution to automatically update timestamps in Doctrine. I have added createdAt and updatedAt to all entities using LifecycleCallbacks. --- src/Entity/Comment.php | 48 +++++++++++++++++++++++++++++++++++++++- src/Entity/Post.php | 50 ++++++++++++++++++++++++++++++++++++++++-- src/Entity/Tag.php | 48 +++++++++++++++++++++++++++++++++++++++- src/Entity/User.php | 48 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 189 insertions(+), 5 deletions(-) diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index aa1b8e6bc..754962c7d 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -13,6 +13,9 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\HasLifecycleCallbacks; +use Doctrine\ORM\Mapping\PrePersist; +use Doctrine\ORM\Mapping\PreUpdate; use Symfony\Component\Validator\Constraints as Assert; use function Symfony\Component\String\u; @@ -25,8 +28,9 @@ * * @author Ryan Weaver * @author Javier Eguiluz + * @author Mecanik */ -#[ORM\Entity] +#[ORM\Entity, HasLifecycleCallbacks] #[ORM\Table(name: 'symfony_demo_comment')] class Comment { @@ -51,6 +55,12 @@ class Comment #[ORM\JoinColumn(nullable: false)] private ?User $author = null; + #[ORM\Column(type: 'datetime_immutable')] + private $createdAt; + + #[ORM\Column(type: 'datetime_immutable')] + private $updatedAt; + public function __construct() { $this->publishedAt = new \DateTime(); @@ -108,4 +118,40 @@ public function setPost(Post $post): void { $this->post = $post; } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeImmutable $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getUpdatedAt(): ?\DateTimeImmutable + { + return $this->updatedAt; + } + + public function setUpdatedAt(\DateTimeImmutable $updatedAt): self + { + $this->updatedAt = $updatedAt; + + return $this; + } + + #[PrePersist] + #[PreUpdate] + public function updatedTimestamps() + { + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } + if ($this->getCreatedAt() == null) { + $this->setCreatedAt(new \DateTimeImmutable('now')); + } + } } diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 8d1913697..cb289589a 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -16,6 +16,9 @@ use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\HasLifecycleCallbacks; +use Doctrine\ORM\Mapping\PrePersist; +use Doctrine\ORM\Mapping\PreUpdate; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -30,8 +33,9 @@ * @author Ryan Weaver * @author Javier Eguiluz * @author Yonel Ceruto + * @author Mecanik */ -#[ORM\Entity(repositoryClass: PostRepository::class)] +#[ORM\Entity(repositoryClass: PostRepository::class), HasLifecycleCallbacks] #[ORM\Table(name: 'symfony_demo_post')] #[UniqueEntity(fields: ['slug'], errorPath: 'title', message: 'post.slug_unique')] class Post @@ -64,7 +68,7 @@ class Post #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?User $author = null; - + /** * @var Collection */ @@ -81,6 +85,12 @@ class Post #[Assert\Count(max: 4, maxMessage: 'post.too_many_tags')] private Collection $tags; + #[ORM\Column(type: 'datetime_immutable')] + private $createdAt; + + #[ORM\Column(type: 'datetime_immutable')] + private $updatedAt; + public function __construct() { $this->publishedAt = new \DateTime(); @@ -195,4 +205,40 @@ public function getTags(): Collection { return $this->tags; } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeImmutable $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getUpdatedAt(): ?\DateTimeImmutable + { + return $this->updatedAt; + } + + public function setUpdatedAt(\DateTimeImmutable $updatedAt): self + { + $this->updatedAt = $updatedAt; + + return $this; + } + + #[PrePersist] + #[PreUpdate] + public function updatedTimestamps() + { + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } + if ($this->getCreatedAt() == null) { + $this->setCreatedAt(new \DateTimeImmutable('now')); + } + } } diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 0979290f4..47ee9026f 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -13,6 +13,9 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\HasLifecycleCallbacks; +use Doctrine\ORM\Mapping\PrePersist; +use Doctrine\ORM\Mapping\PreUpdate; /** * Defines the properties of the Tag entity to represent the post tags. @@ -20,8 +23,9 @@ * See https://symfony.com/doc/current/doctrine.html#creating-an-entity-class * * @author Yonel Ceruto + * @author Mecanik */ -#[ORM\Entity] +#[ORM\Entity, HasLifecycleCallbacks] #[ORM\Table(name: 'symfony_demo_tag')] class Tag implements \JsonSerializable { @@ -33,6 +37,12 @@ class Tag implements \JsonSerializable #[ORM\Column(type: Types::STRING, unique: true)] private readonly string $name; + #[ORM\Column(type: 'datetime_immutable')] + private $createdAt; + + #[ORM\Column(type: 'datetime_immutable')] + private $updatedAt; + public function __construct(string $name) { $this->name = $name; @@ -61,4 +71,40 @@ public function __toString(): string { return $this->name; } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeImmutable $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getUpdatedAt(): ?\DateTimeImmutable + { + return $this->updatedAt; + } + + public function setUpdatedAt(\DateTimeImmutable $updatedAt): self + { + $this->updatedAt = $updatedAt; + + return $this; + } + + #[PrePersist] + #[PreUpdate] + public function updatedTimestamps() + { + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } + if ($this->getCreatedAt() == null) { + $this->setCreatedAt(new \DateTimeImmutable('now')); + } + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 547ee659f..770446098 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -14,6 +14,9 @@ use App\Repository\UserRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\HasLifecycleCallbacks; +use Doctrine\ORM\Mapping\PrePersist; +use Doctrine\ORM\Mapping\PreUpdate; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -27,8 +30,9 @@ * * @author Ryan Weaver * @author Javier Eguiluz + * @author Mecanik */ -#[ORM\Entity(repositoryClass: UserRepository::class)] +#[ORM\Entity(repositoryClass: UserRepository::class), HasLifecycleCallbacks] #[ORM\Table(name: 'symfony_demo_user')] class User implements UserInterface, PasswordAuthenticatedUserInterface { @@ -59,6 +63,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: Types::STRING)] private ?string $password = null; + #[ORM\Column(type: 'datetime_immutable')] + private $createdAt; + + #[ORM\Column(type: 'datetime_immutable')] + private $updatedAt; + /** * @var string[] */ @@ -180,4 +190,40 @@ public function __unserialize(array $data): void // add $this->salt too if you don't use Bcrypt or Argon2i [$this->id, $this->username, $this->password] = $data; } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeImmutable $createdAt): self + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getUpdatedAt(): ?\DateTimeImmutable + { + return $this->updatedAt; + } + + public function setUpdatedAt(\DateTimeImmutable $updatedAt): self + { + $this->updatedAt = $updatedAt; + + return $this; + } + + #[PrePersist] + #[PreUpdate] + public function updatedTimestamps() + { + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } + if ($this->getCreatedAt() == null) { + $this->setCreatedAt(new \DateTimeImmutable('now')); + } + } } From 735ff5f90a43fc3019b76938c911e0b20a4ef83d Mon Sep 17 00:00:00 2001 From: Norbert Boros Date: Fri, 20 Oct 2023 07:07:39 +0100 Subject: [PATCH 2/7] Following official method of HasLifecycleCallbacks --- src/Entity/Comment.php | 3 ++- src/Entity/Post.php | 3 ++- src/Entity/Tag.php | 3 ++- src/Entity/User.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 754962c7d..3ef22cd86 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -30,8 +30,9 @@ * @author Javier Eguiluz * @author Mecanik */ -#[ORM\Entity, HasLifecycleCallbacks] +#[ORM\Entity] #[ORM\Table(name: 'symfony_demo_comment')] +#[HasLifecycleCallbacks] class Comment { #[ORM\Id] diff --git a/src/Entity/Post.php b/src/Entity/Post.php index cb289589a..c8d59b9ce 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -35,9 +35,10 @@ * @author Yonel Ceruto * @author Mecanik */ -#[ORM\Entity(repositoryClass: PostRepository::class), HasLifecycleCallbacks] +#[ORM\Entity(repositoryClass: PostRepository::class)] #[ORM\Table(name: 'symfony_demo_post')] #[UniqueEntity(fields: ['slug'], errorPath: 'title', message: 'post.slug_unique')] +#[HasLifecycleCallbacks] class Post { #[ORM\Id] diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 47ee9026f..a00cefee4 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -25,8 +25,9 @@ * @author Yonel Ceruto * @author Mecanik */ -#[ORM\Entity, HasLifecycleCallbacks] +#[ORM\Entity] #[ORM\Table(name: 'symfony_demo_tag')] +#[HasLifecycleCallbacks] class Tag implements \JsonSerializable { #[ORM\Id] diff --git a/src/Entity/User.php b/src/Entity/User.php index 770446098..ae0cb0554 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -32,8 +32,9 @@ * @author Javier Eguiluz * @author Mecanik */ -#[ORM\Entity(repositoryClass: UserRepository::class), HasLifecycleCallbacks] +#[ORM\Entity(repositoryClass: UserRepository::class)] #[ORM\Table(name: 'symfony_demo_user')] +#[HasLifecycleCallbacks] class User implements UserInterface, PasswordAuthenticatedUserInterface { // We can use constants for roles to find usages all over the application rather From f2be38cc61ad1b0d6efcece8f82b41fb05514321 Mon Sep 17 00:00:00 2001 From: Norbert Boros Date: Fri, 20 Oct 2023 12:33:56 +0100 Subject: [PATCH 3/7] Improved lifecycle logic --- src/Entity/Comment.php | 12 +++++++----- src/Entity/Post.php | 12 +++++++----- src/Entity/Tag.php | 12 +++++++----- src/Entity/User.php | 12 +++++++----- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 3ef22cd86..fd4f47529 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -145,14 +145,16 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self } #[PrePersist] - #[PreUpdate] - public function updatedTimestamps() + public function onPrePersist() { - if ($this->getUpdatedAt() == null) { - $this->setUpdatedAt(new \DateTimeImmutable('now')); - } if ($this->getCreatedAt() == null) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } + + #[PreUpdate] + public function onPreUpdate() + { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } } diff --git a/src/Entity/Post.php b/src/Entity/Post.php index c8d59b9ce..bf1892454 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -232,14 +232,16 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self } #[PrePersist] - #[PreUpdate] - public function updatedTimestamps() + public function onPrePersist() { - if ($this->getUpdatedAt() == null) { - $this->setUpdatedAt(new \DateTimeImmutable('now')); - } if ($this->getCreatedAt() == null) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } + + #[PreUpdate] + public function onPreUpdate() + { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } } diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index a00cefee4..fd240560b 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -98,14 +98,16 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self } #[PrePersist] - #[PreUpdate] - public function updatedTimestamps() + public function onPrePersist() { - if ($this->getUpdatedAt() == null) { - $this->setUpdatedAt(new \DateTimeImmutable('now')); - } if ($this->getCreatedAt() == null) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } + + #[PreUpdate] + public function onPreUpdate() + { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index ae0cb0554..fbf700952 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -217,14 +217,16 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self } #[PrePersist] - #[PreUpdate] - public function updatedTimestamps() + public function onPrePersist() { - if ($this->getUpdatedAt() == null) { - $this->setUpdatedAt(new \DateTimeImmutable('now')); - } if ($this->getCreatedAt() == null) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } + + #[PreUpdate] + public function onPreUpdate() + { + $this->setUpdatedAt(new \DateTimeImmutable('now')); + } } From eb99b8d1be164550f77d2b8c019a577cf7d81fd1 Mon Sep 17 00:00:00 2001 From: Mecanik Date: Sat, 21 Oct 2023 05:43:15 +0100 Subject: [PATCH 4/7] Executed PHP CS Fixer --- .gitignore | 5 + composer.json | 1 + composer.lock | 441 ++++++++++++++++++++++++++++++++++++++++- src/Entity/Comment.php | 16 +- src/Entity/Post.php | 18 +- src/Entity/Tag.php | 16 +- src/Entity/User.php | 16 +- symfony.lock | 12 ++ 8 files changed, 491 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 63425ae1d..89ec521e5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,8 @@ npm-debug.log yarn-error.log ###< symfony/webpack-encore-bundle ### + +###> friendsofphp/php-cs-fixer ### +/.php-cs-fixer.php +/.php-cs-fixer.cache +###< friendsofphp/php-cs-fixer ### diff --git a/composer.json b/composer.json index ae03112f8..a5a5a54ed 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "require-dev": { "dama/doctrine-test-bundle": "^7.0", "doctrine/doctrine-fixtures-bundle": "^3.4", + "friendsofphp/php-cs-fixer": "^3.35", "phpstan/extension-installer": "^1.2", "phpstan/phpstan": "^1.2", "phpstan/phpstan-doctrine": "^1.3", diff --git a/composer.lock b/composer.lock index 1db25d3fe..09fcf705d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "00722ce3778eecbdefc65a10ebf0bba7", + "content-hash": "3a4c068997ce5af6ba580cf804b4c946", "packages": [ { "name": "dflydev/dot-access-data", @@ -7835,6 +7835,224 @@ } ], "packages-dev": [ + { + "name": "composer/pcre", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.1.1" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-10-11T07:11:09+00:00" + }, + { + "name": "composer/semver", + "version": "3.4.0", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-08-31T09:50:34+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "ced299686f41dce890debac69273b47ffe98a40c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", + "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T21:32:43+00:00" + }, { "name": "dama/doctrine-test-bundle", "version": "v7.2.1", @@ -8067,6 +8285,99 @@ ], "time": "2023-05-02T15:12:16+00:00" }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v3.35.1", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", + "reference": "ec1ccc264994b6764882669973ca435cf05bab08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/ec1ccc264994b6764882669973ca435cf05bab08", + "reference": "ec1ccc264994b6764882669973ca435cf05bab08", + "shasum": "" + }, + "require": { + "composer/semver": "^3.3", + "composer/xdebug-handler": "^3.0.3", + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0", + "sebastian/diff": "^4.0 || ^5.0", + "symfony/console": "^5.4 || ^6.0", + "symfony/event-dispatcher": "^5.4 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0", + "symfony/finder": "^5.4 || ^6.0", + "symfony/options-resolver": "^5.4 || ^6.0", + "symfony/polyfill-mbstring": "^1.27", + "symfony/polyfill-php80": "^1.27", + "symfony/polyfill-php81": "^1.27", + "symfony/process": "^5.4 || ^6.0", + "symfony/stopwatch": "^5.4 || ^6.0" + }, + "require-dev": { + "facile-it/paraunit": "^1.3 || ^2.0", + "justinrainbow/json-schema": "^5.2", + "keradus/cli-executor": "^2.0", + "mikey179/vfsstream": "^1.6.11", + "php-coveralls/php-coveralls": "^2.5.3", + "php-cs-fixer/accessible-object": "^1.1", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", + "phpspec/prophecy": "^1.16", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "symfony/phpunit-bridge": "^6.2.3", + "symfony/yaml": "^5.4 || ^6.0" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "keywords": [ + "Static code analysis", + "fixer", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.35.1" + }, + "funding": [ + { + "url": "https://github.com/keradus", + "type": "github" + } + ], + "time": "2023-10-12T13:47:26+00:00" + }, { "name": "nikic/php-parser", "version": "v4.15.5", @@ -8370,6 +8681,73 @@ }, "time": "2023-05-16T12:46:15+00:00" }, + { + "name": "sebastian/diff", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-01T07:48:21+00:00" + }, { "name": "symfony/browser-kit", "version": "v6.3.0", @@ -8818,6 +9196,67 @@ ], "time": "2023-05-30T09:01:24+00:00" }, + { + "name": "symfony/process", + "version": "v6.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/0b5c29118f2e980d455d2e34a5659f4579847c54", + "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Executes commands in sub-processes", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/v6.3.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-08-07T10:39:22+00:00" + }, { "name": "symfony/web-profiler-bundle", "version": "v6.3.0", diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index fd4f47529..bfa2d38d2 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -61,7 +61,7 @@ class Comment #[ORM\Column(type: 'datetime_immutable')] private $updatedAt; - + public function __construct() { $this->publishedAt = new \DateTime(); @@ -119,8 +119,8 @@ public function setPost(Post $post): void { $this->post = $post; } - - public function getCreatedAt(): ?\DateTimeImmutable + + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } @@ -143,15 +143,15 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self return $this; } - - #[PrePersist] - public function onPrePersist() + + #[PrePersist] + public function onPrePersist() { - if ($this->getCreatedAt() == null) { + if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } - + #[PreUpdate] public function onPreUpdate() { diff --git a/src/Entity/Post.php b/src/Entity/Post.php index bf1892454..3998e4ebc 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -69,7 +69,7 @@ class Post #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?User $author = null; - + /** * @var Collection */ @@ -91,7 +91,7 @@ class Post #[ORM\Column(type: 'datetime_immutable')] private $updatedAt; - + public function __construct() { $this->publishedAt = new \DateTime(); @@ -206,8 +206,8 @@ public function getTags(): Collection { return $this->tags; } - - public function getCreatedAt(): ?\DateTimeImmutable + + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } @@ -230,15 +230,15 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self return $this; } - - #[PrePersist] - public function onPrePersist() + + #[PrePersist] + public function onPrePersist() { - if ($this->getCreatedAt() == null) { + if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } - + #[PreUpdate] public function onPreUpdate() { diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index fd240560b..69d82a024 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -43,7 +43,7 @@ class Tag implements \JsonSerializable #[ORM\Column(type: 'datetime_immutable')] private $updatedAt; - + public function __construct(string $name) { $this->name = $name; @@ -72,8 +72,8 @@ public function __toString(): string { return $this->name; } - - public function getCreatedAt(): ?\DateTimeImmutable + + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } @@ -96,15 +96,15 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self return $this; } - - #[PrePersist] - public function onPrePersist() + + #[PrePersist] + public function onPrePersist() { - if ($this->getCreatedAt() == null) { + if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } - + #[PreUpdate] public function onPreUpdate() { diff --git a/src/Entity/User.php b/src/Entity/User.php index fbf700952..30fd677b0 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -69,7 +69,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: 'datetime_immutable')] private $updatedAt; - + /** * @var string[] */ @@ -191,8 +191,8 @@ public function __unserialize(array $data): void // add $this->salt too if you don't use Bcrypt or Argon2i [$this->id, $this->username, $this->password] = $data; } - - public function getCreatedAt(): ?\DateTimeImmutable + + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } @@ -215,15 +215,15 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self return $this; } - - #[PrePersist] - public function onPrePersist() + + #[PrePersist] + public function onPrePersist() { - if ($this->getCreatedAt() == null) { + if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); } } - + #[PreUpdate] public function onPreUpdate() { diff --git a/symfony.lock b/symfony.lock index 2d80ba8dd..ce0eb944a 100644 --- a/symfony.lock +++ b/symfony.lock @@ -98,6 +98,18 @@ "egulias/email-validator": { "version": "3.1.2" }, + "friendsofphp/php-cs-fixer": { + "version": "3.35", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "3.0", + "ref": "be2103eb4a20942e28a6dd87736669b757132435" + }, + "files": [ + ".php-cs-fixer.dist.php" + ] + }, "friendsofphp/proxy-manager-lts": { "version": "v1.0.5" }, From 1682875f8a6cc5025b2bd8458b91174060d72fcd Mon Sep 17 00:00:00 2001 From: Mecanik Date: Mon, 23 Oct 2023 07:55:55 +0100 Subject: [PATCH 5/7] Use Types for property types, removed unwanted php-cs-fixer --- .gitignore | 5 - composer.json | 1 - composer.lock | 441 +---------------------------------------- src/Entity/Comment.php | 4 +- src/Entity/Post.php | 4 +- src/Entity/Tag.php | 4 +- src/Entity/User.php | 4 +- symfony.lock | 12 -- 8 files changed, 9 insertions(+), 466 deletions(-) diff --git a/.gitignore b/.gitignore index 89ec521e5..63425ae1d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,3 @@ npm-debug.log yarn-error.log ###< symfony/webpack-encore-bundle ### - -###> friendsofphp/php-cs-fixer ### -/.php-cs-fixer.php -/.php-cs-fixer.cache -###< friendsofphp/php-cs-fixer ### diff --git a/composer.json b/composer.json index a5a5a54ed..ae03112f8 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,6 @@ "require-dev": { "dama/doctrine-test-bundle": "^7.0", "doctrine/doctrine-fixtures-bundle": "^3.4", - "friendsofphp/php-cs-fixer": "^3.35", "phpstan/extension-installer": "^1.2", "phpstan/phpstan": "^1.2", "phpstan/phpstan-doctrine": "^1.3", diff --git a/composer.lock b/composer.lock index 09fcf705d..908769353 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3a4c068997ce5af6ba580cf804b4c946", + "content-hash": "a0eeb54dbd1af337628325e833d9d409", "packages": [ { "name": "dflydev/dot-access-data", @@ -7835,224 +7835,6 @@ } ], "packages-dev": [ - { - "name": "composer/pcre", - "version": "3.1.1", - "source": { - "type": "git", - "url": "https://github.com/composer/pcre.git", - "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", - "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.3", - "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Pcre\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "PCRE wrapping library that offers type-safe preg_* replacements.", - "keywords": [ - "PCRE", - "preg", - "regex", - "regular expression" - ], - "support": { - "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.1" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2023-10-11T07:11:09+00:00" - }, - { - "name": "composer/semver", - "version": "3.4.0", - "source": { - "type": "git", - "url": "https://github.com/composer/semver.git", - "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", - "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", - "shasum": "" - }, - "require": { - "php": "^5.3.2 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.4", - "symfony/phpunit-bridge": "^4.2 || ^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Semver\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nils Adermann", - "email": "naderman@naderman.de", - "homepage": "http://www.naderman.de" - }, - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - }, - { - "name": "Rob Bast", - "email": "rob.bast@gmail.com", - "homepage": "http://robbast.nl" - } - ], - "description": "Semver library that offers utilities, version constraint parsing and validation.", - "keywords": [ - "semantic", - "semver", - "validation", - "versioning" - ], - "support": { - "irc": "ircs://irc.libera.chat:6697/composer", - "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.4.0" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2023-08-31T09:50:34+00:00" - }, - { - "name": "composer/xdebug-handler", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/composer/xdebug-handler.git", - "reference": "ced299686f41dce890debac69273b47ffe98a40c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", - "reference": "ced299686f41dce890debac69273b47ffe98a40c", - "shasum": "" - }, - "require": { - "composer/pcre": "^1 || ^2 || ^3", - "php": "^7.2.5 || ^8.0", - "psr/log": "^1 || ^2 || ^3" - }, - "require-dev": { - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Composer\\XdebugHandler\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "John Stevenson", - "email": "john-stevenson@blueyonder.co.uk" - } - ], - "description": "Restarts a process without Xdebug.", - "keywords": [ - "Xdebug", - "performance" - ], - "support": { - "irc": "irc://irc.freenode.org/composer", - "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2022-02-25T21:32:43+00:00" - }, { "name": "dama/doctrine-test-bundle", "version": "v7.2.1", @@ -8285,99 +8067,6 @@ ], "time": "2023-05-02T15:12:16+00:00" }, - { - "name": "friendsofphp/php-cs-fixer", - "version": "v3.35.1", - "source": { - "type": "git", - "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "ec1ccc264994b6764882669973ca435cf05bab08" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/ec1ccc264994b6764882669973ca435cf05bab08", - "reference": "ec1ccc264994b6764882669973ca435cf05bab08", - "shasum": "" - }, - "require": { - "composer/semver": "^3.3", - "composer/xdebug-handler": "^3.0.3", - "ext-json": "*", - "ext-tokenizer": "*", - "php": "^7.4 || ^8.0", - "sebastian/diff": "^4.0 || ^5.0", - "symfony/console": "^5.4 || ^6.0", - "symfony/event-dispatcher": "^5.4 || ^6.0", - "symfony/filesystem": "^5.4 || ^6.0", - "symfony/finder": "^5.4 || ^6.0", - "symfony/options-resolver": "^5.4 || ^6.0", - "symfony/polyfill-mbstring": "^1.27", - "symfony/polyfill-php80": "^1.27", - "symfony/polyfill-php81": "^1.27", - "symfony/process": "^5.4 || ^6.0", - "symfony/stopwatch": "^5.4 || ^6.0" - }, - "require-dev": { - "facile-it/paraunit": "^1.3 || ^2.0", - "justinrainbow/json-schema": "^5.2", - "keradus/cli-executor": "^2.0", - "mikey179/vfsstream": "^1.6.11", - "php-coveralls/php-coveralls": "^2.5.3", - "php-cs-fixer/accessible-object": "^1.1", - "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", - "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", - "phpspec/prophecy": "^1.16", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5", - "symfony/phpunit-bridge": "^6.2.3", - "symfony/yaml": "^5.4 || ^6.0" - }, - "suggest": { - "ext-dom": "For handling output formats in XML", - "ext-mbstring": "For handling non-UTF8 characters." - }, - "bin": [ - "php-cs-fixer" - ], - "type": "application", - "autoload": { - "psr-4": { - "PhpCsFixer\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Dariusz Rumiński", - "email": "dariusz.ruminski@gmail.com" - } - ], - "description": "A tool to automatically fix PHP code style", - "keywords": [ - "Static code analysis", - "fixer", - "standards", - "static analysis" - ], - "support": { - "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.35.1" - }, - "funding": [ - { - "url": "https://github.com/keradus", - "type": "github" - } - ], - "time": "2023-10-12T13:47:26+00:00" - }, { "name": "nikic/php-parser", "version": "v4.15.5", @@ -8681,73 +8370,6 @@ }, "time": "2023-05-16T12:46:15+00:00" }, - { - "name": "sebastian/diff", - "version": "5.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0", - "symfony/process": "^4.2 || ^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff", - "udiff", - "unidiff", - "unified diff" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/diff/issues", - "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-05-01T07:48:21+00:00" - }, { "name": "symfony/browser-kit", "version": "v6.3.0", @@ -9196,67 +8818,6 @@ ], "time": "2023-05-30T09:01:24+00:00" }, - { - "name": "symfony/process", - "version": "v6.3.4", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/0b5c29118f2e980d455d2e34a5659f4579847c54", - "reference": "0b5c29118f2e980d455d2e34a5659f4579847c54", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Executes commands in sub-processes", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/process/tree/v6.3.4" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-08-07T10:39:22+00:00" - }, { "name": "symfony/web-profiler-bundle", "version": "v6.3.0", diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index bfa2d38d2..2e40154cc 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -56,10 +56,10 @@ class Comment #[ORM\JoinColumn(nullable: false)] private ?User $author = null; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $updatedAt; public function __construct() diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 3998e4ebc..64e3a5ebb 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -86,10 +86,10 @@ class Post #[Assert\Count(max: 4, maxMessage: 'post.too_many_tags')] private Collection $tags; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $updatedAt; public function __construct() diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 69d82a024..1a8175df1 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -38,10 +38,10 @@ class Tag implements \JsonSerializable #[ORM\Column(type: Types::STRING, unique: true)] private readonly string $name; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $updatedAt; public function __construct(string $name) diff --git a/src/Entity/User.php b/src/Entity/User.php index 30fd677b0..58aab5158 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -64,10 +64,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: Types::STRING)] private ?string $password = null; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: 'datetime_immutable')] + #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] private $updatedAt; /** diff --git a/symfony.lock b/symfony.lock index ce0eb944a..2d80ba8dd 100644 --- a/symfony.lock +++ b/symfony.lock @@ -98,18 +98,6 @@ "egulias/email-validator": { "version": "3.1.2" }, - "friendsofphp/php-cs-fixer": { - "version": "3.35", - "recipe": { - "repo": "github.com/symfony/recipes", - "branch": "main", - "version": "3.0", - "ref": "be2103eb4a20942e28a6dd87736669b757132435" - }, - "files": [ - ".php-cs-fixer.dist.php" - ] - }, "friendsofphp/proxy-manager-lts": { "version": "v1.0.5" }, From 2e28d192bdd3e5461967930cee42e6db527c73df Mon Sep 17 00:00:00 2001 From: Mecanik Date: Mon, 23 Oct 2023 08:49:03 +0100 Subject: [PATCH 6/7] Improved PrePersist for timestamps --- src/Entity/Comment.php | 4 ++++ src/Entity/Post.php | 4 ++++ src/Entity/Tag.php | 4 ++++ src/Entity/User.php | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 2e40154cc..467adca6f 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -149,6 +149,10 @@ public function onPrePersist() { if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); + } + + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); } } diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 64e3a5ebb..0bf8a9f6c 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -236,6 +236,10 @@ public function onPrePersist() { if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); + } + + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); } } diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 1a8175df1..712ac867d 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -102,6 +102,10 @@ public function onPrePersist() { if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); + } + + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 58aab5158..4624b1dba 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -221,6 +221,10 @@ public function onPrePersist() { if (null === $this->getCreatedAt()) { $this->setCreatedAt(new \DateTimeImmutable('now')); + } + + if ($this->getUpdatedAt() == null) { + $this->setUpdatedAt(new \DateTimeImmutable('now')); } } From b88a058ea8eabeb31f2d579a0b6cd6319991abc0 Mon Sep 17 00:00:00 2001 From: Mecanik Date: Tue, 24 Oct 2023 06:35:32 +0100 Subject: [PATCH 7/7] No timezone-aware fields... --- src/Entity/Comment.php | 4 ++-- src/Entity/Post.php | 4 ++-- src/Entity/Tag.php | 4 ++-- src/Entity/User.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Entity/Comment.php b/src/Entity/Comment.php index 467adca6f..a69e6cc09 100644 --- a/src/Entity/Comment.php +++ b/src/Entity/Comment.php @@ -56,10 +56,10 @@ class Comment #[ORM\JoinColumn(nullable: false)] private ?User $author = null; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $updatedAt; public function __construct() diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 0bf8a9f6c..32912cbb8 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -86,10 +86,10 @@ class Post #[Assert\Count(max: 4, maxMessage: 'post.too_many_tags')] private Collection $tags; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $updatedAt; public function __construct() diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index 712ac867d..0b2918f19 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -38,10 +38,10 @@ class Tag implements \JsonSerializable #[ORM\Column(type: Types::STRING, unique: true)] private readonly string $name; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $updatedAt; public function __construct(string $name) diff --git a/src/Entity/User.php b/src/Entity/User.php index 4624b1dba..a471af3ac 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -64,10 +64,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: Types::STRING)] private ?string $password = null; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $createdAt; - #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)] + #[ORM\Column(type: Types::DATETIMET_IMMUTABLE)] private $updatedAt; /**