Skip to content

Commit bb98fa8

Browse files
committed
Added doctrine mappings and minor improvements inside phone
1 parent 6df80ba commit bb98fa8

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/LIN3S/SharedKernel/Domain/Model/Phone.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,33 @@ class Phone
2020

2121
public function __construct($phone)
2222
{
23-
$this->phone = $phone ? $this->cleanPhone($phone) : '';
23+
$this->phone = $this->setPhone($phone);
24+
}
25+
26+
public function phone()
27+
{
28+
return $this->phone;
2429
}
2530

2631
public function equals(Phone $phone)
2732
{
28-
return strtolower((string)$this) === strtolower((string)$phone);
33+
return $this->phone === $phone->phone();
2934
}
3035

3136
public function __toString()
3237
{
3338
return (string)$this->phone;
3439
}
3540

36-
private function cleanPhone($phone)
41+
private function setPhone($phone)
3742
{
38-
$absolute = $phone[0] === '+';
43+
$phone = str_replace('+34', '', $phone);
3944
$numbers = preg_replace('/\D/', '', $phone);
4045

4146
if (!$numbers) {
4247
throw new PhoneFormatInvalidException();
4348
}
4449

45-
// special logic for russian local phone notation
46-
if ($numbers[0] === '8' && !$absolute && strlen($numbers) == 11) {
47-
$numbers[0] = '7';
48-
}
49-
50-
if ($numbers[0] !== '7' || strlen($numbers) != 11) {
51-
throw new PhoneFormatInvalidException();
52-
}
53-
5450
return $numbers;
5551
}
5652
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
5+
http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
6+
7+
<embeddable name="LIN3S\SharedKernel\Domain\Model\Email">
8+
<field name="email" type="string" length="255" nullable="false"/>
9+
</embeddable>
10+
</doctrine-mapping>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
5+
http://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
6+
7+
<embeddable name="LIN3S\SharedKernel\Domain\Model\Phone">
8+
<field name="phone" type="string" length="20" nullable="false"/>
9+
</embeddable>
10+
</doctrine-mapping>

0 commit comments

Comments
 (0)