Completed
Pull Request — master (#56)
by Vladimir
04:42
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
namespace Apple\ApnPush\Model;
6
7
/**
8
 * The type of the notification
9
 * @see https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
10
 */
11
final class PushType
12
{
13
    const TYPE_ALERT      = 'alert';
14
    const TYPE_BACKGROUND = 'background';
15
    
16
    private $value;
17
18
    public static function alert(): PushType
19
    {
20
        return new self(self::TYPE_ALERT);
21
    }
22
23
    public static function background(): PushType
24
    {
25
        return new self(self::TYPE_BACKGROUND);
26
    }
27
    
28
    public function __toString(): string
29
    {
30
        return $this->value;
31
    }
32
    
33
    /**
34
     * @param string $type
35
     * @throws \InvalidArgumentException
36
     */
37
    private function __construct(string $type)
38
    {
39
        if (!in_array($type, [self::TYPE_ALERT, self::TYPE_BACKGROUND], true)) {
40
            throw new \InvalidArgumentException(
41
                sprintf(
42
                    'Invalid priority "%d". Can be "%s" or "%s".',
43
                    $type,
44
                    self::TYPE_BACKGROUND,
45
                    self::TYPE_ALERT
46
                )
47
            );
48
        }
49
        
50
        $this->value = $type;
51
    }
52
}
53