Passed
Push — develop ( 02265f...f821dc )
by Manuele
10:28
created

Vote::setVote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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;
14
15
use D3strukt0r\VotifierClient\ServerType\ServerTypeInterface;
16
use D3strukt0r\VotifierClient\VoteType\VoteInterface;
17
use DateTime;
18
use Exception;
19
20
/**
21
 * This class is used for easy access to all classes and to send the votes.
22
 */
23
class Vote
24
{
25
    /**
26
     * @var VoteInterface the vote package
27
     */
28
    private $vote;
29
30
    /**
31
     * @var ServerTypeInterface the server type information package
32
     */
33
    private $server;
34
35
    /**
36
     * Gets the vote.
37
     *
38
     * @return VoteInterface return the vote
39
     */
40 1
    public function getVote(): VoteInterface
41
    {
42 1
        return $this->vote;
43 1
    }
44 1
45
    /**
46
     * Sets the vote.
47
     *
48
     * @param VoteInterface $vote The vote
49
     *
50
     * @return $this returns the class itself, for doing multiple things at once
51
     */
52
    public function setVote(VoteInterface $vote): self
53
    {
54
        $this->vote = $vote;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Gets the server type.
61
     *
62
     * @return ServerTypeInterface returns the server type
63
     */
64
    public function getServerType(): ServerTypeInterface
65
    {
66
        return $this->server;
67
    }
68
69
    /**
70
     * Sets the server type.
71
     *
72
     * @param ServerTypeInterface $server The server type
73
     *
74
     * @return $this returns the class itself, for doing multiple things at once
75
     */
76
    public function setServerType(ServerTypeInterface $server): self
77
    {
78
        $this->server = $server;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param DateTime|null $timestamp [optional] A timestamp
85
     *
86
     * @throws Exception
87
     */
88
    public function send(DateTime $timestamp = null): void
89
    {
90
        $con = new ServerConnection($this->server);
91
92
        $timestamp = $timestamp ?: new DateTime();
93
        $this->vote->setTimestamp($timestamp);
94
        $this->server->send($con, $this->vote);
95
    }
96
}
97