Phone::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the SmsGate package
7
 *
8
 * (c) SmsGate
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace SmsGate;
15
16
use SmsGate\Exception\InvalidPhoneNumberException;
17
18
/**
19
 * The value object for store phone number
20
 *
21
 * @author Vitaliy Zhuk <[email protected]>
22
 */
23
class Phone
24
{
25
    /**
26
     * @var string
27
     */
28
    private $value;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param string $value
34
     *
35
     * @throws InvalidPhoneNumberException
36
     */
37 11
    public function __construct(string $value)
38
    {
39 11
        if (!preg_match('/^\d+$/', $value)) {
40 1
            throw new InvalidPhoneNumberException(sprintf(
41 1
                'Invalid phone number "%s".',
42 1
                $value
43
            ));
44
        }
45
46 10
        $this->value = $value;
47 10
    }
48
49
    /**
50
     * Get the value of phone
51
     *
52
     * @return string
53
     */
54 4
    public function getValue(): string
55
    {
56 4
        return $this->value;
57
    }
58
59
    /**
60
     * Implement __toString
61
     *
62
     * @return string
63
     */
64 3
    public function __toString(): string
65
    {
66 3
        return $this->value;
67
    }
68
}
69