From d6216860be0f1cc5243824794725ecaa4bd32090 Mon Sep 17 00:00:00 2001 From: Nerea Enrique Date: Tue, 14 Jan 2025 11:05:37 +0100 Subject: [PATCH] fix: roles cannot be considered a list, because array_unique keeps the previous keys --- src/Security/UserClassBuilder.php | 9 ++++++--- .../expected/UserEntityWithEmailAsIdentifier.php | 2 +- .../fixtures/expected/UserEntityWithPassword.php | 2 +- .../UserEntityWithUser_IdentifierAsIdentifier.php | 2 +- .../fixtures/expected/UserEntityWithoutPassword.php | 2 +- .../fixtures/expected/UserModelWithEmailAsIdentifier.php | 2 +- .../Security/fixtures/expected/UserModelWithPassword.php | 2 +- .../fixtures/expected/UserModelWithoutPassword.php | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Security/UserClassBuilder.php b/src/Security/UserClassBuilder.php index e99af57dc..99b3290f2 100644 --- a/src/Security/UserClassBuilder.php +++ b/src/Security/UserClassBuilder.php @@ -160,12 +160,15 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi ) ); $builder->addStmt($manipulator->createMethodLevelBlankLine()); - // return array_unique($roles); + // return array_values(array_unique($roles)); $builder->addStmt( new Node\Stmt\Return_( new Node\Expr\FuncCall( - new Node\Name('array_unique'), - [new Node\Expr\Variable('roles')] + new Node\Name('array_values'), + [new Node\Expr\FuncCall( + new Node\Name('array_unique'), + [new Node\Expr\Variable('roles')] + )] ) ) ); diff --git a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php index d053ec604..f238ab994 100644 --- a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php @@ -67,7 +67,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserEntityWithPassword.php b/tests/Security/fixtures/expected/UserEntityWithPassword.php index ae4158d56..fd68742c8 100644 --- a/tests/Security/fixtures/expected/UserEntityWithPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithPassword.php @@ -62,7 +62,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php index 709982a4a..9d395556b 100644 --- a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php @@ -62,7 +62,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php index a1deca0f6..a8ac03d7e 100644 --- a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php @@ -55,7 +55,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php index d08e3b66e..8322b29bd 100644 --- a/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserModelWithEmailAsIdentifier.php @@ -51,7 +51,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserModelWithPassword.php b/tests/Security/fixtures/expected/UserModelWithPassword.php index fd2e86898..1d56d630c 100644 --- a/tests/Security/fixtures/expected/UserModelWithPassword.php +++ b/tests/Security/fixtures/expected/UserModelWithPassword.php @@ -46,7 +46,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /** diff --git a/tests/Security/fixtures/expected/UserModelWithoutPassword.php b/tests/Security/fixtures/expected/UserModelWithoutPassword.php index 355721786..6127c8df3 100644 --- a/tests/Security/fixtures/expected/UserModelWithoutPassword.php +++ b/tests/Security/fixtures/expected/UserModelWithoutPassword.php @@ -40,7 +40,7 @@ public function getRoles(): array // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; - return array_unique($roles); + return array_values(array_unique($roles)); } /**