Completed
Pull Request — develop (#216)
by Franck
07:08
created

Alignment::getIndent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
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 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
     * Hash index
92
     *
93
     * @var string
94
     */
95
    private $hashIndex;
96
97
    /**
98
     * Create a new \PhpOffice\PhpPresentation\Style\Alignment
99
     */
100 200
    public function __construct()
101
    {
102
        // Initialise values
103 200
        $this->horizontal          = self::HORIZONTAL_LEFT;
104 200
        $this->vertical            = self::VERTICAL_BASE;
105 200
    }
106
107
    /**
108
     * Get Horizontal
109
     *
110
     * @return string
111
     */
112 81
    public function getHorizontal()
113
    {
114 81
        return $this->horizontal;
115
    }
116
117
    /**
118
     * Set Horizontal
119
     *
120
     * @param  string                        $pValue
121
     * @return \PhpOffice\PhpPresentation\Style\Alignment
122
     */
123 14
    public function setHorizontal($pValue = self::HORIZONTAL_LEFT)
124
    {
125 14
        if ($pValue == '') {
126 1
            $pValue = self::HORIZONTAL_LEFT;
127
        }
128 14
        $this->horizontal = $pValue;
129
130 14
        return $this;
131
    }
132
133
    /**
134
     * Get Vertical
135
     *
136
     * @return string
137
     */
138 58
    public function getVertical()
139
    {
140 58
        return $this->vertical;
141
    }
142
143
    /**
144
     * Set Vertical
145
     *
146
     * @param  string                        $pValue
147
     * @return \PhpOffice\PhpPresentation\Style\Alignment
148
     */
149 10
    public function setVertical($pValue = self::VERTICAL_BASE)
150
    {
151 10
        if ($pValue == '') {
152 1
            $pValue = self::VERTICAL_BASE;
153
        }
154 10
        $this->vertical = $pValue;
155
156 10
        return $this;
157
    }
158
159
    /**
160
     * Get Level
161
     *
162
     * @return int
163
     */
164 76
    public function getLevel()
165
    {
166 76
        return $this->level;
167
    }
168
169
    /**
170
     * Set Level
171
     *
172
     * @param  int                           $pValue Ranging 0 - 8
173
     * @throws \Exception
174
     * @return \PhpOffice\PhpPresentation\Style\Alignment
175
     */
176 9
    public function setLevel($pValue = 0)
177
    {
178 9
        if ($pValue < 0) {
179 1
            throw new \Exception("Invalid value should be more than 0.");
180
        }
181 8
        $this->level = $pValue;
182
183 8
        return $this;
184
    }
185
186
    /**
187
     * Get indent
188
     *
189
     * @return int
190
     */
191 75
    public function getIndent()
192
    {
193 75
        return $this->indent;
194
    }
195
196
    /**
197
     * Set indent
198
     *
199
     * @param  int                           $pValue
200
     * @return \PhpOffice\PhpPresentation\Style\Alignment
201
     */
202 8
    public function setIndent($pValue = 0)
203
    {
204 8
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
205 1
            $pValue = 0; // indent not supported
206
        }
207
208 8
        $this->indent = $pValue;
209
210 8
        return $this;
211
    }
212
213
    /**
214
     * Get margin left
215
     *
216
     * @return int
217
     */
218 73
    public function getMarginLeft()
219
    {
220 73
        return $this->marginLeft;
221
    }
222
223
    /**
224
     * Set margin left
225
     *
226
     * @param  int                           $pValue
227
     * @return \PhpOffice\PhpPresentation\Style\Alignment
228
     */
229 8
    public function setMarginLeft($pValue = 0)
230
    {
231 8
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
232 1
            $pValue = 0; // margin left not supported
233
        }
234
235 8
        $this->marginLeft = $pValue;
236
237 8
        return $this;
238
    }
239
240
    /**
241
     * Get margin right
242
     *
243
     * @return int
244
     */
245 58
    public function getMarginRight()
246
    {
247 58
        return $this->marginRight;
248
    }
249
250
    /**
251
     * Set margin ight
252
     *
253
     * @param  int                           $pValue
254
     * @return \PhpOffice\PhpPresentation\Style\Alignment
255
     */
256 4
    public function setMarginRight($pValue = 0)
257
    {
258 4
        if ($pValue > 0 && !in_array($this->getHorizontal(), $this->supportedStyles)) {
259 1
            $pValue = 0; // margin right not supported
260
        }
261
262 4
        $this->marginRight = $pValue;
263
264 4
        return $this;
265
    }
266
267
    /**
268
     * Get hash code
269
     *
270
     * @return string Hash code
271
     */
272 46
    public function getHashCode()
273
    {
274 46
        return md5(
275 46
            $this->horizontal
276 46
            . $this->vertical
277 46
            . $this->level
278 46
            . $this->indent
279 46
            . $this->marginLeft
280 46
            . $this->marginRight
281 46
            . __CLASS__
282
        );
283
    }
284
285
    /**
286
     * Get hash index
287
     *
288
     * Note that this index may vary during script execution! Only reliable moment is
289
     * while doing a write of a workbook and when changes are not allowed.
290
     *
291
     * @return string Hash index
292
     */
293 1
    public function getHashIndex()
294
    {
295 1
        return $this->hashIndex;
296
    }
297
298
    /**
299
     * Set hash index
300
     *
301
     * Note that this index may vary during script execution! Only reliable moment is
302
     * while doing a write of a workbook and when changes are not allowed.
303
     *
304
     * @param string $value Hash index
305
     */
306 1
    public function setHashIndex($value)
307
    {
308 1
        $this->hashIndex = $value;
309 1
    }
310
}
311