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

PasswordUpdater::hashPassword()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 3
rs 9.8666
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 "PasswordUpdater.php" doesn't match the expected filename "passwordupdater.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\Util;
15
16
use Doyo\UserBundle\Model\UserInterface;
17
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
18
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
19
20
class PasswordUpdater implements PasswordUpdaterInterface
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class PasswordUpdater
Loading history...
21
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class PasswordUpdater
Loading history...
22
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
     * @var EncoderFactoryInterface
24
     */
25
    private $encoderFactory;
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
Private member variable "encoderFactory" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "encoderFactory" must be prefixed with an underscore
Loading history...
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $encoderFactory should have a doc-comment as per coding-style.
Loading history...
28
     * PasswordUpdater constructor.
29
     */
30 4
    public function __construct(EncoderFactoryInterface $encoderFactory)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
31
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
32 4
        $this->encoderFactory = $encoderFactory;
33
    }
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...
34
35 7
    public function hashPassword(UserInterface $user)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function hashPassword()
Loading history...
36
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
37 7
        $plainPassword = $user->getPlainPassword();
38 7
        if (0 === \strlen($plainPassword)) {
39 1
            return;
40
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
41 6
        $encoder = $this->encoderFactory->getEncoder($user);
42 6
        if ($encoder instanceof BCryptPasswordEncoder) {
43 5
            $user->setSalt(null);
0 ignored issues
show
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...
44
        } else {
45 1
            $salt = rtrim(str_replace('+', '.', base64_encode(random_bytes(32))), '=');
46 1
            $user->setSalt($salt);
47
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
48 6
        $hashedPassword = $encoder->encodePassword($plainPassword, $user->getSalt());
49 6
        $user->setPassword($hashedPassword);
50 6
        $user->eraseCredentials();
51
    }
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 hashPassword()
Loading history...
52
}
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...
53