Completed
Push — master ( 31741c...acf815 )
by Benjamin
11:01 queued 06:10
created

RevokeCoachCommand::execute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 15
c 2
b 1
f 0
dl 0
loc 22
ccs 0
cts 15
cp 0
rs 9.7666
cc 4
nc 4
nop 2
crap 20
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
            $coach = $this->getCoachByLoginOrEmail();
29
30
            $continue = $this->io->confirm("Are you sure you want to revoke {$coach->getUsername()} ?", true);
31
            if ($continue) {
32
                if (in_array(Roles::ADMIN, $coach->getRoles())) {
33
                    $coach
34
                        ->setRoles([Roles::COACH]);
35
                    $this->saveCoach($coach);
36
                }
37
                $this->io->success("The coach {$coach->getUsername()} has been revoked !");
38
                return 1;
39
            }
40
        }
41
        $this->io->text('Aborted.');
42
        return 0;
43
    }
44
}
45