Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace libphonenumber;
6
 
7
class PhoneNumberMatch implements \Stringable
8
{
9
    /**
10
     * The start index into the text.
11
     */
12
    private int $start;
13
 
14
    /**
15
     * The raw substring matched.
16
     */
17
    private string $rawString;
18
 
19
    /**
20
     * Creates a new match
21
     *
22
     * @param int $start The start index into the target text
23
     * @param string $rawString The matched substring of the target text
24
     * @param PhoneNumber $number The matched phone number
25
     */
26
    public function __construct(int $start, string $rawString, private PhoneNumber $number)
27
    {
28
        if ($start < 0) {
29
            throw new \InvalidArgumentException('Start index must be >= 0.');
30
        }
31
 
32
        $this->start = $start;
33
        $this->rawString = $rawString;
34
    }
35
 
36
    /**
37
     * Returns the phone number matched by the receiver.
38
     */
39
    public function number(): PhoneNumber
40
    {
41
        return $this->number;
42
    }
43
 
44
    /**
45
     * Returns the start index of the matched phone number within the searched text.
46
     */
47
    public function start(): int
48
    {
49
        return $this->start;
50
    }
51
 
52
    /**
53
     * Returns the exclusive end index of the matched phone number within the searched text.
54
     */
55
    public function end(): int
56
    {
57
        return $this->start + \mb_strlen($this->rawString);
58
    }
59
 
60
    /**
61
     * Returns the raw string matched as a phone number in the searched text.
62
     */
63
    public function rawString(): string
64
    {
65
        return $this->rawString;
66
    }
67
 
68
    public function __toString(): string
69
    {
70
        return "PhoneNumberMatch [{$this->start()},{$this->end()}) {$this->rawString}";
71
    }
72
}