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

Payment   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 92
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPrivacyUrl() 0 5 1
A setPublicKey() 0 4 1
A addTester() 0 5 1
A removeTester() 0 5 1
A setDevModeAction() 0 6 2
A jsonSerialize() 0 12 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