Profile::setPhoneNumber()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace SDIS62\Core\User\Entity;
4
5
use libphonenumber\PhoneNumberUtil;
6
use libphonenumber\PhoneNumberFormat;
7
use SDIS62\Core\Common\Entity\IdentityTrait;
8
use SDIS62\Core\User\Exception\InvalidProfileException;
9
use SDIS62\Core\User\Exception\InvalidPhoneNumberException;
10
11
abstract class Profile
12
{
13
    use IdentityTrait;
14
15
    /**
16
     * Utilisateur associé au profil
17
     *
18
     * @var SDIS62\Core\User\Entity\User
19
     */
20
    protected $user;
21
22
    /**
23
     * Type du profil
24
     *
25
     * @var string
26
     */
27
    protected $phone_number;
28
29
    /*
30
    * Constructeur
31
    *
32
    * @param SDIS62\Core\User\Entity\User $user
33
    */
34 126
    public function __construct(User $user)
35
    {
36 126
        $this->user = $user;
0 ignored issues
show
Documentation Bug introduced by
It seems like $user of type object<SDIS62\Core\User\Entity\User> is incompatible with the declared type object<SDIS62\Core\User\...\Core\User\Entity\User> of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
38 126
        $user->addProfile($this);
39 126
    }
40
41
    /**
42
     * Get the value of Type du profil
43
     *
44
     * @return string
45
     */
46 15
    final public function getType()
47
    {
48 15
        if (empty($this->type)) {
0 ignored issues
show
Bug introduced by
The property type does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49 3
            throw new InvalidProfileException(get_class($this).' doit avoir un $type');
50
        }
51
52 12
        return $this->type;
53
    }
54
55
    /**
56
     * Get the value of Numéro de téléphone concernant le profil
57
     *
58
     * @return \DateTime|null
59
     */
60 3
    public function getPhoneNumber()
61
    {
62 3
        return $this->phone_number;
63
    }
64
65
    /**
66
     * Set the value of Numéro de téléphone concernant le profil
67
     *
68
     * @param string|null professional_phone_number
69
     * @throws InvalidPhoneNumberException
70
     *
71
     * @return self
72
     */
73 6
    public function setPhoneNumber($phone_number)
74
    {
75 6
        $phone_util = PhoneNumberUtil::getInstance();
76 6
        $phone_number_parsed = $phone_util->parse($phone_number, "FR");
77
78 6
        if (!$phone_util->isValidNumber($phone_number_parsed)) {
79 3
            throw new InvalidPhoneNumberException("Format du numéro de téléphone professionnel incorrect.");
80
        }
81
82 3
        $this->phone_number = $phone_util->format($phone_number_parsed, PhoneNumberFormat::NATIONAL);
83
84 3
        return $this;
85
    }
86
87
    /**
88
     * Get the value of Utilisateur associé au profil
89
     *
90
     * @return SDIS62\Core\User\Entity\User
91
     */
92 21
    public function getUser()
93
    {
94 21
        return $this->user;
95
    }
96
}
97