Completed
Push — develop ( 49d3fe...2ef315 )
by Franck
17s queued 12s
created

Alignment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 */
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 */
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
    /* Text direction */
43
    const TEXT_DIRECTION_HORIZONTAL = 'horz';
44
    const TEXT_DIRECTION_VERTICAL_90 = 'vert';
45
    const TEXT_DIRECTION_VERTICAL_270 = 'vert270';
46
    const TEXT_DIRECTION_STACKED = 'wordArtVert';
47
48
    private $supportedStyles = array(
49
        self::HORIZONTAL_GENERAL,
50
        self::HORIZONTAL_LEFT,
51
        self::HORIZONTAL_RIGHT,
52
    );
53
54
    /**
55
     * Horizontal
56
     * @var string
57
     */
58
    private $horizontal;
59
60
    /**
61
     * Vertical
62
     * @var string
63
     */
64
    private $vertical;
65
66
    /**
67
     * Text Direction
68
     * @var string
69
     */
70
    private $textDirection = self::TEXT_DIRECTION_HORIZONTAL;
71
72
    /**
73
     * Level
74
     * @var int
75
     */
76
    private $level = 0;
77
78
    /**
79
     * Indent - only possible with horizontal alignment left and right
80
     * @var int
81
     */
82
    private $indent = 0;
83
84
    /**
85
     * Margin left - only possible with horizontal alignment left and right
86
     * @var int
87
     */
88
    private $marginLeft = 0;
89
90
    /**
91
     * Margin right - only possible with horizontal alignment left and right
92
     * @var int
93
     */
94
    private $marginRight = 0;
95
96
    /**
97
     * Margin top
98
     * @var int
99
     */
100
    private $marginTop = 0;
101
102
    /**
103
     * Margin bottom
104
     * @var int
105
     */
106
    private $marginBottom = 0;
107
108
    /**
109
     * Hash index
110
     * @var string
111
     */
112
    private $hashIndex;
113
114
    /**
115
     * Create a new \PhpOffice\PhpPresentation\Style\Alignment
116
     */
117 337
    public function __construct()
118
    {
119
        // Initialise values
120 337
        $this->horizontal          = self::HORIZONTAL_LEFT;
121 337
        $this->vertical            = self::VERTICAL_BASE;
122 337
    }
123
124
    /**
125
     * Get Horizontal
126
     *
127
     * @return string
128
     */
129 236
    public function getHorizontal()
130
    {
131 236
        return $this->horizontal;
132
    }
133
134
    /**
135
     * Set Horizontal
136
     *
137
     * @param  string                        $pValue
138
     * @return \PhpOffice\PhpPresentation\Style\Alignment
139
     */
140 235
    public function setHorizontal($pValue = self::HORIZONTAL_LEFT)
141
    {
142 235
        if ($pValue == '') {
143 1
            $pValue = self::HORIZONTAL_LEFT;
144
        }
145 235
        $this->horizontal = $pValue;
146
147 235
        return $this;
148
    }
149
150
    /**
151
     * Get Vertical
152
     *
153
     * @return string
154
     */
155 72
    public function getVertical()
156
    {
157 72
        return $this->vertical;
158
    }
159
160
    /**
161
     * Set Vertical
162
     *
163
     * @param  string                        $pValue
164
     * @return \PhpOffice\PhpPresentation\Style\Alignment
165
     */
166 10
    public function setVertical($pValue = self::VERTICAL_BASE)
167
    {
168 10
        if ($pValue == '') {
169 1
            $pValue = self::VERTICAL_BASE;
170
        }
171 10
        $this->vertical = $pValue;
172
173 10
        return $this;
174
    }
175
176
    /**
177
     * Get Level
178
     *
179
     * @return int
180
     */
181 90
    public function getLevel()
182
    {
183 90
        return $this->level;
184
    }
185
186
    /**
187
     * Set Level
188
     *
189
     * @param  int                           $pValue Ranging 0 - 8
190
     * @throws \Exception
191
     * @return \PhpOffice\PhpPresentation\Style\Alignment
192
     */
193 10
    public function setLevel($pValue = 0)
194
    {
195 10
        if ($pValue < 0) {
196 1
            throw new \Exception("Invalid value should be more than 0.");
197
        }
198 9
        $this->level = $pValue;
199
200 9
        return $this;
201
    }
202
203
    /**
204
     * Get indent
205
     *
206
     * @return int
207
     */
208 133
    public function getIndent()
209
    {
210 133
        return $this->indent;
211
    }
212
213
    /**
214
     * Set indent
215
     *
216
     * @param  int                           $pValue
217
     * @return \PhpOffice\PhpPresentation\Style\Alignment
218
     */
219 232
    public function setIndent($pValue = 0)
220
    {
221 232
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
222 1
            $pValue = 0; // indent not supported
223
        }
224
225 232
        $this->indent = $pValue;
226
227 232
        return $this;
228
    }
229
230
    /**
231
     * Get margin left
232
     *
233
     * @return int
234
     */
235 131
    public function getMarginLeft()
236
    {
237 131
        return $this->marginLeft;
238
    }
239
240
    /**
241
     * Set margin left
242
     *
243
     * @param  int                           $pValue
244
     * @return \PhpOffice\PhpPresentation\Style\Alignment
245
     */
246 232
    public function setMarginLeft($pValue = 0)
247
    {
248 232
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
249 232
            $pValue = 0; // margin left not supported
250
        }
251
252 232
        $this->marginLeft = $pValue;
253
254 232
        return $this;
255
    }
256
257
    /**
258
     * Get margin right
259
     *
260
     * @return int
261
     */
262 115
    public function getMarginRight()
263
    {
264 115
        return $this->marginRight;
265
    }
266
267
    /**
268
     * Set margin ight
269
     *
270
     * @param  int                           $pValue
271
     * @return \PhpOffice\PhpPresentation\Style\Alignment
272
     */
273 5
    public function setMarginRight($pValue = 0)
274
    {
275 5
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
276 1
            $pValue = 0; // margin right not supported
277
        }
278
279 5
        $this->marginRight = $pValue;
280
281 5
        return $this;
282
    }
283
284
    /**
285
     * Get margin top
286
     *
287
     * @return int
288
     */
289 12
    public function getMarginTop()
290
    {
291 12
        return $this->marginTop;
292
    }
293
294
    /**
295
     * Set margin top
296
     *
297
     * @param  int                           $pValue
298
     * @return \PhpOffice\PhpPresentation\Style\Alignment
299
     */
300 2
    public function setMarginTop($pValue = 0)
301
    {
302 2
        $this->marginTop = $pValue;
303
304 2
        return $this;
305
    }
306
307
    /**
308
     * Get margin bottom
309
     *
310
     * @return int
311
     */
312 12
    public function getMarginBottom()
313
    {
314 12
        return $this->marginBottom;
315
    }
316
317
    /**
318
     * Set margin bottom
319
     *
320
     * @param  int                           $pValue
321
     * @return \PhpOffice\PhpPresentation\Style\Alignment
322
     */
323 2
    public function setMarginBottom($pValue = 0)
324
    {
325 2
        $this->marginBottom = $pValue;
326
327 2
        return $this;
328
    }
329
330
    /**
331
     * @return string
332
     */
333 12
    public function getTextDirection()
334
    {
335 12
        return $this->textDirection;
336
    }
337
338
    /**
339
     * @param string $pValue
340
     * @return Alignment
341
     */
342 2
    public function setTextDirection($pValue = self::TEXT_DIRECTION_HORIZONTAL)
343
    {
344 2
        if (empty($pValue)) {
345 1
            $pValue = self::TEXT_DIRECTION_HORIZONTAL;
346
        }
347 2
        $this->textDirection = $pValue;
348 2
        return $this;
349
    }
350
351
    /**
352
     * Get hash code
353
     *
354
     * @return string Hash code
355
     */
356 59
    public function getHashCode()
357
    {
358 59
        return md5(
359 59
            $this->horizontal
360 59
            . $this->vertical
361 59
            . $this->level
362 59
            . $this->indent
363 59
            . $this->marginLeft
364 59
            . $this->marginRight
365 59
            . __CLASS__
366
        );
367
    }
368
369
    /**
370
     * Get hash index
371
     *
372
     * Note that this index may vary during script execution! Only reliable moment is
373
     * while doing a write of a workbook and when changes are not allowed.
374
     *
375
     * @return string Hash index
376
     */
377 1
    public function getHashIndex()
378
    {
379 1
        return $this->hashIndex;
380
    }
381
382
    /**
383
     * Set hash index
384
     *
385
     * Note that this index may vary during script execution! Only reliable moment is
386
     * while doing a write of a workbook and when changes are not allowed.
387
     *
388
     * @param string $value Hash index
389
     */
390 1
    public function setHashIndex($value)
391
    {
392 1
        $this->hashIndex = $value;
393 1
    }
394
}
395