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

Priority   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A immediately() 0 4 1
A powerConsiderations() 0 4 1
A getValue() 0 4 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
 * 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