Failed Conditions
Pull Request — master (#3876)
by Abdul Malik
22:45 queued 13:31
created

Properties   F

Complexity

Total Complexity 81

Size/Duplication

Total Lines 872
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 81
eloc 469
dl 0
loc 872
ccs 230
cts 230
cp 1
rs 2
c 1
b 0
f 0

How to fix   Complexity   

Complex Class

Complex classes like Properties often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Properties, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: nhw2h8s
8
 * Date: 7/2/14
9
 * Time: 5:45 PM.
10
 */
11
abstract class Properties
12
{
13
    public const AXIS_LABELS_LOW = 'low';
14
    public const AXIS_LABELS_HIGH = 'high';
15
    public const AXIS_LABELS_NEXT_TO = 'nextTo';
16
    public const AXIS_LABELS_NONE = 'none';
17
18
    public const TICK_MARK_NONE = 'none';
19
    public const TICK_MARK_INSIDE = 'in';
20
    public const TICK_MARK_OUTSIDE = 'out';
21
    public const TICK_MARK_CROSS = 'cross';
22
23
    public const HORIZONTAL_CROSSES_AUTOZERO = 'autoZero';
24
    public const HORIZONTAL_CROSSES_MAXIMUM = 'max';
25
26
    public const FORMAT_CODE_GENERAL = 'General';
27
    public const FORMAT_CODE_NUMBER = '#,##0.00';
28
    public const FORMAT_CODE_CURRENCY = '$#,##0.00';
29
    public const FORMAT_CODE_ACCOUNTING = '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)';
30
    public const FORMAT_CODE_DATE = 'm/d/yyyy';
31
    public const FORMAT_CODE_DATE_ISO8601 = 'yyyy-mm-dd';
32
    public const FORMAT_CODE_TIME = '[$-F400]h:mm:ss AM/PM';
33
    public const FORMAT_CODE_PERCENTAGE = '0.00%';
34
    public const FORMAT_CODE_FRACTION = '# ?/?';
35
    public const FORMAT_CODE_SCIENTIFIC = '0.00E+00';
36
    public const FORMAT_CODE_TEXT = '@';
37
    public const FORMAT_CODE_SPECIAL = '00000';
38
39
    public const ORIENTATION_NORMAL = 'minMax';
40
    public const ORIENTATION_REVERSED = 'maxMin';
41
42
    public const LINE_STYLE_COMPOUND_SIMPLE = 'sng';
43
    public const LINE_STYLE_COMPOUND_DOUBLE = 'dbl';
44
    public const LINE_STYLE_COMPOUND_THICKTHIN = 'thickThin';
45
    public const LINE_STYLE_COMPOUND_THINTHICK = 'thinThick';
46
    public const LINE_STYLE_COMPOUND_TRIPLE = 'tri';
47
    public const LINE_STYLE_DASH_SOLID = 'solid';
48
    public const LINE_STYLE_DASH_ROUND_DOT = 'sysDot';
49
    public const LINE_STYLE_DASH_SQUARE_DOT = 'sysDash';
50
    public const LINE_STYPE_DASH_DASH = 'dash';
51
    public const LINE_STYLE_DASH_DASH_DOT = 'dashDot';
52
    public const LINE_STYLE_DASH_LONG_DASH = 'lgDash';
53
    public const LINE_STYLE_DASH_LONG_DASH_DOT = 'lgDashDot';
54
    public const LINE_STYLE_DASH_LONG_DASH_DOT_DOT = 'lgDashDotDot';
55
    public const LINE_STYLE_CAP_SQUARE = 'sq';
56
    public const LINE_STYLE_CAP_ROUND = 'rnd';
57
    public const LINE_STYLE_CAP_FLAT = 'flat';
58
    public const LINE_STYLE_JOIN_ROUND = 'round';
59
    public const LINE_STYLE_JOIN_MITER = 'miter';
60
    public const LINE_STYLE_JOIN_BEVEL = 'bevel';
61
    public const LINE_STYLE_ARROW_TYPE_NOARROW = null;
62
    public const LINE_STYLE_ARROW_TYPE_ARROW = 'triangle';
63
    public const LINE_STYLE_ARROW_TYPE_OPEN = 'arrow';
64
    public const LINE_STYLE_ARROW_TYPE_STEALTH = 'stealth';
65
    public const LINE_STYLE_ARROW_TYPE_DIAMOND = 'diamond';
66
    public const LINE_STYLE_ARROW_TYPE_OVAL = 'oval';
67
    public const LINE_STYLE_ARROW_SIZE_1 = 1;
68
    public const LINE_STYLE_ARROW_SIZE_2 = 2;
69
    public const LINE_STYLE_ARROW_SIZE_3 = 3;
70
    public const LINE_STYLE_ARROW_SIZE_4 = 4;
71
    public const LINE_STYLE_ARROW_SIZE_5 = 5;
72
    public const LINE_STYLE_ARROW_SIZE_6 = 6;
73
    public const LINE_STYLE_ARROW_SIZE_7 = 7;
74
    public const LINE_STYLE_ARROW_SIZE_8 = 8;
75
    public const LINE_STYLE_ARROW_SIZE_9 = 9;
76
77
    public const SHADOW_PRESETS_NOSHADOW = null;
78
    public const SHADOW_PRESETS_OUTER_BOTTTOM_RIGHT = 1;
79
    public const SHADOW_PRESETS_OUTER_BOTTOM = 2;
80
    public const SHADOW_PRESETS_OUTER_BOTTOM_LEFT = 3;
81
    public const SHADOW_PRESETS_OUTER_RIGHT = 4;
82
    public const SHADOW_PRESETS_OUTER_CENTER = 5;
83
    public const SHADOW_PRESETS_OUTER_LEFT = 6;
84
    public const SHADOW_PRESETS_OUTER_TOP_RIGHT = 7;
85
    public const SHADOW_PRESETS_OUTER_TOP = 8;
86
    public const SHADOW_PRESETS_OUTER_TOP_LEFT = 9;
87
    public const SHADOW_PRESETS_INNER_BOTTTOM_RIGHT = 10;
88
    public const SHADOW_PRESETS_INNER_BOTTOM = 11;
89
    public const SHADOW_PRESETS_INNER_BOTTOM_LEFT = 12;
90
    public const SHADOW_PRESETS_INNER_RIGHT = 13;
91
    public const SHADOW_PRESETS_INNER_CENTER = 14;
92
    public const SHADOW_PRESETS_INNER_LEFT = 15;
93
    public const SHADOW_PRESETS_INNER_TOP_RIGHT = 16;
94
    public const SHADOW_PRESETS_INNER_TOP = 17;
95
    public const SHADOW_PRESETS_INNER_TOP_LEFT = 18;
96
    public const SHADOW_PRESETS_PERSPECTIVE_BELOW = 19;
97
    public const SHADOW_PRESETS_PERSPECTIVE_UPPER_RIGHT = 20;
98
    public const SHADOW_PRESETS_PERSPECTIVE_UPPER_LEFT = 21;
99
    public const SHADOW_PRESETS_PERSPECTIVE_LOWER_RIGHT = 22;
100
    public const SHADOW_PRESETS_PERSPECTIVE_LOWER_LEFT = 23;
101
102
    public const POINTS_WIDTH_MULTIPLIER = 12700;
103
    public const ANGLE_MULTIPLIER = 60000; // direction and size-kx size-ky
104
    public const PERCENTAGE_MULTIPLIER = 100000; // size sx and sy
105
106
    protected bool $objectState = false; // used only for minor gridlines
107
108
    /** @var ?float */
109
    protected ?float $glowSize = null;
110
111
    protected ChartColor $glowColor;
112
113
    protected array $softEdges = [
114
        'size' => null,
115
    ];
116
117
    protected array $shadowProperties = self::PRESETS_OPTIONS[0];
118
119
    protected ChartColor $shadowColor;
120
121 133
    public function __construct()
122
    {
123 133
        $this->lineColor = new ChartColor();
124 133
        $this->glowColor = new ChartColor();
125 133
        $this->shadowColor = new ChartColor();
126 133
        $this->shadowColor->setType(ChartColor::EXCEL_COLOR_TYPE_STANDARD);
127 133
        $this->shadowColor->setValue('black');
128 133
        $this->shadowColor->setAlpha(40);
129
    }
130
131
    /**
132
     * Get Object State.
133
     */
134 8
    public function getObjectState(): bool
135
    {
136 8
        return $this->objectState;
137
    }
138
139
    /**
140
     * Change Object State to True.
141
     *
142
     * @return $this
143
     */
144 83
    public function activateObject()
145
    {
146 83
        $this->objectState = true;
147
148 83
        return $this;
149
    }
150
151 47
    public static function pointsToXml(float $width): string
152
    {
153 47
        return (string) (int) ($width * self::POINTS_WIDTH_MULTIPLIER);
154
    }
155
156 51
    public static function xmlToPoints(string $width): float
157
    {
158 51
        return ((float) $width) / self::POINTS_WIDTH_MULTIPLIER;
159
    }
160
161 16
    public static function angleToXml(float $angle): string
162
    {
163 16
        return (string) (int) ($angle * self::ANGLE_MULTIPLIER);
164
    }
165
166 14
    public static function xmlToAngle(string $angle): float
167
    {
168 14
        return ((float) $angle) / self::ANGLE_MULTIPLIER;
169
    }
170
171 2
    public static function tenthOfPercentToXml(float $value): string
172
    {
173 2
        return (string) (int) ($value * self::PERCENTAGE_MULTIPLIER);
174
    }
175
176 1
    public static function xmlToTenthOfPercent(string $value): float
177
    {
178 1
        return ((float) $value) / self::PERCENTAGE_MULTIPLIER;
179
    }
180
181 13
    protected function setColorProperties(?string $color, null|float|int|string $alpha, ?string $colorType): array
182
    {
183 13
        return [
184 13
            'type' => $colorType,
185 13
            'value' => $color,
186 13
            'alpha' => ($alpha === null) ? null : (int) $alpha,
187 13
        ];
188
    }
189
190
    protected const PRESETS_OPTIONS = [
191
        //NONE
192
        0 => [
193
            'presets' => self::SHADOW_PRESETS_NOSHADOW,
194
            'effect' => null,
195
            //'color' => [
196
            //    'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD,
197
            //    'value' => 'black',
198
            //    'alpha' => 40,
199
            //],
200
            'size' => [
201
                'sx' => null,
202
                'sy' => null,
203
                'kx' => null,
204
                'ky' => null,
205
            ],
206
            'blur' => null,
207
            'direction' => null,
208
            'distance' => null,
209
            'algn' => null,
210
            'rotWithShape' => null,
211
        ],
212
        //OUTER
213
        1 => [
214
            'effect' => 'outerShdw',
215
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
216
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
217
            'direction' => 2_700_000 / self::ANGLE_MULTIPLIER,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting ',' or ']' on line 217 at column 28
Loading history...
218
            'algn' => 'tl',
219
            'rotWithShape' => '0',
220
        ],
221
        2 => [
222
            'effect' => 'outerShdw',
223
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
224
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
225
            'direction' => 5_400_000 / self::ANGLE_MULTIPLIER,
226
            'algn' => 't',
227
            'rotWithShape' => '0',
228
        ],
229
        3 => [
230
            'effect' => 'outerShdw',
231
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
232
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
233
            'direction' => 8_100_000 / self::ANGLE_MULTIPLIER,
234
            'algn' => 'tr',
235
            'rotWithShape' => '0',
236
        ],
237
        4 => [
238
            'effect' => 'outerShdw',
239
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
240
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
241
            'algn' => 'l',
242
            'rotWithShape' => '0',
243
        ],
244
        5 => [
245
            'effect' => 'outerShdw',
246
            'size' => [
247
                'sx' => 102000 / self::PERCENTAGE_MULTIPLIER,
248
                'sy' => 102000 / self::PERCENTAGE_MULTIPLIER,
249
            ],
250
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
251
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
252
            'algn' => 'ctr',
253
            'rotWithShape' => '0',
254
        ],
255
        6 => [
256
            'effect' => 'outerShdw',
257
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
258
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
259
            'direction' => 10_800_000 / self::ANGLE_MULTIPLIER,
260
            'algn' => 'r',
261
            'rotWithShape' => '0',
262
        ],
263
        7 => [
264
            'effect' => 'outerShdw',
265
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
266
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
267
            'direction' => 18_900_000 / self::ANGLE_MULTIPLIER,
268
            'algn' => 'bl',
269
            'rotWithShape' => '0',
270
        ],
271
        8 => [
272
            'effect' => 'outerShdw',
273
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
274
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
275
            'direction' => 16_200_000 / self::ANGLE_MULTIPLIER,
276
            'rotWithShape' => '0',
277
        ],
278
        9 => [
279
            'effect' => 'outerShdw',
280
            'blur' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
281
            'distance' => 38100 / self::POINTS_WIDTH_MULTIPLIER,
282
            'direction' => 13_500_000 / self::ANGLE_MULTIPLIER,
283
            'algn' => 'br',
284
            'rotWithShape' => '0',
285
        ],
286
        //INNER
287
        10 => [
288
            'effect' => 'innerShdw',
289
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
290
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
291
            'direction' => 2_700_000 / self::ANGLE_MULTIPLIER,
292
        ],
293
        11 => [
294
            'effect' => 'innerShdw',
295
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
296
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
297
            'direction' => 5_400_000 / self::ANGLE_MULTIPLIER,
298
        ],
299
        12 => [
300
            'effect' => 'innerShdw',
301
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
302
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
303
            'direction' => 8_100_000 / self::ANGLE_MULTIPLIER,
304
        ],
305
        13 => [
306
            'effect' => 'innerShdw',
307
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
308
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
309
        ],
310
        14 => [
311
            'effect' => 'innerShdw',
312
            'blur' => 114300 / self::POINTS_WIDTH_MULTIPLIER,
313
        ],
314
        15 => [
315
            'effect' => 'innerShdw',
316
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
317
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
318
            'direction' => 10_800_000 / self::ANGLE_MULTIPLIER,
319
        ],
320
        16 => [
321
            'effect' => 'innerShdw',
322
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
323
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
324
            'direction' => 18_900_000 / self::ANGLE_MULTIPLIER,
325
        ],
326
        17 => [
327
            'effect' => 'innerShdw',
328
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
329
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
330
            'direction' => 16_200_000 / self::ANGLE_MULTIPLIER,
331
        ],
332
        18 => [
333
            'effect' => 'innerShdw',
334
            'blur' => 63500 / self::POINTS_WIDTH_MULTIPLIER,
335
            'distance' => 50800 / self::POINTS_WIDTH_MULTIPLIER,
336
            'direction' => 13_500_000 / self::ANGLE_MULTIPLIER,
337
        ],
338
        //perspective
339
        19 => [
340
            'effect' => 'outerShdw',
341
            'blur' => 152400 / self::POINTS_WIDTH_MULTIPLIER,
342
            'distance' => 317500 / self::POINTS_WIDTH_MULTIPLIER,
343
            'size' => [
344
                'sx' => 90000 / self::PERCENTAGE_MULTIPLIER,
345
                'sy' => -19000 / self::PERCENTAGE_MULTIPLIER,
346
            ],
347
            'direction' => 5_400_000 / self::ANGLE_MULTIPLIER,
348
            'rotWithShape' => '0',
349
        ],
350
        20 => [
351
            'effect' => 'outerShdw',
352
            'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
353
            'direction' => 18_900_000 / self::ANGLE_MULTIPLIER,
354
            'size' => [
355
                'sy' => 23000 / self::PERCENTAGE_MULTIPLIER,
356
                'kx' => -1_200_000 / self::ANGLE_MULTIPLIER,
357
            ],
358
            'algn' => 'bl',
359
            'rotWithShape' => '0',
360
        ],
361
        21 => [
362
            'effect' => 'outerShdw',
363
            'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
364
            'direction' => 13_500_000 / self::ANGLE_MULTIPLIER,
365
            'size' => [
366
                'sy' => 23000 / self::PERCENTAGE_MULTIPLIER,
367
                'kx' => 1_200_000 / self::ANGLE_MULTIPLIER,
368
            ],
369
            'algn' => 'br',
370
            'rotWithShape' => '0',
371
        ],
372
        22 => [
373
            'effect' => 'outerShdw',
374
            'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
375
            'distance' => 12700 / self::POINTS_WIDTH_MULTIPLIER,
376
            'direction' => 2_700_000 / self::ANGLE_MULTIPLIER,
377
            'size' => [
378
                'sy' => -23000 / self::PERCENTAGE_MULTIPLIER,
379
                'kx' => -800400 / self::ANGLE_MULTIPLIER,
380
            ],
381
            'algn' => 'bl',
382
            'rotWithShape' => '0',
383
        ],
384
        23 => [
385
            'effect' => 'outerShdw',
386
            'blur' => 76200 / self::POINTS_WIDTH_MULTIPLIER,
387
            'distance' => 12700 / self::POINTS_WIDTH_MULTIPLIER,
388
            'direction' => 8_100_000 / self::ANGLE_MULTIPLIER,
389
            'size' => [
390
                'sy' => -23000 / self::PERCENTAGE_MULTIPLIER,
391
                'kx' => 800400 / self::ANGLE_MULTIPLIER,
392
            ],
393
            'algn' => 'br',
394
            'rotWithShape' => '0',
395
        ],
396
    ];
397
398 11
    protected function getShadowPresetsMap(int $presetsOption): array
399
    {
400 11
        return self::PRESETS_OPTIONS[$presetsOption] ?? self::PRESETS_OPTIONS[0];
401
    }
402
403
    /**
404
     * Get value of array element.
405
     */
406 95
    protected function getArrayElementsValue(array $properties, array|int|string $elements): mixed
407
    {
408 95
        $reference = &$properties;
409 95
        if (!is_array($elements)) {
410 95
            return $reference[$elements];
411
        }
412
413 86
        foreach ($elements as $keys) {
414 86
            $reference = &$reference[$keys];
415
        }
416
417 86
        return $reference;
418
    }
419
420
    /**
421
     * Set Glow Properties.
422
     */
423 10
    public function setGlowProperties(float $size, ?string $colorValue = null, ?int $colorAlpha = null, ?string $colorType = null): void
424
    {
425 10
        $this
426 10
            ->activateObject()
427 10
            ->setGlowSize($size);
428 10
        $this->glowColor->setColorPropertiesArray(
429 10
            [
430 10
                'value' => $colorValue,
431 10
                'type' => $colorType,
432 10
                'alpha' => $colorAlpha,
433 10
            ]
434 10
        );
435
    }
436
437
    /**
438
     * Get Glow Property.
439
     */
440 86
    public function getGlowProperty(array|string $property): null|array|float|int|string
441
    {
442 86
        $retVal = null;
443 86
        if ($property === 'size') {
444 86
            $retVal = $this->glowSize;
445 6
        } elseif ($property === 'color') {
446 5
            $retVal = [
447 5
                'value' => $this->glowColor->getColorProperty('value'),
448 5
                'type' => $this->glowColor->getColorProperty('type'),
449 5
                'alpha' => $this->glowColor->getColorProperty('alpha'),
450 5
            ];
451 2
        } elseif (is_array($property) && count($property) >= 2 && $property[0] === 'color') {
452 2
            $retVal = $this->glowColor->getColorProperty($property[1]);
453
        }
454
455 86
        return $retVal;
456
    }
457
458
    /**
459
     * Get Glow Color Property.
460
     */
461 1
    public function getGlowColor(string $propertyName): null|int|string
462
    {
463 1
        return $this->glowColor->getColorProperty($propertyName);
464
    }
465
466 8
    public function getGlowColorObject(): ChartColor
467
    {
468 8
        return $this->glowColor;
469
    }
470
471
    /**
472
     * Get Glow Size.
473
     */
474 2
    public function getGlowSize(): ?float
475
    {
476 2
        return $this->glowSize;
477
    }
478
479
    /**
480
     * Set Glow Size.
481
     *
482
     * @return $this
483
     */
484 10
    protected function setGlowSize(?float $size)
485
    {
486 10
        $this->glowSize = $size;
487
488 10
        return $this;
489
    }
490
491
    /**
492
     * Set Soft Edges Size.
493
     */
494 2
    public function setSoftEdges(?float $size): void
495
    {
496 2
        if ($size !== null) {
497 2
            $this->activateObject();
498 2
            $this->softEdges['size'] = $size;
499
        }
500
    }
501
502
    /**
503
     * Get Soft Edges Size.
504
     */
505 86
    public function getSoftEdgesSize(): ?float
506
    {
507 86
        return $this->softEdges['size'];
508
    }
509
510 8
    public function setShadowProperty(string $propertyName, mixed $value): self
511
    {
512 8
        $this->activateObject();
513 8
        if ($propertyName === 'color' && is_array($value)) {
514 8
            $this->shadowColor->setColorPropertiesArray($value);
515
        } else {
516 8
            $this->shadowProperties[$propertyName] = $value;
517
        }
518
519 8
        return $this;
520
    }
521
522
    /**
523
     * Set Shadow Properties.
524
     */
525 11
    public function setShadowProperties(int $presets, ?string $colorValue = null, ?string $colorType = null, null|float|int|string $colorAlpha = null, ?float $blur = null, ?int $angle = null, ?float $distance = null): void
526
    {
527 11
        $this->activateObject()->setShadowPresetsProperties((int) $presets);
528 11
        if ($presets === 0) {
529 1
            $this->shadowColor->setType(ChartColor::EXCEL_COLOR_TYPE_STANDARD);
530 1
            $this->shadowColor->setValue('black');
531 1
            $this->shadowColor->setAlpha(40);
532
        }
533 11
        if ($colorValue !== null) {
534 2
            $this->shadowColor->setValue($colorValue);
535
        }
536 11
        if ($colorType !== null) {
537 2
            $this->shadowColor->setType($colorType);
538
        }
539 11
        if (is_numeric($colorAlpha)) {
540 2
            $this->shadowColor->setAlpha((int) $colorAlpha);
541
        }
542 11
        $this
543 11
            ->setShadowBlur($blur)
544 11
            ->setShadowAngle($angle)
545 11
            ->setShadowDistance($distance);
546
    }
547
548
    /**
549
     * Set Shadow Presets Properties.
550
     *
551
     * @return $this
552
     */
553 11
    protected function setShadowPresetsProperties(int $presets)
554
    {
555 11
        $this->shadowProperties['presets'] = $presets;
556 11
        $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets));
557
558 11
        return $this;
559
    }
560
561
    protected const SHADOW_ARRAY_KEYS = ['size', 'color'];
562
563
    /**
564
     * Set Shadow Properties Values.
565
     *
566
     * @return $this
567
     */
568 11
    protected function setShadowPropertiesMapValues(array $propertiesMap, ?array &$reference = null)
569
    {
570 11
        $base_reference = $reference;
571 11
        foreach ($propertiesMap as $property_key => $property_val) {
572 11
            if (is_array($property_val)) {
573 4
                if (in_array($property_key, self::SHADOW_ARRAY_KEYS, true)) {
574 4
                    $reference = &$this->shadowProperties[$property_key];
575 4
                    $this->setShadowPropertiesMapValues($property_val, $reference);
576
                }
577
            } else {
578 11
                if ($base_reference === null) {
579 11
                    $this->shadowProperties[$property_key] = $property_val;
580
                } else {
581 4
                    $reference[$property_key] = $property_val;
582
                }
583
            }
584
        }
585
586 11
        return $this;
587
    }
588
589
    /**
590
     * Set Shadow Blur.
591
     *
592
     * @return $this
593
     */
594 11
    protected function setShadowBlur(?float $blur)
595
    {
596 11
        if ($blur !== null) {
597 2
            $this->shadowProperties['blur'] = $blur;
598
        }
599
600 11
        return $this;
601
    }
602
603
    /**
604
     * Set Shadow Angle.
605
     *
606
     * @return $this
607
     */
608 11
    protected function setShadowAngle(null|float|int|string $angle)
609
    {
610 11
        if (is_numeric($angle)) {
611 2
            $this->shadowProperties['direction'] = $angle;
612
        }
613
614 11
        return $this;
615
    }
616
617
    /**
618
     * Set Shadow Distance.
619
     *
620
     * @return $this
621
     */
622 11
    protected function setShadowDistance(?float $distance)
623
    {
624 11
        if ($distance !== null) {
625 2
            $this->shadowProperties['distance'] = $distance;
626
        }
627
628 11
        return $this;
629
    }
630
631 8
    public function getShadowColorObject(): ChartColor
632
    {
633 8
        return $this->shadowColor;
634
    }
635
636
    /**
637
     * Get Shadow Property.
638
     *
639
     * @param string|string[] $elements
640
     */
641 94
    public function getShadowProperty($elements): array|string|null
642
    {
643 94
        if ($elements === 'color') {
644 8
            return [
645 8
                'value' => $this->shadowColor->getValue(),
646 8
                'type' => $this->shadowColor->getType(),
647 8
                'alpha' => $this->shadowColor->getAlpha(),
648 8
            ];
649
        }
650
651 94
        return $this->getArrayElementsValue($this->shadowProperties, $elements);
652
    }
653
654 2
    public function getShadowArray(): array
655
    {
656 2
        $array = $this->shadowProperties;
657 2
        if ($this->getShadowColorObject()->isUsable()) {
658 2
            $array['color'] = $this->getShadowProperty('color');
659
        }
660
661 2
        return $array;
662
    }
663
664
    protected ChartColor $lineColor;
665
666
    protected array $lineStyleProperties = [
667
        'width' => null, //'9525',
668
        'compound' => '', //self::LINE_STYLE_COMPOUND_SIMPLE,
669
        'dash' => '', //self::LINE_STYLE_DASH_SOLID,
670
        'cap' => '', //self::LINE_STYLE_CAP_FLAT,
671
        'join' => '', //self::LINE_STYLE_JOIN_BEVEL,
672
        'arrow' => [
673
            'head' => [
674
                'type' => '', //self::LINE_STYLE_ARROW_TYPE_NOARROW,
675
                'size' => '', //self::LINE_STYLE_ARROW_SIZE_5,
676
                'w' => '',
677
                'len' => '',
678
            ],
679
            'end' => [
680
                'type' => '', //self::LINE_STYLE_ARROW_TYPE_NOARROW,
681
                'size' => '', //self::LINE_STYLE_ARROW_SIZE_8,
682
                'w' => '',
683
                'len' => '',
684
            ],
685
        ],
686
    ];
687
688 63
    public function copyLineStyles(self $otherProperties): void
689
    {
690 63
        $this->lineStyleProperties = $otherProperties->lineStyleProperties;
691 63
        $this->lineColor = $otherProperties->lineColor;
692 63
        $this->glowSize = $otherProperties->glowSize;
693 63
        $this->glowColor = $otherProperties->glowColor;
694 63
        $this->softEdges = $otherProperties->softEdges;
695 63
        $this->shadowProperties = $otherProperties->shadowProperties;
696
    }
697
698 100
    public function getLineColor(): ChartColor
699
    {
700 100
        return $this->lineColor;
701
    }
702
703
    /**
704
     * Set Line Color Properties.
705
     */
706 13
    public function setLineColorProperties(?string $value, ?int $alpha = null, ?string $colorType = null): void
707
    {
708 13
        $this->activateObject();
709 13
        $this->lineColor->setColorPropertiesArray(
710 13
            $this->setColorProperties(
711 13
                $value,
712 13
                $alpha,
713 13
                $colorType
714 13
            )
715 13
        );
716
    }
717
718
    /**
719
     * Get Line Color Property.
720
     */
721 8
    public function getLineColorProperty(string $propertyName): null|int|string
722
    {
723 8
        return $this->lineColor->getColorProperty($propertyName);
724
    }
725
726
    /**
727
     * Set Line Style Properties.
728
     */
729 71
    public function setLineStyleProperties(
730
        null|float|int|string $lineWidth = null,
731
        ?string $compoundType = '',
732
        ?string $dashType = '',
733
        ?string $capType = '',
734
        ?string $joinType = '',
735
        ?string $headArrowType = '',
736
        int $headArrowSize = 0,
737
        ?string $endArrowType = '',
738
        int $endArrowSize = 0,
739
        ?string $headArrowWidth = '',
740
        ?string $headArrowLength = '',
741
        ?string $endArrowWidth = '',
742
        ?string $endArrowLength = ''
743
    ): void {
744 71
        $this->activateObject();
745 71
        if (is_numeric($lineWidth)) {
746 52
            $this->lineStyleProperties['width'] = $lineWidth;
747
        }
748 71
        if ($compoundType !== '') {
749 71
            $this->lineStyleProperties['compound'] = $compoundType;
750
        }
751 71
        if ($dashType !== '') {
752 70
            $this->lineStyleProperties['dash'] = $dashType;
753
        }
754 71
        if ($capType !== '') {
755 71
            $this->lineStyleProperties['cap'] = $capType;
756
        }
757 71
        if ($joinType !== '') {
758 17
            $this->lineStyleProperties['join'] = $joinType;
759
        }
760 71
        if ($headArrowType !== '') {
761 70
            $this->lineStyleProperties['arrow']['head']['type'] = $headArrowType;
762
        }
763 71
        if (isset(self::ARROW_SIZES[$headArrowSize])) {
764 7
            $this->lineStyleProperties['arrow']['head']['size'] = $headArrowSize;
765 7
            $this->lineStyleProperties['arrow']['head']['w'] = self::ARROW_SIZES[$headArrowSize]['w'];
766 7
            $this->lineStyleProperties['arrow']['head']['len'] = self::ARROW_SIZES[$headArrowSize]['len'];
767
        }
768 71
        if ($endArrowType !== '') {
769 70
            $this->lineStyleProperties['arrow']['end']['type'] = $endArrowType;
770
        }
771 71
        if (isset(self::ARROW_SIZES[$endArrowSize])) {
772 7
            $this->lineStyleProperties['arrow']['end']['size'] = $endArrowSize;
773 7
            $this->lineStyleProperties['arrow']['end']['w'] = self::ARROW_SIZES[$endArrowSize]['w'];
774 7
            $this->lineStyleProperties['arrow']['end']['len'] = self::ARROW_SIZES[$endArrowSize]['len'];
775
        }
776 71
        if ($headArrowWidth !== '') {
777 67
            $this->lineStyleProperties['arrow']['head']['w'] = $headArrowWidth;
778
        }
779 71
        if ($headArrowLength !== '') {
780 67
            $this->lineStyleProperties['arrow']['head']['len'] = $headArrowLength;
781
        }
782 71
        if ($endArrowWidth !== '') {
783 66
            $this->lineStyleProperties['arrow']['end']['w'] = $endArrowWidth;
784
        }
785 71
        if ($endArrowLength !== '') {
786 66
            $this->lineStyleProperties['arrow']['end']['len'] = $endArrowLength;
787
        }
788
    }
789
790 1
    public function getLineStyleArray(): array
791
    {
792 1
        return $this->lineStyleProperties;
793
    }
794
795 1
    public function setLineStyleArray(array $lineStyleProperties = []): self
796
    {
797 1
        $this->activateObject();
798 1
        $this->lineStyleProperties['width'] = $lineStyleProperties['width'] ?? null;
799 1
        $this->lineStyleProperties['compound'] = $lineStyleProperties['compound'] ?? '';
800 1
        $this->lineStyleProperties['dash'] = $lineStyleProperties['dash'] ?? '';
801 1
        $this->lineStyleProperties['cap'] = $lineStyleProperties['cap'] ?? '';
802 1
        $this->lineStyleProperties['join'] = $lineStyleProperties['join'] ?? '';
803 1
        $this->lineStyleProperties['arrow']['head']['type'] = $lineStyleProperties['arrow']['head']['type'] ?? '';
804 1
        $this->lineStyleProperties['arrow']['head']['size'] = $lineStyleProperties['arrow']['head']['size'] ?? '';
805 1
        $this->lineStyleProperties['arrow']['head']['w'] = $lineStyleProperties['arrow']['head']['w'] ?? '';
806 1
        $this->lineStyleProperties['arrow']['head']['len'] = $lineStyleProperties['arrow']['head']['len'] ?? '';
807 1
        $this->lineStyleProperties['arrow']['end']['type'] = $lineStyleProperties['arrow']['end']['type'] ?? '';
808 1
        $this->lineStyleProperties['arrow']['end']['size'] = $lineStyleProperties['arrow']['end']['size'] ?? '';
809 1
        $this->lineStyleProperties['arrow']['end']['w'] = $lineStyleProperties['arrow']['end']['w'] ?? '';
810 1
        $this->lineStyleProperties['arrow']['end']['len'] = $lineStyleProperties['arrow']['end']['len'] ?? '';
811
812 1
        return $this;
813
    }
814
815 1
    public function setLineStyleProperty(string $propertyName, mixed $value): self
816
    {
817 1
        $this->activateObject();
818 1
        $this->lineStyleProperties[$propertyName] = $value;
819
820 1
        return $this;
821
    }
822
823
    /**
824
     * Get Line Style Property.
825
     */
826 87
    public function getLineStyleProperty(array|string $elements): ?string
827
    {
828 87
        return $this->getArrayElementsValue($this->lineStyleProperties, $elements);
829
    }
830
831
    protected const ARROW_SIZES = [
832
        1 => ['w' => 'sm', 'len' => 'sm'],
833
        2 => ['w' => 'sm', 'len' => 'med'],
834
        3 => ['w' => 'sm', 'len' => 'lg'],
835
        4 => ['w' => 'med', 'len' => 'sm'],
836
        5 => ['w' => 'med', 'len' => 'med'],
837
        6 => ['w' => 'med', 'len' => 'lg'],
838
        7 => ['w' => 'lg', 'len' => 'sm'],
839
        8 => ['w' => 'lg', 'len' => 'med'],
840
        9 => ['w' => 'lg', 'len' => 'lg'],
841
    ];
842
843
    /**
844
     * Get Line Style Arrow Size.
845
     */
846 2
    protected function getLineStyleArrowSize(int $arraySelector, string $arrayKaySelector): string
847
    {
848 2
        return self::ARROW_SIZES[$arraySelector][$arrayKaySelector] ?? '';
849
    }
850
851
    /**
852
     * Get Line Style Arrow Parameters.
853
     */
854 2
    public function getLineStyleArrowParameters(string $arrowSelector, string $propertySelector): string
855
    {
856 2
        return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector);
857
    }
858
859
    /**
860
     * Get Line Style Arrow Width.
861
     */
862 13
    public function getLineStyleArrowWidth(string $arrow): ?string
863
    {
864 13
        return $this->getLineStyleProperty(['arrow', $arrow, 'w']);
865
    }
866
867
    /**
868
     * Get Line Style Arrow Excel Length.
869
     */
870 13
    public function getLineStyleArrowLength(string $arrow): ?string
871
    {
872 13
        return $this->getLineStyleProperty(['arrow', $arrow, 'len']);
873
    }
874
875
    /**
876
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
877
     */
878 5
    public function __clone()
879
    {
880 5
        $this->lineColor = clone $this->lineColor;
881 5
        $this->glowColor = clone $this->glowColor;
882 5
        $this->shadowColor = clone $this->shadowColor;
883
    }
884
}
885