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

RevisionTrait::getRevisionNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Util\Util;
15
16
/**
17
 * Trait RevisionTrait.
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
trait RevisionTrait
22
{
23
    /**
24
     * Revision guid.
25
     *
26
     * @var string
27
     */
28
    protected $revisionGuid;
29
30
    /**
31
     * Revision number.
32
     *
33
     * @var int|null
34
     */
35
    protected $revisionNumber;
36
37
    /**
38
     * Revision type that can be 'single_user', or 'vote_based'.
39
     *
40
     * @var string
41
     */
42
    protected $revisionType;
43
44
    /**
45
     * Sets revision guid.
46
     *
47
     * @param string $revisionGuid The revision guid
48
     *
49
     * @return $this self Object
50
     */
51
    public function setRevisionGuid($revisionGuid)
52
    {
53
        $this->revisionGuid = $revisionGuid;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Gets revision guid.
60
     *
61
     * @return string
62
     */
63
    public function getRevisionGuid()
64
    {
65
        return $this->revisionGuid;
66
    }
67
68
    /**
69
     * Sets revision number.
70
     *
71
     * @param int|null $revisionNumber The revision number
72
     *
73
     * @return $this self Object
74
     */
75
    public function setRevisionNumber($revisionNumber)
76
    {
77
        $this->revisionNumber = $revisionNumber;
78
79
        return $this;
80
    }
81
82
    /**
83
     * Gets revision number.
84
     *
85
     * @return int|null
86
     */
87
    public function getRevisionNumber()
88
    {
89
        return $this->revisionNumber;
90
    }
91
92
    /**
93
     * Sets revision type.
94
     *
95
     * @param string $revisionType The revision that can be 'single_user', or 'vote_based'
96
     *
97
     * @return $this self Object
98
     */
99
    public function setRevisionType($revisionType)
100
    {
101
        if (Util::coincidesElement($revisionType, ['single_user', 'vote_based']) === true) {
102
            $this->revisionType = $revisionType;
103
        }
104
105
        return $this;
106
    }
107
108
    /**
109
     * Gets revision type.
110
     *
111
     * @return string
112
     */
113
    public function getRevisionType()
114
    {
115
        return $this->revisionType;
116
    }
117
118
    /**
119
     * Loads the variables if the data exist into resource. It works like a constructor.
120
     *
121
     * @param null|mixed[] $resource  The resource
122
     * @param string[]     $constants The array of constants
123
     */
124
    protected function loadRevision($resource, $constants)
125
    {
126
        $this->revisionGuid = Util::setIfStringExists($resource, 'revision_guid');
127
        $this->revisionNumber = Util::setIfIntegerExists($resource, 'revision_number');
128
        $this->revisionType = Util::isEqual($resource, 'revision_type', $constants);
129
    }
130
}
131