Completed
Pull Request — develop (#315)
by Carlos
07:17
created

Alignment::getMarginTop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Style;
19
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
22
/**
23
 * \PhpOffice\PhpPresentation\Style\Alignment
24
 */
25
class Alignment implements ComparableInterface
26
{
27
    /* Horizontal alignment styles */
28
    const HORIZONTAL_GENERAL                = 'l';
29
    const HORIZONTAL_LEFT                   = 'l';
30
    const HORIZONTAL_RIGHT                  = 'r';
31
    const HORIZONTAL_CENTER                 = 'ctr';
32
    const HORIZONTAL_JUSTIFY                = 'just';
33
    const HORIZONTAL_DISTRIBUTED            = 'dist';
34
35
    /* Vertical alignment styles */
36
    const VERTICAL_BASE                     = 'base';
37
    const VERTICAL_AUTO                     = 'auto';
38
    const VERTICAL_BOTTOM                   = 'b';
39
    const VERTICAL_TOP                      = 't';
40
    const VERTICAL_CENTER                   = 'ctr';
41
42
    private $supportedStyles = array(
43
        self::HORIZONTAL_GENERAL,
44
        self::HORIZONTAL_LEFT,
45
        self::HORIZONTAL_RIGHT,
46
    );
47
48
    /**
49
     * Horizontal
50
     *
51
     * @var string
52
     */
53
    private $horizontal;
54
55
    /**
56
     * Vertical
57
     *
58
     * @var string
59
     */
60
    private $vertical;
61
62
    /**
63
     * Level
64
     *
65
     * @var int
66
     */
67
    private $level = 0;
68
69
    /**
70
     * Indent - only possible with horizontal alignment left and right
71
     *
72
     * @var int
73
     */
74
    private $indent = 0;
75
76
    /**
77
     * Margin left - only possible with horizontal alignment left and right
78
     *
79
     * @var int
80
     */
81
    private $marginLeft = 0;
82
83
    /**
84
     * Margin right - only possible with horizontal alignment left and right
85
     *
86
     * @var int
87
     */
88
    private $marginRight = 0;
89
90
    /**
91
     * Margin top
92
     *
93
     * @var int
94
     */
95
    private $marginTop = 0;
96
97
    /**
98
     * Margin bottom
99
     *
100 298
     * @var int
101
     */
102
    private $marginBottom = 0;
103 298
104 298
    /**
105 298
     * Hash index
106
     *
107
     * @var string
108
     */
109
    private $hashIndex;
110
111
    /**
112 206
     * Create a new \PhpOffice\PhpPresentation\Style\Alignment
113
     */
114 206
    public function __construct()
115
    {
116
        // Initialise values
117
        $this->horizontal          = self::HORIZONTAL_LEFT;
118
        $this->vertical            = self::VERTICAL_BASE;
119
    }
120
121
    /**
122
     * Get Horizontal
123 205
     *
124
     * @return string
125 205
     */
126 1
    public function getHorizontal()
127
    {
128 205
        return $this->horizontal;
129
    }
130 205
131
    /**
132
     * Set Horizontal
133
     *
134
     * @param  string                        $pValue
135
     * @return \PhpOffice\PhpPresentation\Style\Alignment
136
     */
137
    public function setHorizontal($pValue = self::HORIZONTAL_LEFT)
138 61
    {
139
        if ($pValue == '') {
140 61
            $pValue = self::HORIZONTAL_LEFT;
141
        }
142
        $this->horizontal = $pValue;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Get Vertical
149 10
     *
150
     * @return string
151 10
     */
152 1
    public function getVertical()
153
    {
154 10
        return $this->vertical;
155
    }
156 10
157
    /**
158
     * Set Vertical
159
     *
160
     * @param  string                        $pValue
161
     * @return \PhpOffice\PhpPresentation\Style\Alignment
162
     */
163
    public function setVertical($pValue = self::VERTICAL_BASE)
164 79
    {
165
        if ($pValue == '') {
166 79
            $pValue = self::VERTICAL_BASE;
167
        }
168
        $this->vertical = $pValue;
169
170
        return $this;
171
    }
172
173
    /**
174
     * Get Level
175
     *
176 10
     * @return int
177
     */
178 10
    public function getLevel()
179 1
    {
180
        return $this->level;
181 9
    }
182
183 9
    /**
184
     * Set Level
185
     *
186
     * @param  int                           $pValue Ranging 0 - 8
187
     * @throws \Exception
188
     * @return \PhpOffice\PhpPresentation\Style\Alignment
189
     */
190
    public function setLevel($pValue = 0)
191 118
    {
192
        if ($pValue < 0) {
193 118
            throw new \Exception("Invalid value should be more than 0.");
194
        }
195
        $this->level = $pValue;
196
197
        return $this;
198
    }
199
200
    /**
201
     * Get indent
202 202
     *
203
     * @return int
204 202
     */
205 1
    public function getIndent()
206
    {
207
        return $this->indent;
208 202
    }
209
210 202
    /**
211
     * Set indent
212
     *
213
     * @param  int                           $pValue
214
     * @return \PhpOffice\PhpPresentation\Style\Alignment
215
     */
216
    public function setIndent($pValue = 0)
217
    {
218 116
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
219
            $pValue = 0; // indent not supported
220 116
        }
221
222
        $this->indent = $pValue;
223
224
        return $this;
225
    }
226
227
    /**
228
     * Get margin left
229 202
     *
230
     * @return int
231 202
     */
232 202
    public function getMarginLeft()
233
    {
234
        return $this->marginLeft;
235 202
    }
236
237 202
    /**
238
     * Set margin left
239
     *
240
     * @param  int                           $pValue
241
     * @return \PhpOffice\PhpPresentation\Style\Alignment
242
     */
243
    public function setMarginLeft($pValue = 0)
244
    {
245 101
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
246
            $pValue = 0; // margin left not supported
247 101
        }
248
249
        $this->marginLeft = $pValue;
250
251
        return $this;
252
    }
253
254
    /**
255
     * Get margin right
256 4
     *
257
     * @return int
258 4
     */
259 1
    public function getMarginRight()
260
    {
261
        return $this->marginRight;
262 4
    }
263
264 4
    /**
265
     * Set margin ight
266
     *
267
     * @param  int                           $pValue
268
     * @return \PhpOffice\PhpPresentation\Style\Alignment
269
     */
270
    public function setMarginRight($pValue = 0)
271
    {
272 46
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
273
            $pValue = 0; // margin right not supported
274 46
        }
275 46
276 46
        $this->marginRight = $pValue;
277 46
278 46
        return $this;
279 46
    }
280 46
281 46
    /**
282
     * Get margin top
283
     *
284
     * @return int
285
     */
286
    public function getMarginTop()
287
    {
288
        return $this->marginTop;
289
    }
290
291
    /**
292
     * Set margin top
293 1
     *
294
     * @param  int                           $pValue
295 1
     * @return \PhpOffice\PhpPresentation\Style\Alignment
296
     */
297
    public function setMarginTop($pValue = 0)
298
    {
299
        $this->marginTop = $pValue;
300
301
        return $this;
302
    }
303
304
    /**
305
     * Get margin bottom
306 1
     *
307
     * @return int
308 1
     */
309 1
    public function getMarginBottom()
310
    {
311 1
        return $this->marginBottom;
312
    }
313
314
    /**
315
     * Set margin bottom
316
     *
317
     * @param  int                           $pValue
318
     * @return \PhpOffice\PhpPresentation\Style\Alignment
319
     */
320
    public function setMarginBottom($pValue = 0)
321
    {
322
        $this->marginBottom = $pValue;
323
324
        return $this;
325
    }
326
327
    /**
328
     * Get hash code
329
     *
330
     * @return string Hash code
331
     */
332
    public function getHashCode()
333
    {
334
        return md5(
335
            $this->horizontal
336
            . $this->vertical
337
            . $this->level
338
            . $this->indent
339
            . $this->marginLeft
340
            . $this->marginRight
341
            . __CLASS__
342
        );
343
    }
344
345
    /**
346
     * Get hash index
347
     *
348
     * Note that this index may vary during script execution! Only reliable moment is
349
     * while doing a write of a workbook and when changes are not allowed.
350
     *
351
     * @return string Hash index
352
     */
353
    public function getHashIndex()
354
    {
355
        return $this->hashIndex;
356
    }
357
358
    /**
359
     * Set hash index
360
     *
361
     * Note that this index may vary during script execution! Only reliable moment is
362
     * while doing a write of a workbook and when changes are not allowed.
363
     *
364
     * @param string $value Hash index
365
     */
366
    public function setHashIndex($value)
367
    {
368
        $this->hashIndex = $value;
369
    }
370
}
371