Passed
Push — develop ( 743253...17d957 )
by Manuele
01:37
created

ClassicVote::getAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Vote;
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
     * {@inheritdoc}
44
     */
45 1
    public function getServiceName(): string
46
    {
47 1
        return $this->serviceName;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function setServiceName(string $serviceName): self
54
    {
55 1
        $this->serviceName = $serviceName;
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function getUsername(): string
64
    {
65 1
        return $this->username;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function setUsername(string $username)
72
    {
73
        // Replace username to letters, numbers and "_"
74 1
        $this->username = preg_replace('/[^A-Za-z0-9_]+/', '', $username);
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 1
    public function getAddress(): string
83
    {
84 1
        return $this->address;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 1
    public function setAddress(string $address): self
91
    {
92 1
        $this->address = $address;
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 1
    public function getTimestamp(): ?int
101
    {
102 1
        return $this->timestamp->getTimestamp();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 1
    public function setTimestamp(DateTime $timestamp = null): self
109
    {
110 1
        $this->timestamp = $timestamp ?: new DateTime();
111
112 1
        return $this;
113
    }
114
}
115