Piou-piou /
RibsAdminBundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace PiouPiou\RibsAdminBundle\Command; |
||||
| 4 | |||||
| 5 | use Doctrine\ORM\EntityManagerInterface; |
||||
| 6 | use PiouPiou\RibsAdminBundle\Entity\Account; |
||||
| 7 | use PiouPiou\RibsAdminBundle\Entity\User; |
||||
| 8 | use Symfony\Component\Console\Command\Command; |
||||
| 9 | use Symfony\Component\Console\Input\InputArgument; |
||||
| 10 | use Symfony\Component\Console\Input\InputInterface; |
||||
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
||||
| 12 | use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
||||
| 13 | |||||
| 14 | class CreateAdminCommand extends Command |
||||
| 15 | { |
||||
| 16 | /** @var EntityManagerInterface */ |
||||
| 17 | private $em; |
||||
| 18 | |||||
| 19 | /** @var UserPasswordEncoderInterface */ |
||||
| 20 | private $passwordEncoder; |
||||
| 21 | |||||
| 22 | /** |
||||
| 23 | * CreateAdminCommand constructor. |
||||
| 24 | * @param EntityManagerInterface $em |
||||
| 25 | * @param UserPasswordEncoderInterface $passwordEncoder |
||||
| 26 | * @param string|null $name |
||||
| 27 | */ |
||||
| 28 | public function __construct(EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, string $name = null) |
||||
| 29 | { |
||||
| 30 | parent::__construct($name); |
||||
| 31 | $this->em = $em; |
||||
| 32 | $this->passwordEncoder = $passwordEncoder; |
||||
| 33 | } |
||||
| 34 | |||||
| 35 | protected function configure() |
||||
| 36 | { |
||||
| 37 | $this |
||||
| 38 | ->setName('ribsadmin:create-admin') |
||||
| 39 | ->setDescription('Create an admin in ribs admin') |
||||
| 40 | ->addArgument( |
||||
| 41 | 'firstname', |
||||
| 42 | InputArgument::REQUIRED, |
||||
| 43 | 'Firstname of admin to create' |
||||
| 44 | ) |
||||
| 45 | ->addArgument( |
||||
| 46 | 'lastname', |
||||
| 47 | InputArgument::REQUIRED, |
||||
| 48 | 'Lastname of admin to create' |
||||
| 49 | ) |
||||
| 50 | ->addArgument( |
||||
| 51 | 'email', |
||||
| 52 | InputArgument::REQUIRED, |
||||
| 53 | 'email of admin to create' |
||||
| 54 | ) |
||||
| 55 | ->addArgument( |
||||
| 56 | 'password', |
||||
| 57 | InputArgument::REQUIRED, |
||||
| 58 | 'password of admin to create' |
||||
| 59 | ) |
||||
| 60 | ; |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
| 64 | { |
||||
| 65 | $firstname = $input->getArgument('firstname'); |
||||
| 66 | $lastname = $input->getArgument('lastname'); |
||||
| 67 | $email = $input->getArgument('email'); |
||||
| 68 | $password = $input->getArgument('password'); |
||||
| 69 | |||||
| 70 | $output->writeln("Create admin " . $firstname . " " . $lastname); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
Are you sure
$lastname of type null|string|string[] can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | |||||
| 72 | $user = new User(); |
||||
| 73 | $user->setFirstname($firstname); |
||||
|
0 ignored issues
–
show
It seems like
$firstname can also be of type string[]; however, parameter $firstname of PiouPiou\RibsAdminBundle...ty\User::setFirstname() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 74 | $user->setLastname($lastname); |
||||
|
0 ignored issues
–
show
It seems like
$lastname can also be of type string[]; however, parameter $lastname of PiouPiou\RibsAdminBundle...ity\User::setLastname() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 75 | $user->setAccessRights("*"); |
||||
| 76 | $this->em->persist($user); |
||||
| 77 | |||||
| 78 | $account = new Account(); |
||||
| 79 | $temp_password = $this->passwordEncoder->encodePassword($account, $password); |
||||
|
0 ignored issues
–
show
It seems like
$password can also be of type null and string[]; however, parameter $plainPassword of Symfony\Component\Securi...rface::encodePassword() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 80 | $account->setPassword($temp_password); |
||||
| 81 | $account->setUser($user); |
||||
| 82 | $account->setEmail($email); |
||||
| 83 | $account->setUsername(substr($firstname, 0, 1).".".$lastname); |
||||
|
0 ignored issues
–
show
It seems like
$firstname can also be of type string[]; however, parameter $string of substr() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 84 | $this->em->persist($account); |
||||
| 85 | |||||
| 86 | $this->em->flush(); |
||||
| 87 | |||||
| 88 | $output->writeln("End Create admin " . $firstname . " " . $lastname); |
||||
| 89 | |||||
| 90 | return 0; |
||||
| 91 | } |
||||
| 92 | } |
||||
| 93 |