Completed
Push — master ( a95c92...e40b6a )
by Beñat
04:36
created

CloseTrait   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 172
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 11
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 172
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setCanClose() 0 6 1
A isCanClose() 0 4 1
A setCloseVoteCount() 0 6 1
A getCloseVoteCount() 0 4 1
A setClosedDate() 0 6 1
A getClosedDate() 0 4 1
A setClosedDetails() 0 6 1
A getClosedDetails() 0 4 1
A setClosedReason() 0 6 1
A getClosedReason() 0 4 1
A loadClose() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2015 Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BenatEspina\StackExchangeApiClient\Model\Traits;
13
14
use BenatEspina\StackExchangeApiClient\Model\ClosedDetails;
15
use BenatEspina\StackExchangeApiClient\Model\Interfaces\ClosedDetailsInterface;
16
use BenatEspina\StackExchangeApiClient\Util\Util;
17
18
/**
19
 * Trait CloseTrait.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
trait CloseTrait
24
{
25
    /**
26
     * Boolean that shows it can close or not.
27
     *
28
     * @var bool
29
     */
30
    protected $canClose;
31
32
    /**
33
     * Number of close votes.
34
     *
35
     * @var int
36
     */
37
    protected $closeVoteCount;
38
39
    /**
40
     * Closed date.
41
     *
42
     * @var \DateTime|null
43
     */
44
    protected $closedDate;
45
46
    /**
47
     * Closed details.
48
     *
49
     * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\ClosedDetailsInterface|null
50
     */
51
    protected $closedDetails;
52
53
    /**
54
     * Closed reason.
55
     *
56
     * @var string|null
57
     */
58
    protected $closedReason;
59
60
    /**
61
     * Sets can close.
62
     *
63
     * @param bool $canClose The canClose boolean
64
     *
65
     * @return $this self Object
66
     */
67
    public function setCanClose($canClose)
68
    {
69
        $this->canClose = $canClose;
70
71
        return $this;
72
    }
73
74
    /**
75
     * Gets can close.
76
     *
77
     * @return bool
78
     */
79
    public function isCanClose()
80
    {
81
        return $this->canClose;
82
    }
83
84
    /**
85
     * Sets number of close votes.
86
     *
87
     * @param int $closeVoteCount The number of close votes
88
     *
89
     * @return $this self Object
90
     */
91
    public function setCloseVoteCount($closeVoteCount)
92
    {
93
        $this->closeVoteCount = $closeVoteCount;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Gets close vote count.
100
     *
101
     * @return int
102
     */
103
    public function getCloseVoteCount()
104
    {
105
        return $this->closeVoteCount;
106
    }
107
108
    /**
109
     * Sets closed date.
110
     *
111
     * @param \DateTime|null $closedDate The closed date
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $closedDate a bit more specific; maybe use \DateTime.
Loading history...
112
     *
113
     * @return $this self Object
114
     */
115
    public function setClosedDate(\DateTime $closedDate)
116
    {
117
        $this->closedDate = $closedDate;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Gets closed date.
124
     *
125
     * @return \DateTime|null
126
     */
127
    public function getClosedDate()
128
    {
129
        return $this->closedDate;
130
    }
131
132
    /**
133
     * Sets closed details.
134
     *
135
     * @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\ClosedDetailsInterface|null $closedDetails The closed
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $closedDetails a bit more specific; maybe use ClosedDetailsInterface.
Loading history...
136
     *                                                                                                        details
137
     *
138
     * @return $this self Object
139
     */
140
    public function setClosedDetails(ClosedDetailsInterface $closedDetails)
141
    {
142
        $this->closedDetails = $closedDetails;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Gets closed details.
149
     *
150
     * @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\ClosedDetailsInterface|null
151
     */
152
    public function getClosedDetails()
153
    {
154
        return $this->closedDetails;
155
    }
156
157
    /**
158
     * Sets closed reason.
159
     *
160
     * @param string|null $closedReason The closed reason
161
     *
162
     * @return $this self Object
163
     */
164
    public function setClosedReason($closedReason)
165
    {
166
        $this->closedReason = $closedReason;
167
168
        return $this;
169
    }
170
171
    /**
172
     * Gets closed reason.
173
     *
174
     * @return string|null
175
     */
176
    public function getClosedReason()
177
    {
178
        return $this->closedReason;
179
    }
180
181
    /**
182
     * Loads the variables if the data exist into resource. It works like a constructor.
183
     *
184
     * @param null|mixed[] $resource The resource
185
     */
186
    protected function loadClose($resource)
187
    {
188
        $this->canClose = Util::setIfBoolExists($resource, 'can_close');
189
        $this->closeVoteCount = Util::setIfIntegerExists($resource, 'close_vote_count');
190
        $this->closedDate = Util::setIfDateTimeExists($resource, 'closed_date');
191
        $this->closedDetails = new ClosedDetails(Util::setIfArrayExists($resource, 'closed_details'));
192
        $this->closedReason = Util::setIfStringExists($resource, 'closed_reason');
193
    }
194
}
195