Completed
Push — master ( bbd5c2...15f243 )
by Derek Stephen
01:52
created

UserCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 57
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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
    /**
21
     * UserCommand constructor.
22
     * @throws \Doctrine\ORM\ORMException
23
     */
24 2
    public function __construct(UserService $userService)
25
    {
26 2
        parent::__construct();
27 2
        $this->userService = $userService;
28 2
    }
29
30
    /**
31
     *
32
     */
33 2
    protected function configure()
34
    {
35
        $this
36 2
            ->setName('reset-pass')
37 2
            ->setDescription('Resets a user\'s password')
38 2
            ->addArgument(
39 2
                'email',
40 2
                InputArgument::REQUIRED,
41 2
                'The email of the user'
42 2
            )->addArgument(
43 2
                'newPassword',
44 2
                InputArgument::REQUIRED,
45 2
                'The email of the user'
46
            )
47
        ;
48 2
    }
49
50
    /**
51
     * @param InputInterface $input
52
     * @param OutputInterface $output
53
     * @return int|void|null
54
     * @throws \Doctrine\ORM\OptimisticLockException
55
     */
56 2
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58 2
        $email = $input->getArgument('email');
59 2
        $pass = $input->getArgument('newPassword');
60 2
        $criteria = new UserCriteria();
61 2
        $criteria->setEmail($email);
0 ignored issues
show
Bug introduced by
It seems like $email defined by $input->getArgument('email') on line 58 can also be of type array<integer,string> or null; however, Del\Criteria\UserCriteria::setEmail() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
62 2
        $user = $this->userService->findOneByCriteria($criteria);
63 2
        if ($user === null) {
64 1
            $output->writeln('No User Found.');
65
        } else {
66 1
            $this->userService->changePassword($user, $pass);
0 ignored issues
show
Bug introduced by
It seems like $pass defined by $input->getArgument('newPassword') on line 59 can also be of type array<integer,string> or null; however, Del\Service\UserService::changePassword() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67 1
            $this->userService->saveUser($user);
68 1
            $output->writeln('Password changed for '.$email);
69
        }
70 2
    }
71
}
72