Completed
Branch v1.x-dev (6fcd50)
by Benjamin
04:47
created

RevokeCoachCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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 RevokeCoachCommand extends AbstractAdminCommand
15
{
16
    /** @var string */
17
    protected static $defaultName = 'obblm:coach:revoke';
18
    protected static $description = 'Remoke the administrator role to an existing user.';
19
    protected static $help = 'This command will revoke the administrator role of an existing user.';
20
21
    protected function execute(InputInterface $input, OutputInterface $output)
22
    {
23
        parent::execute($input, $output);
24
25
        $this->io->title('Revoke an OBBLM Administrator');
26
        $this->io->caution('Be carefull, this new user will not have anymore the highest right on the application');
27
        if($this->confirmContinue()) {
28
29
            $coach = $this->getCoachByLoginOrEmail();
30
31
            $continue = $this->io->confirm("Are you sure you want to revoke {$coach->getUsername()} ?", true);
32
            if($continue) {
33
                if(in_array(Roles::ADMIN, $coach->getRoles())) {
34
                    $coach
35
                        ->setRoles([Roles::COACH]);
36
                    $this->saveCoach($coach);
37
                }
38
                $this->io->success("The coach {$coach->getUsername()} has been revoked !");
39
                return 1;
40
            }
41
        }
42
        $this->io->text('Aborted.');
43
        return 0;
44
    }
45
}
46