Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.87% covered (warning)
60.87%
14 / 23
88.89% covered (warning)
88.89%
8 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
Webhook
60.87% covered (warning)
60.87%
14 / 23
88.89% covered (warning)
88.89%
8 / 9
15.99
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHttpMethod
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExtraPayload
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 getMaxRetries
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponseValidationEnable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2019 (original work) Open Assessment Technologies SA;
19 */
20
21namespace oat\tao\model\webhooks\configEntity;
22
23class Webhook implements WebhookInterface
24{
25    public const ID = 'id';
26    public const URL = 'url';
27    public const HTTP_METHOD = 'httpMethod';
28    public const AUTH = 'auth';
29    public const RETRY_MAX = 'retryMax';
30    public const RESPONSE_VALIDATION = 'responseValidation';
31    public const EXTRA_PAYLOAD = 'extraPayload';
32
33    /**
34     * @var string
35     */
36    private $id;
37
38    /**
39     * @var string
40     */
41    private $url;
42
43    /**
44     * @var string
45     */
46    private $httpMethod;
47
48    /**
49     * @var WebhookAuth|null
50     */
51    private $auth;
52
53    /**
54     * @var int
55     */
56    private $retryMax;
57
58    /** @var bool */
59    private $responseValidation;
60
61    /** @var array */
62    private $extraPayload;
63
64    public function __construct(
65        string $id,
66        string $url,
67        string $httpMethod,
68        int $retryMax,
69        WebhookAuth $auth = null,
70        bool $responseValidation = true,
71        array $extraPayload = []
72    ) {
73        $this->id = $id;
74        $this->url = $url;
75        $this->httpMethod = $httpMethod;
76        $this->auth = $auth;
77        $this->retryMax = $retryMax;
78        $this->responseValidation = $responseValidation;
79        $this->extraPayload = $extraPayload;
80    }
81
82    /**
83     * @return string
84     */
85    public function getId()
86    {
87        return $this->id;
88    }
89
90    /**
91     * @return string
92     */
93    public function getUrl()
94    {
95        return $this->url;
96    }
97
98    /**
99     * @return string
100     */
101    public function getHttpMethod()
102    {
103        return $this->httpMethod;
104    }
105
106    /**
107     * @return WebhookAuth|null
108     */
109    public function getAuth()
110    {
111        return $this->auth;
112    }
113
114    public function getExtraPayload(): array
115    {
116        return $this->extraPayload;
117    }
118
119    /**
120     * @return array
121     */
122    public function toArray(): array
123    {
124        return [
125            self::ID => $this->getId(),
126            self::URL => $this->getUrl(),
127            self::HTTP_METHOD => $this->getHttpMethod(),
128            self::RETRY_MAX => $this->getMaxRetries(),
129            self::RESPONSE_VALIDATION => $this->getResponseValidationEnable(),
130            self::AUTH => $this->getAuth() !== null
131                ? $this->getAuth()->toArray()
132                : null
133        ];
134    }
135
136    /**
137     * @return int
138     */
139    public function getMaxRetries()
140    {
141        return $this->retryMax;
142    }
143
144    public function getResponseValidationEnable()
145    {
146        return $this->responseValidation;
147    }
148}