Failed Conditions
Pull Request — master (#1694)
by Adrien
08:05
created

Axis::setAxisOptionsProperties()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
eloc 11
nc 1024
nop 10
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 132
rs 3.15
c 0
b 0
f 0

How to fix   Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: Wiktor Trzonkowski
8
 * Date: 6/17/14
9
 * Time: 12:11 PM.
10
 */
11
class Axis extends Properties
12
{
13
    /**
14
     * Axis Number.
15
     *
16
     * @var mixed[]
17
     */
18
    private $axisNumber = [
19
        'format' => self::FORMAT_CODE_GENERAL,
20
        'source_linked' => 1,
21
    ];
22
23
    /**
24
     * Axis Options.
25
     *
26
     * @var mixed[]
27
     */
28
    private $axisOptions = [
29
        'minimum' => null,
30
        'maximum' => null,
31
        'major_unit' => null,
32
        'minor_unit' => null,
33
        'orientation' => self::ORIENTATION_NORMAL,
34
        'minor_tick_mark' => self::TICK_MARK_NONE,
35
        'major_tick_mark' => self::TICK_MARK_NONE,
36
        'axis_labels' => self::AXIS_LABELS_NEXT_TO,
37
        'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
38
        'horizontal_crosses_value' => null,
39
    ];
40
41
    /**
42
     * Fill Properties.
43
     *
44
     * @var mixed[]
45
     */
46
    private $fillProperties = [
47
        'type' => self::EXCEL_COLOR_TYPE_ARGB,
48
        'value' => null,
49
        'alpha' => 0,
50
    ];
51
52
    /**
53
     * Line Properties.
54
     *
55
     * @var mixed[]
56
     */
57
    private $lineProperties = [
58
        'type' => self::EXCEL_COLOR_TYPE_ARGB,
59
        'value' => null,
60
        'alpha' => 0,
61
    ];
62
63
    /**
64
     * Line Style Properties.
65
     *
66
     * @var mixed[]
67
     */
68
    private $lineStyleProperties = [
69
        'width' => '9525',
70
        'compound' => self::LINE_STYLE_COMPOUND_SIMPLE,
71
        'dash' => self::LINE_STYLE_DASH_SOLID,
72
        'cap' => self::LINE_STYLE_CAP_FLAT,
73
        'join' => self::LINE_STYLE_JOIN_BEVEL,
74
        'arrow' => [
75
            'head' => [
76
                'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
77
                'size' => self::LINE_STYLE_ARROW_SIZE_5,
78
            ],
79
            'end' => [
80
                'type' => self::LINE_STYLE_ARROW_TYPE_NOARROW,
81
                'size' => self::LINE_STYLE_ARROW_SIZE_8,
82
            ],
83
        ],
84
    ];
85
86
    /**
87
     * Shadow Properties.
88
     *
89
     * @var mixed[]
90
     */
91
    private $shadowProperties = [
92
        'presets' => self::SHADOW_PRESETS_NOSHADOW,
93
        'effect' => null,
94
        'color' => [
95
            'type' => self::EXCEL_COLOR_TYPE_STANDARD,
96
            'value' => 'black',
97
            'alpha' => 40,
98
        ],
99
        'size' => [
100
            'sx' => null,
101
            'sy' => null,
102
            'kx' => null,
103
        ],
104
        'blur' => null,
105
        'direction' => null,
106
        'distance' => null,
107
        'algn' => null,
108
        'rotWithShape' => null,
109
    ];
110
111
    /**
112
     * Glow Properties.
113
     *
114
     * @var mixed[]
115
     */
116
    private $glowProperties = [
117
        'size' => null,
118
        'color' => [
119
            'type' => self::EXCEL_COLOR_TYPE_STANDARD,
120
            'value' => 'black',
121
            'alpha' => 40,
122
        ],
123
    ];
124
125
    /**
126
     * Soft Edge Properties.
127
     *
128
     * @var mixed[]
129
     */
130
    private $softEdges = [
131
        'size' => null,
132
    ];
133
134
    /**
135
     * Get Series Data Type.
136
     *
137
     * @param mixed $format_code
138
     */
139
    public function setAxisNumberProperties($format_code): void
140
    {
141
        $this->axisNumber['format'] = (string) $format_code;
142
        $this->axisNumber['source_linked'] = 0;
143
    }
144
145
    /**
146
     * Get Axis Number Format Data Type.
147
     *
148
     * @return string
149
     */
150 13
    public function getAxisNumberFormat()
151
    {
152 13
        return $this->axisNumber['format'];
153
    }
154
155
    /**
156
     * Get Axis Number Source Linked.
157
     *
158
     * @return string
159
     */
160 13
    public function getAxisNumberSourceLinked()
161
    {
162 13
        return (string) $this->axisNumber['source_linked'];
163
    }
164
165
    /**
166
     * Set Axis Options Properties.
167
     *
168
     * @param string $axisLabels
169
     * @param string $horizontalCrossesValue
170
     * @param string $horizontalCrosses
171
     * @param string $axisOrientation
172
     * @param string $majorTmt
173
     * @param string $minorTmt
174
     * @param string $minimum
175
     * @param string $maximum
176
     * @param string $majorUnit
177
     * @param string $minorUnit
178
     */
179
    public function setAxisOptionsProperties($axisLabels, $horizontalCrossesValue = null, $horizontalCrosses = null, $axisOrientation = null, $majorTmt = null, $minorTmt = null, $minimum = null, $maximum = null, $majorUnit = null, $minorUnit = null): void
180
    {
181
        $this->axisOptions['axis_labels'] = (string) $axisLabels;
182
        ($horizontalCrossesValue !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontalCrossesValue : null;
183
        ($horizontalCrosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontalCrosses : null;
184
        ($axisOrientation !== null) ? $this->axisOptions['orientation'] = (string) $axisOrientation : null;
185
        ($majorTmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $majorTmt : null;
186
        ($minorTmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minorTmt : null;
187
        ($minorTmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minorTmt : null;
188
        ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null;
189
        ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null;
190
        ($majorUnit !== null) ? $this->axisOptions['major_unit'] = (string) $majorUnit : null;
191
        ($minorUnit !== null) ? $this->axisOptions['minor_unit'] = (string) $minorUnit : null;
192
    }
193
194
    /**
195
     * Get Axis Options Property.
196
     *
197
     * @param string $property
198
     *
199
     * @return string
200
     */
201 13
    public function getAxisOptionsProperty($property)
202
    {
203 13
        return $this->axisOptions[$property];
204
    }
205
206
    /**
207
     * Set Axis Orientation Property.
208
     *
209
     * @param string $orientation
210
     */
211
    public function setAxisOrientation($orientation): void
212
    {
213
        $this->axisOptions['orientation'] = (string) $orientation;
214
    }
215
216
    /**
217
     * Set Fill Property.
218
     *
219
     * @param string $color
220
     * @param int $alpha
221
     * @param string $AlphaType
222
     */
223
    public function setFillParameters($color, $alpha = 0, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void
224
    {
225
        $this->fillProperties = $this->setColorProperties($color, $alpha, $AlphaType);
226
    }
227
228
    /**
229
     * Set Line Property.
230
     *
231
     * @param string $color
232
     * @param int $alpha
233
     * @param string $alphaType
234
     */
235
    public function setLineParameters($color, $alpha = 0, $alphaType = self::EXCEL_COLOR_TYPE_ARGB): void
236
    {
237
        $this->lineProperties = $this->setColorProperties($color, $alpha, $alphaType);
238
    }
239
240
    /**
241
     * Get Fill Property.
242
     *
243
     * @param string $property
244
     *
245
     * @return string
246
     */
247 13
    public function getFillProperty($property)
248
    {
249 13
        return $this->fillProperties[$property];
250
    }
251
252
    /**
253
     * Get Line Property.
254
     *
255
     * @param string $property
256
     *
257
     * @return string
258
     */
259 13
    public function getLineProperty($property)
260
    {
261 13
        return $this->lineProperties[$property];
262
    }
263
264
    /**
265
     * Set Line Style Properties.
266
     *
267
     * @param float $lineWidth
268
     * @param string $compoundType
269
     * @param string $dashType
270
     * @param string $capType
271
     * @param string $joinType
272
     * @param string $headArrowType
273
     * @param string $headArrowSize
274
     * @param string $endArrowType
275
     * @param string $endArrowSize
276
     */
277
    public function setLineStyleProperties($lineWidth = null, $compoundType = null, $dashType = null, $capType = null, $joinType = null, $headArrowType = null, $headArrowSize = null, $endArrowType = null, $endArrowSize = null): void
278
    {
279
        ($lineWidth !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $lineWidth) : null;
280
        ($compoundType !== null) ? $this->lineStyleProperties['compound'] = (string) $compoundType : null;
281
        ($dashType !== null) ? $this->lineStyleProperties['dash'] = (string) $dashType : null;
282
        ($capType !== null) ? $this->lineStyleProperties['cap'] = (string) $capType : null;
283
        ($joinType !== null) ? $this->lineStyleProperties['join'] = (string) $joinType : null;
284
        ($headArrowType !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $headArrowType : null;
285
        ($headArrowSize !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $headArrowSize : null;
286
        ($endArrowType !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $endArrowType : null;
287
        ($endArrowSize !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $endArrowSize : null;
288
    }
289
290
    /**
291
     * Get Line Style Property.
292
     *
293
     * @param array|string $elements
294
     *
295
     * @return string
296
     */
297 13
    public function getLineStyleProperty($elements)
298
    {
299 13
        return $this->getArrayElementsValue($this->lineStyleProperties, $elements);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getArrayEl...eProperties, $elements) also could return the type array<mixed,mixed> which is incompatible with the documented return type string.
Loading history...
300
    }
301
302
    /**
303
     * Get Line Style Arrow Excel Width.
304
     *
305
     * @param string $arrow
306
     *
307
     * @return string
308
     */
309
    public function getLineStyleArrowWidth($arrow)
310
    {
311
        return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w');
312
    }
313
314
    /**
315
     * Get Line Style Arrow Excel Length.
316
     *
317
     * @param string $arrow
318
     *
319
     * @return string
320
     */
321
    public function getLineStyleArrowLength($arrow)
322
    {
323
        return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len');
324
    }
325
326
    /**
327
     * Set Shadow Properties.
328
     *
329
     * @param int $shadowPresets
330
     * @param string $colorValue
331
     * @param string $colorType
332
     * @param string $colorAlpha
333
     * @param float $blur
334
     * @param int $angle
335
     * @param float $distance
336
     */
337
    public function setShadowProperties($shadowPresets, $colorValue = null, $colorType = null, $colorAlpha = null, $blur = null, $angle = null, $distance = null): void
338
    {
339
        $this->setShadowPresetsProperties((int) $shadowPresets)
340
            ->setShadowColor(
341
                $colorValue ?? $this->shadowProperties['color']['value'],
342
                $colorAlpha ?? (int) $this->shadowProperties['color']['alpha'],
1 ignored issue
show
Bug introduced by
It seems like $colorAlpha ?? (int)$thi...rties['color']['alpha'] can also be of type string; however, parameter $alpha of PhpOffice\PhpSpreadsheet...\Axis::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

342
                /** @scrutinizer ignore-type */ $colorAlpha ?? (int) $this->shadowProperties['color']['alpha'],
Loading history...
343
                $colorType ?? $this->shadowProperties['color']['type']
344
            )
345
            ->setShadowBlur($blur)
346
            ->setShadowAngle($angle)
347
            ->setShadowDistance($distance);
348
    }
349
350
    /**
351
     * Set Shadow Color.
352
     *
353
     * @param int $presets
354
     *
355
     * @return $this
356
     */
357
    private function setShadowPresetsProperties($presets)
358
    {
359
        $this->shadowProperties['presets'] = $presets;
360
        $this->setShadowPropertiesMapValues($this->getShadowPresetsMap($presets));
361
362
        return $this;
363
    }
364
365
    /**
366
     * Set Shadow Properties from Mapped Values.
367
     *
368
     * @param mixed $reference
369
     *
370
     * @return $this
371
     */
372
    private function setShadowPropertiesMapValues(array $propertiesMap, &$reference = null)
373
    {
374
        $base_reference = $reference;
375
        foreach ($propertiesMap as $property_key => $property_val) {
376
            if (is_array($property_val)) {
377
                if ($reference === null) {
378
                    $reference = &$this->shadowProperties[$property_key];
379
                } else {
380
                    $reference = &$reference[$property_key];
381
                }
382
                $this->setShadowPropertiesMapValues($property_val, $reference);
383
            } else {
384
                if ($base_reference === null) {
385
                    $this->shadowProperties[$property_key] = $property_val;
386
                } else {
387
                    $reference[$property_key] = $property_val;
388
                }
389
            }
390
        }
391
392
        return $this;
393
    }
394
395
    /**
396
     * Set Shadow Color.
397
     *
398
     * @param string $color
399
     * @param int $alpha
400
     * @param string $alphaType
401
     *
402
     * @return $this
403
     */
404
    private function setShadowColor($color, $alpha, $alphaType)
405
    {
406
        $this->shadowProperties['color'] = $this->setColorProperties($color, $alpha, $alphaType);
407
408
        return $this;
409
    }
410
411
    /**
412
     * Set Shadow Blur.
413
     *
414
     * @param float $blur
415
     *
416
     * @return $this
417
     */
418
    private function setShadowBlur($blur)
419
    {
420
        if ($blur !== null) {
0 ignored issues
show
introduced by
The condition $blur !== null is always true.
Loading history...
421
            $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
422
        }
423
424
        return $this;
425
    }
426
427
    /**
428
     * Set Shadow Angle.
429
     *
430
     * @param int $angle
431
     *
432
     * @return $this
433
     */
434
    private function setShadowAngle($angle)
435
    {
436
        if ($angle !== null) {
0 ignored issues
show
introduced by
The condition $angle !== null is always true.
Loading history...
437
            $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
438
        }
439
440
        return $this;
441
    }
442
443
    /**
444
     * Set Shadow Distance.
445
     *
446
     * @param float $distance
447
     *
448
     * @return $this
449
     */
450
    private function setShadowDistance($distance)
451
    {
452
        if ($distance !== null) {
0 ignored issues
show
introduced by
The condition $distance !== null is always true.
Loading history...
453
            $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
454
        }
455
456
        return $this;
457
    }
458
459
    /**
460
     * Get Shadow Property.
461
     *
462
     * @param string|string[] $elements
463
     *
464
     * @return null|array|int|string
465
     */
466 13
    public function getShadowProperty($elements)
467
    {
468 13
        return $this->getArrayElementsValue($this->shadowProperties, $elements);
469
    }
470
471
    /**
472
     * Set Glow Properties.
473
     *
474
     * @param float $size
475
     * @param string $colorValue
476
     * @param int $colorAlpha
477
     * @param string $colorType
478
     */
479
    public function setGlowProperties($size, $colorValue = null, $colorAlpha = null, $colorType = null): void
480
    {
481
        $this->setGlowSize($size)
482
            ->setGlowColor(
483
                $colorValue ?? $this->glowProperties['color']['value'],
484
                $colorAlpha ?? (int) $this->glowProperties['color']['alpha'],
485
                $colorType ?? $this->glowProperties['color']['type']
486
            );
487
    }
488
489
    /**
490
     * Get Glow Property.
491
     *
492
     * @param array|string $property
493
     *
494
     * @return string
495
     */
496 13
    public function getGlowProperty($property)
497
    {
498 13
        return $this->getArrayElementsValue($this->glowProperties, $property);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getArrayEl...wProperties, $property) also could return the type array<mixed,mixed> which is incompatible with the documented return type string.
Loading history...
499
    }
500
501
    /**
502
     * Set Glow Color.
503
     *
504
     * @param float $size
505
     *
506
     * @return $this
507
     */
508
    private function setGlowSize($size)
509
    {
510
        if ($size !== null) {
0 ignored issues
show
introduced by
The condition $size !== null is always true.
Loading history...
511
            $this->glowProperties['size'] = $this->getExcelPointsWidth($size);
512
        }
513
514
        return $this;
515
    }
516
517
    /**
518
     * Set Glow Color.
519
     *
520
     * @param string $color
521
     * @param int $alpha
522
     * @param string $colorType
523
     *
524
     * @return $this
525
     */
526
    private function setGlowColor($color, $alpha, $colorType)
527
    {
528
        $this->glowProperties['color'] = $this->setColorProperties($color, $alpha, $colorType);
529
530
        return $this;
531
    }
532
533
    /**
534
     * Set Soft Edges Size.
535
     *
536
     * @param float $size
537
     */
538
    public function setSoftEdges($size): void
539
    {
540
        if ($size !== null) {
0 ignored issues
show
introduced by
The condition $size !== null is always true.
Loading history...
541
            $softEdges['size'] = (string) $this->getExcelPointsWidth($size);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$softEdges was never initialized. Although not strictly required by PHP, it is generally a good practice to add $softEdges = array(); before regardless.
Loading history...
542
        }
543
    }
544
545
    /**
546
     * Get Soft Edges Size.
547
     *
548
     * @return string
549
     */
550 13
    public function getSoftEdgesSize()
551
    {
552 13
        return $this->softEdges['size'];
553
    }
554
}
555