Completed
Branch develop (8166a6)
by Romain
01:52
created

Payment::addTester()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger\Model\ThreadSettings;
3
4
use Kerox\Messenger\Model\ThreadSettings;
5
6
class Payment extends ThreadSettings implements ActionTypeInterface
7
{
8
9
    /**
10
     * @var null|string
11
     */
12
    protected $privacyUrl;
13
14
    /**
15
     * @var null|string
16
     */
17
    protected $publicKey;
18
19
    /**
20
     * @var null|string
21
     */
22
    protected $devModeAction;
23
24
    /**
25
     * @var null|array
26
     */
27
    protected $testers = [];
28
29
    /**
30
     * Payment constructor.
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct(ThreadSettings::TYPE_PAYMENT);
35
    }
36
37
    /**
38
     * @param string $privacyUrl
39
     */
40
    public function setPrivacyUrl(string $privacyUrl)
41
    {
42
        $this->isValidUrl($privacyUrl);
43
        $this->privacyUrl = $privacyUrl;
44
    }
45
46
    /**
47
     * @param string $publicKey
48
     */
49
    public function setPublicKey(string $publicKey)
50
    {
51
        $this->publicKey = $publicKey;
52
    }
53
54
    /**
55
     * @param string $tester
56
     */
57
    public function addTester(string $tester)
58
    {
59
        $this->testers[] = $tester;
60
        $this->setDevModeAction(ActionTypeInterface::ADD);
61
    }
62
63
    /**
64
     * @param string $tester
65
     */
66
    public function removeTester(string $tester)
67
    {
68
        $this->testers[] = $tester;
69
        $this->setDevModeAction(ActionTypeInterface::REMOVE);
70
    }
71
72
    /**
73
     * @param string $devModeAction
74
     */
75
    private function setDevModeAction(string $devModeAction)
76
    {
77
        if ($this->devModeAction === null) {
78
            $this->devModeAction = strtoupper($devModeAction);
79
        }
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function jsonSerialize(): array
86
    {
87
        $json = parent::jsonSerialize();
88
        $json += [
89
            'payment_privacy_url' => $this->privacyUrl,
90
            'payment_public_key' => $this->publicKey,
91
            'payment_dev_mode_action' => $this->devModeAction,
92
            'payment_testers' => $this->testers,
93
        ];
94
95
        return array_filter($json);
96
    }
97
}
98