Failed Conditions
Push — develop ( a6bb49...7a4cbd )
by Adrien
36:15
created

Axis::setLineStyleProperties()   D

Complexity

Conditions 10
Paths 512

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
nc 512
nop 9
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 110
rs 4.1777
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 array of mixed
17
     */
18
    private $axisNumber = [
19
        'format' => self::FORMAT_CODE_GENERAL,
20
        'source_linked' => 1,
21
    ];
22
23
    /**
24
     * Axis Options.
25
     *
26
     * @var array of 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 array of 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 array of 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 array of 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 array of 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 array of 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 array of mixed
129
     */
130
    private $softEdges = [
131
        'size' => null,
132
    ];
133
134
    /**
135
     * Get Series Data Type.
136
     *
137
     * @param mixed $format_code
138
     *
139
     * @return string
140
     */
141
    public function setAxisNumberProperties($format_code)
142
    {
143
        $this->axisNumber['format'] = (string) $format_code;
144
        $this->axisNumber['source_linked'] = 0;
145
    }
146
147
    /**
148
     * Get Axis Number Format Data Type.
149
     *
150
     * @return string
151
     */
152 12
    public function getAxisNumberFormat()
153
    {
154 12
        return $this->axisNumber['format'];
155
    }
156
157
    /**
158
     * Get Axis Number Source Linked.
159
     *
160
     * @return string
161
     */
162 12
    public function getAxisNumberSourceLinked()
163
    {
164 12
        return (string) $this->axisNumber['source_linked'];
165
    }
166
167
    /**
168
     * Set Axis Options Properties.
169
     *
170
     * @param string $axis_labels
171
     * @param string $horizontal_crosses_value
172
     * @param string $horizontal_crosses
173
     * @param string $axis_orientation
174
     * @param string $major_tmt
175
     * @param string $minor_tmt
176
     * @param string $minimum
177
     * @param string $maximum
178
     * @param string $major_unit
179
     * @param string $minor_unit
180
     */
181
    public function setAxisOptionsProperties($axis_labels, $horizontal_crosses_value = null, $horizontal_crosses = null, $axis_orientation = null, $major_tmt = null, $minor_tmt = null, $minimum = null, $maximum = null, $major_unit = null, $minor_unit = null)
182
    {
183
        $this->axisOptions['axis_labels'] = (string) $axis_labels;
184
        ($horizontal_crosses_value !== null) ? $this->axisOptions['horizontal_crosses_value'] = (string) $horizontal_crosses_value : null;
185
        ($horizontal_crosses !== null) ? $this->axisOptions['horizontal_crosses'] = (string) $horizontal_crosses : null;
186
        ($axis_orientation !== null) ? $this->axisOptions['orientation'] = (string) $axis_orientation : null;
187
        ($major_tmt !== null) ? $this->axisOptions['major_tick_mark'] = (string) $major_tmt : null;
188
        ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
189
        ($minor_tmt !== null) ? $this->axisOptions['minor_tick_mark'] = (string) $minor_tmt : null;
190
        ($minimum !== null) ? $this->axisOptions['minimum'] = (string) $minimum : null;
191
        ($maximum !== null) ? $this->axisOptions['maximum'] = (string) $maximum : null;
192
        ($major_unit !== null) ? $this->axisOptions['major_unit'] = (string) $major_unit : null;
193
        ($minor_unit !== null) ? $this->axisOptions['minor_unit'] = (string) $minor_unit : null;
194
    }
195
196
    /**
197
     * Get Axis Options Property.
198
     *
199
     * @param string $property
200
     *
201
     * @return string
202
     */
203 12
    public function getAxisOptionsProperty($property)
204
    {
205 12
        return $this->axisOptions[$property];
206
    }
207
208
    /**
209
     * Set Axis Orientation Property.
210
     *
211
     * @param string $orientation
212
     */
213
    public function setAxisOrientation($orientation)
214
    {
215
        $this->axisOptions['orientation'] = (string) $orientation;
216
    }
217
218
    /**
219
     * Set Fill Property.
220
     *
221
     * @param string $color
222
     * @param int $alpha
223
     * @param string $type
224
     */
225
    public function setFillParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB)
226
    {
227
        $this->fillProperties = $this->setColorProperties($color, $alpha, $type);
228
    }
229
230
    /**
231
     * Set Line Property.
232
     *
233
     * @param string $color
234
     * @param int $alpha
235
     * @param string $type
236
     */
237
    public function setLineParameters($color, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_ARGB)
238
    {
239
        $this->lineProperties = $this->setColorProperties($color, $alpha, $type);
240
    }
241
242
    /**
243
     * Get Fill Property.
244
     *
245
     * @param string $property
246
     *
247
     * @return string
248
     */
249 12
    public function getFillProperty($property)
250
    {
251 12
        return $this->fillProperties[$property];
252
    }
253
254
    /**
255
     * Get Line Property.
256
     *
257
     * @param string $property
258
     *
259
     * @return string
260
     */
261 12
    public function getLineProperty($property)
262
    {
263 12
        return $this->lineProperties[$property];
264
    }
265
266
    /**
267
     * Set Line Style Properties.
268
     *
269
     * @param float $line_width
270
     * @param string $compound_type
271
     * @param string $dash_type
272
     * @param string $cap_type
273
     * @param string $join_type
274
     * @param string $head_arrow_type
275
     * @param string $head_arrow_size
276
     * @param string $end_arrow_type
277
     * @param string $end_arrow_size
278
     */
279
    public function setLineStyleProperties($line_width = null, $compound_type = null, $dash_type = null, $cap_type = null, $join_type = null, $head_arrow_type = null, $head_arrow_size = null, $end_arrow_type = null, $end_arrow_size = null)
280
    {
281
        ($line_width !== null) ? $this->lineStyleProperties['width'] = $this->getExcelPointsWidth((float) $line_width) : null;
282
        ($compound_type !== null) ? $this->lineStyleProperties['compound'] = (string) $compound_type : null;
283
        ($dash_type !== null) ? $this->lineStyleProperties['dash'] = (string) $dash_type : null;
284
        ($cap_type !== null) ? $this->lineStyleProperties['cap'] = (string) $cap_type : null;
285
        ($join_type !== null) ? $this->lineStyleProperties['join'] = (string) $join_type : null;
286
        ($head_arrow_type !== null) ? $this->lineStyleProperties['arrow']['head']['type'] = (string) $head_arrow_type : null;
287
        ($head_arrow_size !== null) ? $this->lineStyleProperties['arrow']['head']['size'] = (string) $head_arrow_size : null;
288
        ($end_arrow_type !== null) ? $this->lineStyleProperties['arrow']['end']['type'] = (string) $end_arrow_type : null;
289
        ($end_arrow_size !== null) ? $this->lineStyleProperties['arrow']['end']['size'] = (string) $end_arrow_size : null;
290
    }
291
292
    /**
293
     * Get Line Style Property.
294
     *
295
     * @param array|string $elements
296
     *
297
     * @return string
298
     */
299 12
    public function getLineStyleProperty($elements)
300
    {
301 12
        return $this->getArrayElementsValue($this->lineStyleProperties, $elements);
302
    }
303
304
    /**
305
     * Get Line Style Arrow Excel Width.
306
     *
307
     * @param string $arrow
308
     *
309
     * @return string
310
     */
311
    public function getLineStyleArrowWidth($arrow)
312
    {
313
        return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'w');
314
    }
315
316
    /**
317
     * Get Line Style Arrow Excel Length.
318
     *
319
     * @param string $arrow
320
     *
321
     * @return string
322
     */
323
    public function getLineStyleArrowLength($arrow)
324
    {
325
        return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrow]['size'], 'len');
326
    }
327
328
    /**
329
     * Set Shadow Properties.
330
     *
331
     * @param int $sh_presets
332
     * @param string $sh_color_value
333
     * @param string $sh_color_type
334
     * @param string $sh_color_alpha
335
     * @param float $sh_blur
336
     * @param int $sh_angle
337
     * @param float $sh_distance
338
     */
339
    public function setShadowProperties($sh_presets, $sh_color_value = null, $sh_color_type = null, $sh_color_alpha = null, $sh_blur = null, $sh_angle = null, $sh_distance = null)
340
    {
341
        $this->setShadowPresetsProperties((int) $sh_presets)
342
            ->setShadowColor(
343
                $sh_color_value === null ? $this->shadowProperties['color']['value'] : $sh_color_value,
344
                $sh_color_alpha === null ? (int) $this->shadowProperties['color']['alpha'] : $sh_color_alpha,
1 ignored issue
show
Bug introduced by
It seems like $sh_color_alpha === null...pha'] : $sh_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

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