Completed
Push — master ( 62a450...2faef5 )
by
unknown
12s
created

AdminDataTransferObject::getEntity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkUserBundle\DataTransferObject;
4
5
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\BaseUserDataTransferObject;
6
use SumoCoders\FrameworkUserBundle\Entity\Admin;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9 View Code Duplication
final class AdminDataTransferObject extends BaseUserDataTransferObject
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...
10
{
11
    /**
12
     * @var string
13
     *
14
     * @Assert\NotBlank(message="forms.not_blank")
15
     */
16
    public $displayName;
17
18
    /**
19
     * @var string
20
     *
21
     * @Assert\NotBlank(message="forms.not_blank")
22
     * @Assert\Email(message="forms.invalid_email")
23
     */
24
    public $email;
25
26
    /**
27
     * @var string
28
     *
29
     * @Assert\NotBlank(message="forms.not_blank", groups={"add"})
30
     */
31
    public $plainPassword;
32
33
    /**
34
     * @var Admin
35
     */
36
    protected $user;
37
38
    public function getEntity(): Admin
39
    {
40
        if ($this->user) {
41
            $this->user->change($this);
42
43
            return $this->user;
44
        }
45
46
        return new Admin(
47
            $this->plainPassword,
48
            $this->displayName,
49
            $this->email
50
        );
51
    }
52
}
53