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

PushType   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 alert() 0 4 1
A background() 0 4 1
A __toString() 0 4 1
A __construct() 0 15 2
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