NotificationRequestEntity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 6 2
A setCreatedAt() 0 7 2
A setData() 0 5 1
1
<?php
2
3
/**
4
 * PHP version 5.4 and 8
5
 *
6
 * @category  RequestEntity
7
 * @package   Payever\Payments
8
 * @author    payever GmbH <[email protected]>
9
 * @author    Hennadii Shymanskyi <[email protected]>
10
 * @copyright 2017-2021 payever GmbH
11
 * @license   MIT <https://opensource.org/licenses/MIT>
12
 * @link      https://docs.payever.org/shopsystems/api/getting-started
13
 */
14
15
namespace Payever\ExternalIntegration\Payments\Http\RequestEntity;
16
17
use Payever\ExternalIntegration\Core\Http\RequestEntity;
18
use Payever\ExternalIntegration\Payments\Notification\MessageEntity\NotificationResultEntity;
19
20
/**
21
 * @method string getNotificationType()
22
 * @method array getNotificationTypesAvailable()
23
 * @method setNotificationType(string $notificationType)
24
 * @method setNotificationTypesAvailable(array $notificationTypes)
25
 * @method \DateTime|false getCreatedAt()
26
 * @method NotificationResultEntity getPayment()
27
 *
28
 * @SuppressWarnings(PHPMD.LongVariable)
29
 */
30
class NotificationRequestEntity extends RequestEntity
31
{
32
    /** @var string */
33
    protected $notificationType;
34
35
    /** @var array */
36
    protected $notificationTypesAvailable;
37
38
    /** @var \DateTime|bool */
39
    protected $createdAt;
40
41
    /** @var NotificationResultEntity */
42
    protected $payment;
43
44
    /**
45
     * @param string $createdAt
46
     * @return static
47
     */
48
    public function setCreatedAt($createdAt)
49
    {
50
        if ($createdAt) {
51
            $this->createdAt = date_create($createdAt);
52
        }
53
54
        return $this;
55
    }
56
57
    /**
58
     * @return bool
59
     */
60
    public function isValid()
61
    {
62
        $types = $this->getNotificationTypesAvailable();
63
64
        return is_array($types)
65
            && in_array($this->getNotificationType(), $types)
66
        ;
67
    }
68
69
    /**
70
     * @param array $data
71
     *
72
     * @return static
73
     */
74
    public function setData(array $data)
75
    {
76
        $this->payment = new NotificationResultEntity($data['payment']);
77
78
        return $this;
79
    }
80
}
81