GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d4426a...04c02a )
by Boy
11:46 queued 08:30
created

InternationalPhoneNumber   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 8
c 4
b 2
f 1
lcom 1
cbo 4
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromStringFormat() 0 18 3
A toMSISDN() 0 4 1
A equals() 0 5 2
A __toString() 0 4 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupBundle\Value\PhoneNumber;
20
21
use Surfnet\StepupBundle\Exception\InvalidArgumentException;
22
use Surfnet\StepupBundle\Value\Exception\InvalidPhoneNumberFormatException;
23
24
class InternationalPhoneNumber
25
{
26
    /**
27
     * @var CountryCode
28
     */
29
    private $countryCode;
30
31
    /**
32
     * @var PhoneNumber
33
     */
34
    private $phoneNumber;
35
36
    public function __construct(CountryCode $countryCode, PhoneNumber $number)
37
    {
38
        $this->countryCode = $countryCode;
39
        $this->phoneNumber = $number;
40
    }
41
42
    /**
43
     * @param string $string a well formatted "+{CountryCode} (0) {PhoneNumber}" international phone number
44
     * @return InternationalPhoneNumber
45
     */
46
    public static function fromStringFormat($string)
47
    {
48
        if (!is_string($string)) {
49
            throw InvalidArgumentException::invalidType('string', 'string', $string);
50
        }
51
52
        if (!preg_match('~^\+([^\(]+)\(0\)\s{1}([\d]+)$~', $string, $matches)) {
53
            throw new InvalidPhoneNumberFormatException(
54
                'In order to create the phone number from string, it must have the format "+31 (0) 614696076", formal: '
55
                . '"+{CountryCode} (0) {PhoneNumber}"'
56
            );
57
        }
58
59
        $countryCode = str_replace(' ', '', $matches[1]);
60
        $phoneNumber = $matches[2];
61
62
        return new self(new CountryCode($countryCode), new PhoneNumber($phoneNumber));
63
    }
64
65
    /**
66
     * @see http://en.wikipedia.org/wiki/MSISDN#MSISDN_Format
67
     * @see https://www.messagebird.com/developers#messaging-send
68
     *
69
     * @return string
70
     */
71
    public function toMSISDN()
72
    {
73
        return $this->countryCode->getCountryCode() . $this->phoneNumber->formatAsMsisdnPart();
74
    }
75
76
    /**
77
     * @param InternationalPhoneNumber $other
78
     * @return bool
79
     */
80
    public function equals(InternationalPhoneNumber $other)
81
    {
82
        return $this->countryCode->equals($other->countryCode)
83
                && $this->phoneNumber->equals($other->phoneNumber);
84
    }
85
86
    public function __toString()
87
    {
88
        return $this->countryCode . ' ' . $this->phoneNumber;
89
    }
90
}
91