Completed
Push — legacy ( c3f933 )
by Simonas
95:41
created

AbstractDocument::setTtl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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 ONGR\ElasticsearchBundle\Document;
13
14
use ONGR\ElasticsearchBundle\Result\DocumentHighlight;
15
16
/**
17
 * Document abstraction which introduces mandatory fields for the document.
18
 */
19
abstract class AbstractDocument implements DocumentInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $id;
25
26
    /**
27
     * @var string
28
     */
29
    private $score;
30
31
    /**
32
     * @var string
33
     */
34
    private $parent;
35
36
    /**
37
     * @var string
38
     */
39
    private $ttl;
40
41
    /**
42
     * @var DocumentHighlight
43
     */
44
    private $highlight;
45
46
    /**
47
     * Legacy property support.
48
     *
49
     * @param string $property
50
     *
51
     * @return null|string
52
     */
53 View Code Duplication
    public function __get($property)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        switch ($property) {
56
            case '_id':
57
                return $this->id;
58
            case '_score':
59
                return $this->score;
60
            case '_ttl':
61
                return $this->ttl;
62
            case '_parent':
63
                return $this->parent;
64
            default:
65
                return null;
66
        }
67
    }
68
69
    /**
70
     * Legacy property support and some special properties.
71
     *
72
     * @param string $property
73
     * @param mixed  $value
74
     */
75 View Code Duplication
    public function __set($property, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        switch ($property) {
78
            case '_id':
79
                $this->setId($value);
80
                break;
81
            case '_score':
82
                $this->setScore($value);
83
                break;
84
            case '_ttl':
85
                $this->setTtl($value);
86
                break;
87
            case '_parent':
88
                $this->setParent($value);
89
                break;
90
            default:
91
                // Required default case.
92
                break;
93
        }
94
    }
95
96
    /**
97
     * When document is cloned id is set to null.
98
     */
99
    public function __clone()
100
    {
101
        $this->setId(null);
102
    }
103
104
    /**
105
     * Sets document unique id.
106
     *
107
     * @param string $documentId
108
     *
109
     * @return $this
110
     */
111
    public function setId($documentId)
112
    {
113
        $this->id = $documentId;
114
115
        return $this;
116
    }
117
118
    /**
119
     * Returns document id.
120
     *
121
     * @return string
122
     */
123
    public function getId()
124
    {
125
        return $this->id;
126
    }
127
128
    /**
129
     * Sets document score.
130
     *
131
     * @param string $documentScore
132
     *
133
     * @return $this
134
     */
135
    public function setScore($documentScore)
136
    {
137
        $this->score = $documentScore;
138
139
        return $this;
140
    }
141
142
    /**
143
     * Gets document score.
144
     *
145
     * @return string
146
     */
147
    public function getScore()
148
    {
149
        return $this->score;
150
    }
151
152
    /**
153
     * Sets parent document id.
154
     *
155
     * @param string $parent
156
     *
157
     * @return $this
158
     */
159
    public function setParent($parent)
160
    {
161
        $this->parent = $parent;
162
163
        return $this;
164
    }
165
166
    /**
167
     * Returns parent document id.
168
     *
169
     * @return null|string
170
     */
171
    public function getParent()
172
    {
173
        return $this->parent;
174
    }
175
176
    /**
177
     * Checks if document has a parent.
178
     *
179
     * @return bool
180
     */
181
    public function hasParent()
182
    {
183
        return $this->parent !== null;
184
    }
185
186
    /**
187
     * Sets highlight.
188
     *
189
     * @param DocumentHighlight $highlight
190
     */
191
    public function setHighlight(DocumentHighlight $highlight)
192
    {
193
        $this->highlight = $highlight;
194
    }
195
196
    /**
197
     * Returns highlight.
198
     *
199
     * @throws \UnderflowException
200
     *
201
     * @return DocumentHighlight
202
     */
203
    public function getHighLight()
204
    {
205
        if ($this->highlight === null) {
206
            throw new \UnderflowException('Highlight not set.');
207
        }
208
209
        return $this->highlight;
210
    }
211
212
    /**
213
     * Sets time to live timestamp.
214
     *
215
     * @param string $ttl
216
     *
217
     * @return $this
218
     */
219
    public function setTtl($ttl)
220
    {
221
        $this->ttl = $ttl;
222
223
        return $this;
224
    }
225
226
    /**
227
     * Returns time to live value.
228
     *
229
     * @return int
230
     */
231
    public function getTtl()
232
    {
233
        return $this->ttl;
234
    }
235
}
236