Test Setup Failed
Push — master ( 01683c...feea73 )
by Vitaliy
03:11
created

ApnId::fromId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the AppleApnPush package
7
 *
8
 * (c) Vitaliy Zhuk <[email protected]>
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 Apple\ApnPush\Model;
15
16
/**
17
 * UUID identifier for APN
18
 */
19 View Code Duplication
class ApnId
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * @var string
23
     */
24
    private $value;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param string $value
30
     *
31
     * @throws \InvalidArgumentException
32
     */
33
    public function __construct(string $value)
34
    {
35
        if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $value)) {
36
            throw new \InvalidArgumentException(sprintf(
37
                'Invalid UUID identifier "%s".',
38
                $value
39
            ));
40
        }
41
42
        $this->value = $value;
43
    }
44
45
    /**
46
     * Get value
47
     *
48
     * @return string
49
     *
50
     * @throws \LogicException
51
     */
52
    public function getValue(): string
53
    {
54
        return (string) $this->value;
55
    }
56
}
57