Completed
Pull Request — master (#13)
by Benjamin
06:13
created

PromoteCoachCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 18
c 2
b 1
f 0
dl 0
loc 25
ccs 0
cts 14
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 18 3
1
<?php
2
3
namespace Obblm\Core\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Obblm\Core\Entity\Coach;
7
use Obblm\Core\Event\RegisterCoachEvent;
8
use Obblm\Core\Security\Roles;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
class PromoteCoachCommand extends AbstractAdminCommand
15
{
16
    /** @var string */
17
    protected static $defaultName = 'obblm:coach:promote';
18
    protected static $description = 'Promotes an existing user to OBBLM Administrator.';
19
    protected static $help = 'This command will promote an existing user to the administrator role.';
20
21
    protected function execute(InputInterface $input, OutputInterface $output)
22
    {
23
        parent::execute($input, $output);
24
        $this->io->title('Promote a new OBBLM Administrator');
25
        $this->io->caution('Be carefull, this new user will have the highest right on the application');
26
        if ($this->confirmContinue()) {
27
            $coach = $this->getCoachByLoginOrEmail();
28
            $continue = $this->io->confirm("Are you sure you want to promote {$coach->getUsername()} ?", true);
29
            if ($continue) {
30
                $coach
31
                    ->setRoles([Roles::ADMIN]);
32
                $this->saveCoach($coach);
33
                $this->io->success("The coach {$coach->getUsername()} has been promoted !");
34
                return 1;
35
            }
36
        }
37
        $this->io->text('Aborted.');
38
        return 0;
39
    }
40
}
41