TravisCIService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * WebhookManager
5
 *
6
 * @author: Luca Agnello <[email protected]>
7
 */
8
9
namespace Gnello\WebhookManager\Services;
10
11
use Gnello\WebhookManager\WebhookManagerException;
12
13
/**
14
 * Class TravisCIService
15
 *
16
 * @link https://docs.travis-ci.com/user/notifications/#Configuring-webhook-notifications
17
 * @package Gnello\WebhookManager\Services
18
 */
19
class TravisCIService implements ServiceInterface
20
{
21
    /**
22
     * General events
23
     */
24
    const PUSH = 'push';
25
    const PULL_REQUEST = 'pull_request';
26
    const CRON = 'cron';
27
    const API = 'api';
28
29
    /**
30
     * @var array
31
     */
32
    private $options;
33
34
    /**
35
     * @var array
36
     */
37
    private $headers = [];
38
39
    /**
40
     * @var mixed
41
     */
42
    private $payload;
43
44
    /**
45
     * BitbucketService constructor.
46
     *
47
     * @param array $options
48
     */
49
    public function __construct(array $options)
50
    {
51
        $this->options = $options;
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getHeaders(): array
58
    {
59
        return $this->headers;
60
    }
61
62
    /**
63
     * @return string
64
     * @throws WebhookManagerException
65
     */
66
    public function getEvent(): string
67
    {
68
        return $this->getPayload()['type'];
69
    }
70
71
    /**
72
     * @return mixed
73
     */
74
    public function getPayload()
75
    {
76
        if (!isset($this->payload)) {
77
            $this->payload = json_decode($_POST['payload'], (bool) $this->options['json_decode_assoc']);
78
        }
79
80
        return $this->payload;
81
    }
82
}