Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
WebhookResponse
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getStatuses
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatus
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 isDelivered
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParseError
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\task;
22
23class WebhookResponse
24{
25    public const STATUS_ACCEPTED = 'accepted';
26    public const STATUS_IGNORED = 'ignored';
27    public const STATUS_ERROR = 'error';
28
29    /**
30     * Key is event id, value - one of the statuses
31     * @var string[]
32     */
33    private $statuses;
34
35    /**
36     * @var string|null
37     */
38    private $parseError;
39
40    /**
41     * @param string[] $statuses
42     * @param string|null $parseError
43     */
44    public function __construct(
45        array $statuses = [],
46        $parseError = null
47    ) {
48        $this->statuses = $statuses;
49        $this->parseError = $parseError;
50    }
51
52    /**
53     * @return string[]
54     */
55    public function getStatuses()
56    {
57        return $this->statuses;
58    }
59
60    /**
61     * @param $eventId
62     * @return string|null
63     */
64    public function getStatus($eventId)
65    {
66        return isset($this->statuses[$eventId])
67            ? $this->statuses[$eventId]
68            : null;
69    }
70
71    /**
72     * @param string $eventId
73     * @return bool
74     */
75    public function isDelivered($eventId)
76    {
77        return in_array($this->getStatus($eventId), [self::STATUS_ACCEPTED, self::STATUS_IGNORED], true);
78    }
79
80    /**
81     * @return string|null
82     */
83    public function getParseError()
84    {
85        return $this->parseError;
86    }
87}