Passed
Branch master (4407aa)
by ANTHONIUS
03:52
created

CreateUserCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 1
rs 9.456
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "CreateUserCommand.php" doesn't match the expected filename "createusercommand.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\Command;
15
16
use Doyo\UserBundle\Manager\UserManagerInterface;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\Console\Question\Question;
23
24
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
 * @author Matthieu Bontemps <[email protected]>
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
26
 * @author Thibault Duplessis <[email protected]>
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
27
 * @author Luis Cordova <[email protected]>
0 ignored issues
show
Coding Style Documentation introduced by
@author tag is not allowed in class comment
Loading history...
28
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
29
class CreateUserCommand extends Command
30
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class CreateUserCommand
Loading history...
31
    protected static $defaultName = 'doyo:user:create';
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style introduced by
Protected member variable "defaultName" must contain a leading underscore
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @var UserManagerInterface
35
     */
36
    private $userManager;
0 ignored issues
show
Coding Style introduced by
Private member variable "userManager" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "userManager" must be prefixed with an underscore
Loading history...
37
38 2
    public function __construct(UserManagerInterface $userManager)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
39
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
40 2
        parent::__construct();
41
42 2
        $this->userManager = $userManager;
43
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
44
45
    /**
46
     * {@inheritdoc}
47
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
48 2
    protected function configure()
49
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
50
        $this
51 2
            ->setName('doyo:user:create')
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
52 2
            ->setDescription('Create a user.')
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
53 2
            ->setDefinition([
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
54 2
                new InputArgument('username', InputArgument::REQUIRED, 'The username'),
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 29 spaces, but found 16.
Loading history...
55 2
                new InputArgument('email', InputArgument::REQUIRED, 'The email'),
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 29 spaces, but found 16.
Loading history...
56 2
                new InputArgument('password', InputArgument::REQUIRED, 'The password'),
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 29 spaces, but found 16.
Loading history...
57 2
                new InputOption('super-admin', null, InputOption::VALUE_NONE, 'Set the user as super admin'),
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 29 spaces, but found 16.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 109 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58 2
                new InputOption('inactive', null, InputOption::VALUE_NONE, 'Set the user as inactive'),
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 29 spaces, but found 16.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 103 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
59
            ])
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 28 space(s), but found 12.
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
60 2
            ->setHelp(<<<'EOT'
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead
Loading history...
61 2
The <info>doyo:user:create</info> command creates a user:
62
63
  <info>php %command.full_name% matthieu</info>
64
65
This interactive shell will ask you for an email and then a password.
66
67
You can alternatively specify the email and password as the second and third arguments:
68
69
  <info>php %command.full_name% matthieu [email protected] mypassword</info>
70
71
You can create a super admin via the super-admin flag:
72
73
  <info>php %command.full_name% admin --super-admin</info>
74
75
You can create an inactive user (will not be able to log in):
76
77
  <info>php %command.full_name% thibault --inactive</info>
78
79
EOT
80
            );
81
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end configure()
Loading history...
82
83
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $input should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $output should have a doc-comment as per coding-style.
Loading history...
84
     * {@inheritdoc}
85
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
86 2
    protected function execute(InputInterface $input, OutputInterface $output)
87
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
88 2
        $username   = $input->getArgument('username');
89 2
        $email      = $input->getArgument('email');
90 2
        $password   = $input->getArgument('password');
91 2
        $inactive   = $input->getOption('inactive');
92 2
        $superadmin = $input->getOption('super-admin');
93 2
        $manager    = $this->userManager;
94 2
        $user       = $manager->createUser();
95
96 2
        $user->setUsername($username)
0 ignored issues
show
Bug introduced by
It seems like $username can also be of type string[]; however, parameter $username of Doyo\UserBundle\Model\UserInterface::setUsername() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
        $user->setUsername(/** @scrutinizer ignore-type */ $username)
Loading history...
97 2
            ->setPlainPassword($password)
0 ignored issues
show
Bug introduced by
It seems like $password can also be of type string[]; however, parameter $plainPassword of Doyo\UserBundle\Model\Us...ace::setPlainPassword() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
            ->setPlainPassword(/** @scrutinizer ignore-type */ $password)
Loading history...
Coding Style introduced by
Space found before object operator
Loading history...
98 2
            ->setEmail($email)
0 ignored issues
show
Bug introduced by
It seems like $email can also be of type string[]; however, parameter $email of Doyo\UserBundle\Model\UserInterface::setEmail() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
            ->setEmail(/** @scrutinizer ignore-type */ $email)
Loading history...
Coding Style introduced by
Space found before object operator
Loading history...
99 2
            ->setEnabled(!$inactive);
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
100
101 2
        if ($superadmin) {
102
            $user->addRole('ROLE_SUPER_ADMIN');
103
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
104 2
        $manager->updateUser($user);
105
106 2
        $output->writeln(sprintf('Created user <comment>%s</comment>', $username));
0 ignored issues
show
Bug introduced by
It seems like $username can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

106
        $output->writeln(sprintf('Created user <comment>%s</comment>', /** @scrutinizer ignore-type */ $username));
Loading history...
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end execute()
Loading history...
108
109
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $input should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $output should have a doc-comment as per coding-style.
Loading history...
110
     * {@inheritdoc}
111
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
112 1
    protected function interact(InputInterface $input, OutputInterface $output)
113
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
114 1
        $questions = [];
0 ignored issues
show
Coding Style introduced by
Short array syntax is not allowed
Loading history...
115
116 1
        if (!$input->getArgument('username')) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
117 1
            $question = new Question('Please choose a username:');
118
            $question->setValidator(function ($username) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
119
                if (empty($username)) {
120
                    throw new \Exception('Username can not be empty');
121
                }
122
123
                return $username;
124 1
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
125 1
            $questions['username'] = $question;
126
        }
127
128 1
        if (!$input->getArgument('email')) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
129 1
            $question = new Question('Please choose an email:');
130
            $question->setValidator(function ($email) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
131
                if (empty($email)) {
132
                    throw new \Exception('Email can not be empty');
133
                }
134
135
                return $email;
136 1
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
137 1
            $questions['email'] = $question;
138
        }
139
140 1
        if (!$input->getArgument('password')) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
141 1
            $question = new Question('Please choose a password:');
142
            $question->setValidator(function ($password) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
143
                if (empty($password)) {
144
                    throw new \Exception('Password can not be empty');
145
                }
146
147
                return $password;
148 1
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
149 1
            $question->setHidden(true);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
150 1
            $questions['password'] = $question;
151
        }
152
153 1
        foreach ($questions as $name => $question) {
154 1
            $answer = $this->getHelper('question')->ask($input, $output, $question);
155 1
            $input->setArgument($name, $answer);
156
        }
157
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end interact()
Loading history...
158
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
159