Skip to content

Commit

Permalink
fix: roles cannot be considered a list, because array_unique keeps th…
Browse files Browse the repository at this point in the history
…e previous keys
  • Loading branch information
Curryed committed Jan 14, 2025
1 parent 0624f13 commit d621686
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/Security/UserClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
)]
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Security/fixtures/expected/UserModelWithPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit d621686

Please sign in to comment.