Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| UserAdminCommand | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRoles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setRole | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Command; |
| 6 | |
| 7 | use BackedEnum; |
| 8 | use App\Entity\User; |
| 9 | use App\Enum\UserRole; |
| 10 | use App\Repository\UserRepository; |
| 11 | use Doctrine\ORM\EntityManagerInterface; |
| 12 | use Elkuku\SymfonyUtils\Command\UserAdminBaseCommand; |
| 13 | use Symfony\Component\Console\Attribute\AsCommand; |
| 14 | use Symfony\Component\Security\Core\User\UserInterface; |
| 15 | |
| 16 | #[AsCommand( |
| 17 | name: 'user-admin', |
| 18 | description: 'Administer user accounts', |
| 19 | aliases: ['useradmin', 'admin'] |
| 20 | )] |
| 21 | class UserAdminCommand extends UserAdminBaseCommand |
| 22 | { |
| 23 | public function __construct( |
| 24 | EntityManagerInterface $entityManager, |
| 25 | UserRepository $userRepository, |
| 26 | ) |
| 27 | { |
| 28 | parent::__construct($entityManager, $userRepository); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @return array<BackedEnum> |
| 33 | */ |
| 34 | protected function getRoles(): array |
| 35 | { |
| 36 | return UserRole::cases(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param User $user |
| 41 | */ |
| 42 | protected function setRole(UserInterface $user, string $role): User |
| 43 | { |
| 44 | return $user->setRole(UserRole::from($role)); |
| 45 | } |
| 46 | } |