Completed
Push — develop ( 9a2399...3e0ce0 )
by Franck
09:15
created

Alignment   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 346
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 92.11%

Importance

Changes 0
Metric Value
wmc 29
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 346
ccs 70
cts 76
cp 0.9211
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
A getHorizontal() 0 4 1
A getVertical() 0 4 1
A getIndent() 0 4 1
A getMarginLeft() 0 4 1
A getMarginRight() 0 4 1
A getMarginBottom() 0 4 1
A __construct() 0 6 1
A setHorizontal() 0 9 2
A setVertical() 0 9 2
A getLevel() 0 4 1
A setLevel() 0 9 2
A setIndent() 0 10 3
A setMarginLeft() 0 10 3
A setMarginRight() 0 10 3
A getMarginTop() 0 4 1
A setMarginTop() 0 6 1
A setMarginBottom() 0 6 1
A getHashCode() 0 12 1
A getHashIndex() 0 4 1
A setHashIndex() 0 4 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 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
     * @var int
101
     */
102
    private $marginBottom = 0;
103
104
    /**
105
     * Hash index
106
     *
107
     * @var string
108
     */
109
    private $hashIndex;
110
111
    /**
112
     * Create a new \PhpOffice\PhpPresentation\Style\Alignment
113
     */
114 298
    public function __construct()
115
    {
116
        // Initialise values
117 298
        $this->horizontal          = self::HORIZONTAL_LEFT;
118 298
        $this->vertical            = self::VERTICAL_BASE;
119 298
    }
120
121
    /**
122
     * Get Horizontal
123
     *
124
     * @return string
125
     */
126 206
    public function getHorizontal()
127
    {
128 206
        return $this->horizontal;
129
    }
130
131
    /**
132
     * Set Horizontal
133
     *
134
     * @param  string                        $pValue
135
     * @return \PhpOffice\PhpPresentation\Style\Alignment
136
     */
137 205
    public function setHorizontal($pValue = self::HORIZONTAL_LEFT)
138
    {
139 205
        if ($pValue == '') {
140 1
            $pValue = self::HORIZONTAL_LEFT;
141 1
        }
142 205
        $this->horizontal = $pValue;
143
144 205
        return $this;
145
    }
146
147
    /**
148
     * Get Vertical
149
     *
150
     * @return string
151
     */
152 61
    public function getVertical()
153
    {
154 61
        return $this->vertical;
155
    }
156
157
    /**
158
     * Set Vertical
159
     *
160
     * @param  string                        $pValue
161
     * @return \PhpOffice\PhpPresentation\Style\Alignment
162
     */
163 10
    public function setVertical($pValue = self::VERTICAL_BASE)
164
    {
165 10
        if ($pValue == '') {
166 1
            $pValue = self::VERTICAL_BASE;
167 1
        }
168 10
        $this->vertical = $pValue;
169
170 10
        return $this;
171
    }
172
173
    /**
174
     * Get Level
175
     *
176
     * @return int
177
     */
178 79
    public function getLevel()
179
    {
180 79
        return $this->level;
181
    }
182
183
    /**
184
     * Set Level
185
     *
186
     * @param  int                           $pValue Ranging 0 - 8
187
     * @throws \Exception
188
     * @return \PhpOffice\PhpPresentation\Style\Alignment
189
     */
190 10
    public function setLevel($pValue = 0)
191
    {
192 10
        if ($pValue < 0) {
193 1
            throw new \Exception("Invalid value should be more than 0.");
194
        }
195 9
        $this->level = $pValue;
196
197 9
        return $this;
198
    }
199
200
    /**
201
     * Get indent
202
     *
203
     * @return int
204
     */
205 118
    public function getIndent()
206
    {
207 118
        return $this->indent;
208
    }
209
210
    /**
211
     * Set indent
212
     *
213
     * @param  int                           $pValue
214
     * @return \PhpOffice\PhpPresentation\Style\Alignment
215
     */
216 202
    public function setIndent($pValue = 0)
217
    {
218 202
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
219 1
            $pValue = 0; // indent not supported
220 1
        }
221
222 202
        $this->indent = $pValue;
223
224 202
        return $this;
225
    }
226
227
    /**
228
     * Get margin left
229
     *
230
     * @return int
231
     */
232 116
    public function getMarginLeft()
233
    {
234 116
        return $this->marginLeft;
235
    }
236
237
    /**
238
     * Set margin left
239
     *
240
     * @param  int                           $pValue
241
     * @return \PhpOffice\PhpPresentation\Style\Alignment
242
     */
243 202
    public function setMarginLeft($pValue = 0)
244
    {
245 202
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
246 202
            $pValue = 0; // margin left not supported
247 202
        }
248
249 202
        $this->marginLeft = $pValue;
250
251 202
        return $this;
252
    }
253
254
    /**
255
     * Get margin right
256
     *
257
     * @return int
258
     */
259 101
    public function getMarginRight()
260
    {
261 101
        return $this->marginRight;
262
    }
263
264
    /**
265
     * Set margin ight
266
     *
267
     * @param  int                           $pValue
268
     * @return \PhpOffice\PhpPresentation\Style\Alignment
269
     */
270 4
    public function setMarginRight($pValue = 0)
271
    {
272 4
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
273 1
            $pValue = 0; // margin right not supported
274 1
        }
275
276 4
        $this->marginRight = $pValue;
277
278 4
        return $this;
279
    }
280
281
    /**
282
     * Get margin top
283
     *
284
     * @return int
285
     */
286 9
    public function getMarginTop()
287
    {
288 9
        return $this->marginTop;
289
    }
290
291
    /**
292
     * Set margin top
293
     *
294
     * @param  int                           $pValue
295
     * @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
     *
307
     * @return int
308
     */
309 9
    public function getMarginBottom()
310
    {
311 9
        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 46
    public function getHashCode()
333
    {
334 46
        return md5(
335 46
            $this->horizontal
336 46
            . $this->vertical
337 46
            . $this->level
338 46
            . $this->indent
339 46
            . $this->marginLeft
340 46
            . $this->marginRight
341 46
            . __CLASS__
342 46
        );
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 1
    public function getHashIndex()
354
    {
355 1
        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 1
    public function setHashIndex($value)
367
    {
368 1
        $this->hashIndex = $value;
369 1
    }
370
}
371