SMSRecipient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validateNumber() 0 6 2
A __toString() 0 4 1
1
<?php
2
3
namespace Spitoglou\SMS;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class SMSRecipient
9
 *
10
 * The recipient's Value Object
11
 * @package Spitoglou\SMS
12
 */
13
class SMSRecipient
14
{
15
    protected $number;
16
17
    /**
18
     * SMSRecipient constructor.
19
     *
20
     * Gets the recipient's phone number and validates
21
     * @param string $number
22
     */
23
    public function __construct($number = '')
24
    {
25
        $this->number = $number;
26
        $this->validateNumber();
27
    }
28
29
    /**
30
     * Validates that the recipient's phone number is 12 digits long (as required by the service)
31
     *
32
     * @throws \InvalidArgumentException
33
     */
34
    protected function validateNumber()
35
    {
36
        if (strlen($this->number) !== 12) {
37
            throw new InvalidArgumentException('The number provided is not exactly 12 chars long');
38
        }
39
    }
40
41
    /**
42
     * __toString
43
     * @return string
44
     */
45
    public function __toString()
46
    {
47
        return $this->number;
48
    }
49
}