GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b6f376...58a2c7 )
by Alexander
03:08
created

NotificationServices::getAvailableServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Alexander Zhukov <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Zbox\UnifiedPush\NotificationService;
11
12
use Zbox\UnifiedPush\Exception\DomainException;
13
14
/**
15
 * Class NotificationServices
16
 * @package Zbox\UnifiedPush\NotificationService
17
 */
18
class NotificationServices
19
{
20
    const APPLE_PUSH_NOTIFICATIONS_SERVICE     = 'APNS';
21
    const GOOGLE_CLOUD_MESSAGING               = 'GCM';
22
    const MICROSOFT_PUSH_NOTIFICATIONS_SERVICE = 'MPNS';
23
24
    const CREDENTIALS_NULL          = 1;
25
    const CREDENTIALS_CERTIFICATE   = 2;
26
    const CREDENTIALS_AUTH_TOKEN    = 3;
27
28
    /**
29
     * List of supported notification services
30
     *
31
     * @return array
32
     */
33
    public static function getAvailableServices()
34
    {
35
        return
36
            array(
37
                self::APPLE_PUSH_NOTIFICATIONS_SERVICE,
38
                self::GOOGLE_CLOUD_MESSAGING,
39
                self::MICROSOFT_PUSH_NOTIFICATIONS_SERVICE
40
            );
41
    }
42
43
    /**
44
     * Checks if notification service is supported
45
     *
46
     * @param string $serviceName
47
     * @return string
48
     * @throws DomainException
49
     */
50
    public static function validateServiceName($serviceName)
51
    {
52
        if (!in_array($serviceName, self::getAvailableServices())) {
53
            throw new DomainException(sprintf("Notification service '%s' is not supported.", $serviceName));
54
        }
55
        return $serviceName;
56
    }
57
58
    /**
59
     * @param string $serviceName
60
     * @return int
61
     */
62
    public static function getCredentialsTypeByService($serviceName)
63
    {
64
        self::validateServiceName($serviceName);
65
66
        $credentials = array(
67
            self::APPLE_PUSH_NOTIFICATIONS_SERVICE      => self::CREDENTIALS_CERTIFICATE,
68
            self::GOOGLE_CLOUD_MESSAGING                => self::CREDENTIALS_AUTH_TOKEN,
69
            self::MICROSOFT_PUSH_NOTIFICATIONS_SERVICE  => self::CREDENTIALS_CERTIFICATE
70
        );
71
72
        return $credentials[$serviceName];
73
    }
74
}
75