Failed Conditions
Push — master ( 7635b3...69fc93 )
by Adrien
36s queued 21s
created

GridLines::activateObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: Wiktor Trzonkowski
8
 * Date: 7/2/14
9
 * Time: 2:36 PM.
10
 */
11
class GridLines extends Properties
12
{
13
    /**
14
     * Properties of Class:
15
     * Object State (State for Minor Tick Mark) @var bool
16
     * Line Properties @var  array of mixed
17
     * Shadow Properties @var  array of mixed
18
     * Glow Properties @var  array of mixed
19
     * Soft Properties @var  array of mixed.
20
     */
21
    private $objectState = false;
22
23
    private $lineProperties = [
24
        'color' => [
25
            'type' => self::EXCEL_COLOR_TYPE_STANDARD,
26
            'value' => null,
27
            'alpha' => 0,
28
        ],
29
        'style' => [
30
            'width' => '9525',
31
            'compound' => self::LINE_STYLE_COMPOUND_SIMPLE,
32
            'dash' => self::LINE_STYLE_DASH_SOLID,
33
            'cap' => self::LINE_STYLE_CAP_FLAT,
34
            'join' => self::LINE_STYLE_JOIN_BEVEL,
35
            'arrow' => [
36
                'head' => [
37
                    'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
38
                    'size' => self::LINE_STYLE_ARROW_SIZE_5,
39
                ],
40
                'end' => [
41
                    'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
42
                    'size' => self::LINE_STYLE_ARROW_SIZE_8,
43
                ],
44
            ],
45
        ],
46
    ];
47
48
    private $shadowProperties = [
49
        'presets' => self::SHADOW_PRESETS_NOSHADOW,
50
        'effect' => null,
51
        'color' => [
52
            'type' => self::EXCEL_COLOR_TYPE_STANDARD,
53
            'value' => 'black',
54
            'alpha' => 85,
55
        ],
56
        'size' => [
57
            'sx' => null,
58
            'sy' => null,
59
            'kx' => null,
60
        ],
61
        'blur' => null,
62
        'direction' => null,
63
        'distance' => null,
64
        'algn' => null,
65
        'rotWithShape' => null,
66
    ];
67
68
    private $glowProperties = [
69
        'size' => null,
70
        'color' => [
71
            'type' => self::EXCEL_COLOR_TYPE_STANDARD,
72
            'value' => 'black',
73
            'alpha' => 40,
74
        ],
75
    ];
76
77
    private $softEdges = [
78
        'size' => null,
79
    ];
80
81
    /**
82
     * Get Object State.
83
     *
84
     * @return bool
85
     */
86 13
    public function getObjectState()
87
    {
88 13
        return $this->objectState;
89
    }
90
91
    /**
92
     * Change Object State to True.
93
     *
94
     * @return $this
95
     */
96
    private function activateObject()
97
    {
98
        $this->objectState = true;
99
100
        return $this;
101
    }
102
103
    /**
104
     * Set Line Color Properties.
105
     *
106
     * @param string $value
107
     * @param int $alpha
108
     * @param string $colorType
109
     */
110
    public function setLineColorProperties($value, $alpha = 0, $colorType = self::EXCEL_COLOR_TYPE_STANDARD): void
111
    {
112
        $this->activateObject()
113
            ->lineProperties['color'] = $this->setColorProperties(
114
                $value,
115
                $alpha,
116
                $colorType
117
            );
118
    }
119
120
    /**
121
     * Set Line Color Properties.
122
     *
123
     * @param float $lineWidth
124
     * @param string $compoundType
125
     * @param string $dashType
126
     * @param string $capType
127
     * @param string $joinType
128
     * @param string $headArrowType
129
     * @param string $headArrowSize
130
     * @param string $endArrowType
131
     * @param string $endArrowSize
132
     */
133
    public function setLineStyleProperties($lineWidth = null, $compoundType = null, $dashType = null, $capType = null, $joinType = null, $headArrowType = null, $headArrowSize = null, $endArrowType = null, $endArrowSize = null): void
134
    {
135
        $this->activateObject();
136
        ($lineWidth !== null)
137
                ? $this->lineProperties['style']['width'] = $this->getExcelPointsWidth((float) $lineWidth)
138
                : null;
139
        ($compoundType !== null)
140
                ? $this->lineProperties['style']['compound'] = (string) $compoundType
141
                : null;
142
        ($dashType !== null)
143
                ? $this->lineProperties['style']['dash'] = (string) $dashType
144
                : null;
145
        ($capType !== null)
146
                ? $this->lineProperties['style']['cap'] = (string) $capType
147
                : null;
148
        ($joinType !== null)
149
                ? $this->lineProperties['style']['join'] = (string) $joinType
150
                : null;
151
        ($headArrowType !== null)
152
                ? $this->lineProperties['style']['arrow']['head']['type'] = (string) $headArrowType
153
                : null;
154
        ($headArrowSize !== null)
155
                ? $this->lineProperties['style']['arrow']['head']['size'] = (string) $headArrowSize
156
                : null;
157
        ($endArrowType !== null)
158
                ? $this->lineProperties['style']['arrow']['end']['type'] = (string) $endArrowType
159
                : null;
160
        ($endArrowSize !== null)
161
                ? $this->lineProperties['style']['arrow']['end']['size'] = (string) $endArrowSize
162
                : null;
163
    }
164
165
    /**
166
     * Get Line Color Property.
167
     *
168
     * @param string $propertyName
169
     *
170
     * @return string
171
     */
172 13
    public function getLineColorProperty($propertyName)
173
    {
174 13
        return $this->lineProperties['color'][$propertyName];
175
    }
176
177
    /**
178
     * Get Line Style Property.
179
     *
180
     * @param array|string $elements
181
     *
182
     * @return string
183
     */
184
    public function getLineStyleProperty($elements)
185
    {
186
        return $this->getArrayElementsValue($this->lineProperties['style'], $elements);
187
    }
188
189
    /**
190
     * Set Glow Properties.
191
     *
192
     * @param float $size
193
     * @param string $colorValue
194
     * @param int $colorAlpha
195
     * @param string $colorType
196
     */
197
    public function setGlowProperties($size, $colorValue = null, $colorAlpha = null, $colorType = null): void
198
    {
199
        $this
200
            ->activateObject()
201
            ->setGlowSize($size)
202
            ->setGlowColor($colorValue, $colorAlpha, $colorType);
203
    }
204
205
    /**
206
     * Get Glow Color Property.
207
     *
208
     * @param string $propertyName
209
     *
210
     * @return string
211
     */
212
    public function getGlowColor($propertyName)
213
    {
214
        return $this->glowProperties['color'][$propertyName];
215
    }
216
217
    /**
218
     * Get Glow Size.
219
     *
220
     * @return string
221
     */
222 13
    public function getGlowSize()
223
    {
224 13
        return $this->glowProperties['size'];
225
    }
226
227
    /**
228
     * Set Glow Size.
229
     *
230
     * @param float $size
231
     *
232
     * @return $this
233
     */
234
    private function setGlowSize($size)
235
    {
236
        $this->glowProperties['size'] = $this->getExcelPointsWidth((float) $size);
237
238
        return $this;
239
    }
240
241
    /**
242
     * Set Glow Color.
243
     *
244
     * @param string $color
245
     * @param int $alpha
246
     * @param string $colorType
247
     *
248
     * @return $this
249
     */
250
    private function setGlowColor($color, $alpha, $colorType)
251
    {
252
        if ($color !== null) {
0 ignored issues
show
introduced by
The condition $color !== null is always true.
Loading history...
253
            $this->glowProperties['color']['value'] = (string) $color;
254
        }
255
        if ($alpha !== null) {
0 ignored issues
show
introduced by
The condition $alpha !== null is always true.
Loading history...
256
            $this->glowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
257
        }
258
        if ($colorType !== null) {
0 ignored issues
show
introduced by
The condition $colorType !== null is always true.
Loading history...
259
            $this->glowProperties['color']['type'] = (string) $colorType;
260
        }
261
262
        return $this;
263
    }
264
265
    /**
266
     * Get Line Style Arrow Parameters.
267
     *
268
     * @param string $arrowSelector
269
     * @param string $propertySelector
270
     *
271
     * @return string
272
     */
273
    public function getLineStyleArrowParameters($arrowSelector, $propertySelector)
274
    {
275
        return $this->getLineStyleArrowSize($this->lineProperties['style']['arrow'][$arrowSelector]['size'], $propertySelector);
276
    }
277
278
    /**
279
     * Set Shadow Properties.
280
     *
281
     * @param int $presets
282
     * @param string $colorValue
283
     * @param string $colorType
284
     * @param string $colorAlpha
285
     * @param string $blur
286
     * @param int $angle
287
     * @param float $distance
288
     */
289
    public function setShadowProperties($presets, $colorValue = null, $colorType = null, $colorAlpha = null, $blur = null, $angle = null, $distance = null): void
290
    {
291
        $this->activateObject()
292
            ->setShadowPresetsProperties((int) $presets)
293
            ->setShadowColor(
294
                $colorValue ?? $this->shadowProperties['color']['value'],
295
                $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha),
1 ignored issue
show
Bug introduced by
It seems like $colorAlpha === null ? (...tTrueAlpha($colorAlpha) can also be of type string; however, parameter $alpha of PhpOffice\PhpSpreadsheet...Lines::setShadowColor() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

295
                /** @scrutinizer ignore-type */ $colorAlpha === null ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($colorAlpha),
Loading history...
296
                $colorType ?? $this->shadowProperties['color']['type']
297
            )
298
            ->setShadowBlur((float) $blur)
299
            ->setShadowAngle($angle)
300
            ->setShadowDistance($distance);
301
    }
302
303
    /**
304
     * Set Shadow Presets Properties.
305
     *
306
     * @param int $presets
307
     *
308
     * @return $this
309
     */
310
    private function setShadowPresetsProperties($presets)
311
    {
312
        $this->shadowProperties['presets'] = $presets;
313
        $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets));
314
315
        return $this;
316
    }
317
318
    /**
319
     * Set Shadow Properties Values.
320
     *
321
     * @param mixed $reference
322
     *
323
     * @return $this
324
     */
325
    private function setShadowPropertiesMapValues(array $propertiesMap, &$reference = null)
326
    {
327
        $base_reference = $reference;
328
        foreach ($propertiesMap as $property_key => $property_val) {
329
            if (is_array($property_val)) {
330
                if ($reference === null) {
331
                    $reference = &$this->shadowProperties[$property_key];
332
                } else {
333
                    $reference = &$reference[$property_key];
334
                }
335
                $this->setShadowPropertiesMapValues($property_val, $reference);
336
            } else {
337
                if ($base_reference === null) {
338
                    $this->shadowProperties[$property_key] = $property_val;
339
                } else {
340
                    $reference[$property_key] = $property_val;
341
                }
342
            }
343
        }
344
345
        return $this;
346
    }
347
348
    /**
349
     * Set Shadow Color.
350
     *
351
     * @param string $color
352
     * @param int $alpha
353
     * @param string $colorType
354
     *
355
     * @return $this
356
     */
357
    private function setShadowColor($color, $alpha, $colorType)
358
    {
359
        if ($color !== null) {
0 ignored issues
show
introduced by
The condition $color !== null is always true.
Loading history...
360
            $this->shadowProperties['color']['value'] = (string) $color;
361
        }
362
        if ($alpha !== null) {
0 ignored issues
show
introduced by
The condition $alpha !== null is always true.
Loading history...
363
            $this->shadowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
364
        }
365
        if ($colorType !== null) {
0 ignored issues
show
introduced by
The condition $colorType !== null is always true.
Loading history...
366
            $this->shadowProperties['color']['type'] = (string) $colorType;
367
        }
368
369
        return $this;
370
    }
371
372
    /**
373
     * Set Shadow Blur.
374
     *
375
     * @param float $blur
376
     *
377
     * @return $this
378
     */
379
    private function setShadowBlur($blur)
380
    {
381
        if ($blur !== null) {
0 ignored issues
show
introduced by
The condition $blur !== null is always true.
Loading history...
382
            $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
383
        }
384
385
        return $this;
386
    }
387
388
    /**
389
     * Set Shadow Angle.
390
     *
391
     * @param int $angle
392
     *
393
     * @return $this
394
     */
395
    private function setShadowAngle($angle)
396
    {
397
        if ($angle !== null) {
0 ignored issues
show
introduced by
The condition $angle !== null is always true.
Loading history...
398
            $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
399
        }
400
401
        return $this;
402
    }
403
404
    /**
405
     * Set Shadow Distance.
406
     *
407
     * @param float $distance
408
     *
409
     * @return $this
410
     */
411
    private function setShadowDistance($distance)
412
    {
413
        if ($distance !== null) {
0 ignored issues
show
introduced by
The condition $distance !== null is always true.
Loading history...
414
            $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
415
        }
416
417
        return $this;
418
    }
419
420
    /**
421
     * Get Shadow Property.
422
     *
423
     * @param string|string[] $elements
424
     *
425
     * @return string
426
     */
427 13
    public function getShadowProperty($elements)
428
    {
429 13
        return $this->getArrayElementsValue($this->shadowProperties, $elements);
430
    }
431
432
    /**
433
     * Set Soft Edges Size.
434
     *
435
     * @param float $size
436
     */
437
    public function setSoftEdgesSize($size): void
438
    {
439
        if ($size !== null) {
0 ignored issues
show
introduced by
The condition $size !== null is always true.
Loading history...
440
            $this->activateObject();
441
            $this->softEdges['size'] = (string) $this->getExcelPointsWidth($size);
442
        }
443
    }
444
445
    /**
446
     * Get Soft Edges Size.
447
     *
448
     * @return string
449
     */
450 13
    public function getSoftEdgesSize()
451
    {
452 13
        return $this->softEdges['size'];
453
    }
454
}
455