From ad47205b67f1e638c37c8bca2ac1a285ca7cc898 Mon Sep 17 00:00:00 2001 From: Maelan LE BORGNE Date: Fri, 15 Dec 2023 11:19:13 +0100 Subject: [PATCH 1/2] Rebase --- src/Security/UserClassBuilder.php | 22 +++++++++++-------- .../UserEntityWithEmailAsIdentifier.php | 7 ++++++ .../expected/UserEntityWithPassword.php | 7 ++++++ ...rEntityWithUser_IdentifierAsIdentifier.php | 7 ++++++ .../expected/UserEntityWithoutPassword.php | 7 ++++++ .../UserModelWithEmailAsIdentifier.php | 7 ++++++ .../expected/UserModelWithPassword.php | 7 ++++++ .../expected/UserModelWithoutPassword.php | 7 ++++++ 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Security/UserClassBuilder.php b/src/Security/UserClassBuilder.php index ec6a7de09..ab224a57b 100644 --- a/src/Security/UserClassBuilder.php +++ b/src/Security/UserClassBuilder.php @@ -105,28 +105,32 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi // add normal property $manipulator->addProperty( name: 'roles', - defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]) + defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]), + comments: [ + '@var list The user roles', + ] ); $manipulator->addGetter( 'roles', 'array', - false - ); - - $manipulator->addSetter( - 'roles', - 'array', - false + false, ); } + $manipulator->addSetter( + 'roles', + 'array', + false, + ['@param list $roles'] + ); + // define getRoles (if it was defined above, this will override) $builder = $manipulator->createMethodBuilder( 'getRoles', 'array', false, - ['@see UserInterface'] + ['@see UserInterface', '@return list'] ); // $roles = $this->roles diff --git a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php index b51cd3138..722dd2507 100644 --- a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 180, unique: true)] private ?string $email = null; + /** + * @var list The user roles + */ #[ORM\Column] private array $roles = []; @@ -55,6 +58,7 @@ public function getUserIdentifier(): string /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -65,6 +69,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserEntityWithPassword.php b/tests/Security/fixtures/expected/UserEntityWithPassword.php index 345bed336..c2a0ca349 100644 --- a/tests/Security/fixtures/expected/UserEntityWithPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithPassword.php @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 180, unique: true)] private ?string $userIdentifier = null; + /** + * @var list The user roles + */ #[ORM\Column] private array $roles = []; @@ -50,6 +53,7 @@ public function setUserIdentifier(string $userIdentifier): static /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -60,6 +64,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php index 47a2e65b6..ae8333885 100644 --- a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php @@ -17,6 +17,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 180, unique: true)] private ?string $user_identifier = null; + /** + * @var list The user roles + */ #[ORM\Column] private array $roles = []; @@ -50,6 +53,7 @@ public function setUserIdentifier(string $user_identifier): static /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -60,6 +64,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php index fee8463ba..bd90ddb36 100644 --- a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php @@ -16,6 +16,9 @@ class User implements UserInterface #[ORM\Column(length: 180, unique: true)] private ?string $userIdentifier = null; + /** + * @var list The user roles + */ #[ORM\Column] private array $roles = []; @@ -43,6 +46,7 @@ public function setUserIdentifier(string $userIdentifier): static /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -53,6 +57,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php index 7c2761f79..062108367 100644 --- a/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php @@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { private $email; + /** + * @var list The user roles + */ private $roles = []; /** @@ -40,6 +43,7 @@ public function getUserIdentifier(): string /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -50,6 +54,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserModelWithPassword.php b/tests/Security/fixtures/expected/UserModelWithPassword.php index f734cebbf..6c4dcafc5 100644 --- a/tests/Security/fixtures/expected/UserModelWithPassword.php +++ b/tests/Security/fixtures/expected/UserModelWithPassword.php @@ -9,6 +9,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface { private $userIdentifier; + /** + * @var list The user roles + */ private $roles = []; /** @@ -35,6 +38,7 @@ public function setUserIdentifier(string $userIdentifier): static /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -45,6 +49,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/tests/Security/fixtures/expected/UserModelWithoutPassword.php b/tests/Security/fixtures/expected/UserModelWithoutPassword.php index 138df1763..355721786 100644 --- a/tests/Security/fixtures/expected/UserModelWithoutPassword.php +++ b/tests/Security/fixtures/expected/UserModelWithoutPassword.php @@ -8,6 +8,9 @@ class User implements UserInterface { private $userIdentifier; + /** + * @var list The user roles + */ private $roles = []; /** @@ -29,6 +32,7 @@ public function setUserIdentifier(string $userIdentifier): static /** * @see UserInterface + * @return list */ public function getRoles(): array { @@ -39,6 +43,9 @@ public function getRoles(): array return array_unique($roles); } + /** + * @param list $roles + */ public function setRoles(array $roles): static { $this->roles = $roles; From 01a334781ea345e59276eb32c69190a5771f5b85 Mon Sep 17 00:00:00 2001 From: Maelan LE BORGNE Date: Fri, 16 Feb 2024 14:15:50 +0100 Subject: [PATCH 2/2] Rebase --- src/Security/UserClassBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security/UserClassBuilder.php b/src/Security/UserClassBuilder.php index ab224a57b..8a1e9fa09 100644 --- a/src/Security/UserClassBuilder.php +++ b/src/Security/UserClassBuilder.php @@ -99,7 +99,7 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi if ($userClassConfig->isEntity()) { // add entity property $manipulator->addEntityField( - new ClassProperty(propertyName: 'roles', type: 'json') + new ClassProperty(propertyName: 'roles', type: 'json', comments: ['@var list The user roles']) ); } else { // add normal property