Completed
Push — master ( 2e845d...f1d84d )
by Derek Stephen
08:19
created

UserCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 45
ccs 0
cts 37
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 16 1
A execute() 0 15 2
1
<?php
2
3
namespace Del\Console;
4
5
use DateTime;
6
use Del\Common\ContainerService;
7
use Del\Criteria\UserCriteria;
8
use Del\Service\UserService;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class UserCommand extends Command
16
{
17
    /** @var UserService $userService */
18
    private $userService;
19
20
    public function __construct()
21
    {
22
        parent::__construct();
23
        $container = ContainerService::getInstance()->getContainer();
24
        $this->userService = $container['service.user'];
25
    }
26
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('reset-pass')
31
            ->setDescription('Resets a user\'s password')
32
            ->addArgument(
33
                'email',
34
                InputArgument::REQUIRED,
35
                'The email of the user'
36
            )->addArgument(
37
                'newPassword',
38
                InputArgument::REQUIRED,
39
                'The email of the user'
40
            )
41
        ;
42
    }
43
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $email = $input->getArgument('email');
47
        $pass = $input->getArgument('newPassword');
48
        $criteria = new UserCriteria();
49
        $criteria->setEmail($email);
50
        $user = $this->userService->findOneByCriteria($criteria);
51
        if ($user === null) {
52
            $output->writeln('No User Found.');
53
        } else {
54
            $this->userService->changePassword($user, $pass);
55
            $this->userService->saveUser($user);
56
            $output->writeln('Password changed for '.$email);
57
        }
58
    }
59
}
60