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