Completed
Push — master ( c4b22f...ba9072 )
by Matze
08:46
created

CreateController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 38
loc 38
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A register() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace BrainExe\Core\Authentication\Controller;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\Annotations\Controller;
7
use BrainExe\Core\Annotations\Guest;
8
use BrainExe\Core\Annotations\Route;
9
use BrainExe\Core\Authentication\Register;
10
use BrainExe\Core\Authentication\UserVO;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * @Controller("Authentication.Controller.Create")
15
 */
16 View Code Duplication
class CreateController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
19
    /**
20
     * @var Register
21
     */
22
    private $register;
23
24
    /**
25
     * @Inject("@Register")
26
     * @param Register $register
27
     */
28
    public function __construct(Register $register)
29
    {
30
        $this->register = $register;
31
    }
32
33
    /**
34
     * @param Request $request
35
     * @return UserVO
36
     * @Route("/admin/", name="authenticate.doRegister", methods="POST")
37
     * @Guest
38
     */
39
    public function register(Request $request)
40
    {
41
        $username       = $request->request->get('username');
42
        $plainPassword  = $request->request->get('password');
43
        $token          = $request->cookies->get('token');
44
45
        $user           = new UserVO();
46
        $user->username = $username;
47
        $user->password = $plainPassword;
48
49
        $this->register->registerUser($user, $request->getSession(), $token);
0 ignored issues
show
Compatibility introduced by
$request->getSession() of type object<Symfony\Component...ssion\SessionInterface> is not a sub-type of object<Symfony\Component...dation\Session\Session>. It seems like you assume a concrete implementation of the interface Symfony\Component\HttpFo...ession\SessionInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
50
51
        return $user;
52
    }
53
}
54