Passed
Push — develop ( d07d22...02265f )
by Manuele
14:21
created

ClassicVote::setServiceName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * Votifier PHP Client
5
 *
6
 * @package   VotifierClient
7
 * @author    Manuele Vaccari <[email protected]>
8
 * @copyright Copyright (c) 2017-2020 Manuele Vaccari <[email protected]>
9
 * @license   https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
10
 * @link      https://github.com/D3strukt0r/votifier-client-php
11
 */
12
13
namespace D3strukt0r\VotifierClient\VoteType;
14
15
use DateTime;
16
17
/**
18
 * The classic vote package can be used by most plugins.
19
 */
20
class ClassicVote implements VoteInterface
21
{
22
    /**
23
     * @var string the name of the list/service
24
     */
25
    private $serviceName;
26
27
    /**
28
     * @var string the username who wants to receive the rewards
29
     */
30
    private $username;
31
32
    /**
33
     * @var string the IP Address of the user
34
     */
35
    private $address;
36
37
    /**
38
     * @var DateTime the time when the vote will be sent
39
     */
40
    private $timestamp;
41
42
    /**
43
     * Creates the ClassicVote object.
44
     */
45
    public function __construct()
46
    {
47
    }
48
49
    /**
50 3
     * {@inheritdoc}
51
     */
52
    public function getServiceName(): string
53 3
    {
54 3
        return $this->serviceName;
55 3
    }
56 3
57 3
    /**
58
     * {@inheritdoc}
59
     */
60
    public function setServiceName(string $serviceName): self
61
    {
62 1
        $this->serviceName = $serviceName;
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function getUsername(): string
71
    {
72 1
        return $this->username;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function setUsername(string $username)
79
    {
80 1
        // Replace username to letters, numbers and "_"
81
        $this->username = preg_replace('/[^A-Za-z0-9_]+/', '', $username);
82
83
        return $this;
84
    }
85
86 2
    /**
87
     * {@inheritdoc}
88 2
     */
89 1
    public function getAddress(): string
90
    {
91
        return $this->address;
92 1
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function setAddress(string $address): self
98 1
    {
99
        $this->address = $address;
100 1
101
        return $this;
102 1
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function getTimestamp(): ?int
108
    {
109
        return $this->timestamp->getTimestamp();
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function setTimestamp(DateTime $timestamp = null): self
116
    {
117
        $this->timestamp = $timestamp ?: new DateTime();
118
119
        return $this;
120
    }
121
}
122