Completed
Pull Request — master (#56)
by Vladimir
01:39
created

PushType::background()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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
 * The type of the notification
18
 * @see https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
19
 */
20
final class PushType
21
{
22
    const TYPE_ALERT      = 'alert';
23
    const TYPE_BACKGROUND = 'background';
24
25
    private $value;
26
27
    /**
28
     * Create alert push-type
29
     *
30
     * @return PushType
31
     */
32
    public static function alert(): PushType
33
    {
34
        return new self(self::TYPE_ALERT);
35
    }
36
37
    /**
38
     * Create background push-type
39
     *
40
     * @return PushType
41
     */
42
    public static function background(): PushType
43
    {
44
        return new self(self::TYPE_BACKGROUND);
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function __toString(): string
51
    {
52
        return $this->value;
53
    }
54
55
    /**
56
     * @param string $type
57
     *
58
     * @throws \InvalidArgumentException
59
     */
60
    private function __construct(string $type)
61
    {
62
        if (!in_array($type, [self::TYPE_ALERT, self::TYPE_BACKGROUND], true)) {
63
            throw new \InvalidArgumentException(
64
                sprintf(
65
                    'Invalid priority "%d". Can be "%s" or "%s".',
66
                    $type,
67
                    self::TYPE_BACKGROUND,
68
                    self::TYPE_ALERT
69
                )
70
            );
71
        }
72
73
        $this->value = $type;
74
    }
75
}
76