Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.06% covered (success)
97.06%
33 / 34
95.00% covered (success)
95.00%
19 / 20
CRAP
0.00% covered (danger)
0.00%
0 / 1
Shadow
97.06% covered (success)
97.06%
33 / 34
95.00% covered (success)
95.00%
19 / 20
22
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isVisible
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setVisible
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getBlurRadius
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setBlurRadius
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDistance
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDistance
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDirection
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDirection
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAlignment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAlignment
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getColor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setColor
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAlpha
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAlpha
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setType
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 getHashCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHashIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Style;
21
22use PhpOffice\PhpPresentation\ComparableInterface;
23use PhpOffice\PhpPresentation\Exception\NotAllowedValueException;
24
25/**
26 * \PhpOffice\PhpPresentation\Style\Shadow.
27 */
28class Shadow implements ComparableInterface
29{
30    public const TYPE_SHADOW_INNER = 'innerShdw';
31    public const TYPE_SHADOW_OUTER = 'outerShdw';
32    public const TYPE_REFLECTION = 'reflection';
33
34    // Shadow alignment
35    public const SHADOW_BOTTOM = 'b';
36    public const SHADOW_BOTTOM_LEFT = 'bl';
37    public const SHADOW_BOTTOM_RIGHT = 'br';
38    public const SHADOW_CENTER = 'ctr';
39    public const SHADOW_LEFT = 'l';
40    public const SHADOW_TOP = 't';
41    public const SHADOW_TOP_LEFT = 'tl';
42    public const SHADOW_TOP_RIGHT = 'tr';
43
44    /**
45     * Visible.
46     *
47     * @var bool
48     */
49    private $visible = false;
50
51    /**
52     * Blur radius.
53     *
54     * @var int
55     */
56    private $blurRadius = 6;
57
58    /**
59     * Shadow distance.
60     *
61     * @var int
62     */
63    private $distance = 2;
64
65    /**
66     * Shadow direction (in degrees).
67     *
68     * @var int
69     */
70    private $direction = 0;
71
72    /**
73     * Shadow alignment.
74     *
75     * @var string
76     */
77    private $alignment = self::SHADOW_BOTTOM_RIGHT;
78
79    /**
80     * @var null|Color
81     */
82    private $color;
83
84    /**
85     * @var int
86     */
87    private $alpha = 50;
88
89    /**
90     * @var string
91     */
92    private $type = self::TYPE_SHADOW_OUTER;
93
94    /**
95     * Hash index.
96     *
97     * @var int
98     */
99    private $hashIndex;
100
101    /**
102     * Create a new \PhpOffice\PhpPresentation\Style\Shadow.
103     */
104    public function __construct()
105    {
106        $this->color = new Color(Color::COLOR_BLACK);
107    }
108
109    /**
110     * Get Visible.
111     */
112    public function isVisible(): bool
113    {
114        return $this->visible;
115    }
116
117    /**
118     * Set Visible.
119     */
120    public function setVisible(bool $pValue = false): self
121    {
122        $this->visible = $pValue;
123
124        return $this;
125    }
126
127    /**
128     * Get Blur radius.
129     */
130    public function getBlurRadius(): int
131    {
132        return $this->blurRadius;
133    }
134
135    /**
136     * Set Blur radius.
137     */
138    public function setBlurRadius(int $pValue = 6): self
139    {
140        $this->blurRadius = $pValue;
141
142        return $this;
143    }
144
145    /**
146     * Get Shadow distance.
147     */
148    public function getDistance(): int
149    {
150        return $this->distance;
151    }
152
153    /**
154     * Set Shadow distance.
155     *
156     * @return $this
157     */
158    public function setDistance(int $pValue = 2): self
159    {
160        $this->distance = $pValue;
161
162        return $this;
163    }
164
165    /**
166     * Get Shadow direction (in degrees).
167     */
168    public function getDirection(): int
169    {
170        return $this->direction;
171    }
172
173    /**
174     * Set Shadow direction (in degrees).
175     */
176    public function setDirection(int $pValue = 0): self
177    {
178        $this->direction = $pValue;
179
180        return $this;
181    }
182
183    /**
184     * Get Shadow alignment.
185     */
186    public function getAlignment(): string
187    {
188        return $this->alignment;
189    }
190
191    /**
192     * Set Shadow alignment.
193     */
194    public function setAlignment(string $pValue = self::SHADOW_BOTTOM_RIGHT): self
195    {
196        $this->alignment = $pValue;
197
198        return $this;
199    }
200
201    /**
202     * Get Color.
203     */
204    public function getColor(): ?Color
205    {
206        return $this->color;
207    }
208
209    /**
210     * Set Color.
211     */
212    public function setColor(?Color $pValue = null): self
213    {
214        $this->color = $pValue;
215
216        return $this;
217    }
218
219    /**
220     * Get Alpha.
221     */
222    public function getAlpha(): int
223    {
224        return $this->alpha;
225    }
226
227    /**
228     * Set Alpha.
229     */
230    public function setAlpha(int $pValue = 0): self
231    {
232        $this->alpha = $pValue;
233
234        return $this;
235    }
236
237    /**
238     * Get Type.
239     */
240    public function getType(): string
241    {
242        return $this->type;
243    }
244
245    /**
246     * Set Type.
247     */
248    public function setType(string $pValue = self::TYPE_SHADOW_OUTER): self
249    {
250        if (!in_array(
251            $pValue,
252            [self::TYPE_REFLECTION, self::TYPE_SHADOW_INNER, self::TYPE_SHADOW_OUTER]
253        )) {
254            throw new NotAllowedValueException($pValue, [self::TYPE_REFLECTION, self::TYPE_SHADOW_INNER, self::TYPE_SHADOW_OUTER]);
255        }
256
257        $this->type = $pValue;
258
259        return $this;
260    }
261
262    /**
263     * Get hash code.
264     *
265     * @return string Hash code
266     */
267    public function getHashCode(): string
268    {
269        return md5(($this->visible ? 't' : 'f') . $this->blurRadius . $this->distance . $this->direction . $this->alignment . $this->type . $this->color->getHashCode() . $this->alpha . __CLASS__);
270    }
271
272    /**
273     * Get hash index.
274     *
275     * Note that this index may vary during script execution! Only reliable moment is
276     * while doing a write of a workbook and when changes are not allowed.
277     *
278     * @return null|int Hash index
279     */
280    public function getHashIndex(): ?int
281    {
282        return $this->hashIndex;
283    }
284
285    /**
286     * Set 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     * @param int $value Hash index
292     *
293     * @return $this
294     */
295    public function setHashIndex(int $value)
296    {
297        $this->hashIndex = $value;
298
299        return $this;
300    }
301}