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

CreateController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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