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

Priority::isNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
 * Message priority
18
 */
19
class Priority
20
{
21
    /**
22
     * @var int
23
     */
24
    private $value;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param int $priority
30
     *
31
     * @throws \InvalidArgumentException
32
     */
33
    public function __construct(int $priority)
34
    {
35
        if (!in_array($priority, [5, 10], true)) {
36
            throw new \InvalidArgumentException(sprintf(
37
                'Invalid priority "%d". Can be 5 or 10.',
38
                $priority
39
            ));
40
        }
41
42
        $this->value = $priority;
43
    }
44
45
    /**
46
     * Create immediately priority
47
     *
48
     * @return Priority
49
     */
50
    public static function immediately(): Priority
51
    {
52
        return new self(10);
53
    }
54
55
    /**
56
     * Create priority with power considerations
57
     *
58
     * @return Priority
59
     */
60
    public static function powerConsiderations(): Priority
61
    {
62
        return new self(5);
63
    }
64
65
    /**
66
     * Get value
67
     *
68
     * @return int
69
     */
70
    public function getValue(): int
71
    {
72
        return $this->value;
73
    }
74
}
75