Completed
Push — develop ( 672893...dd9590 )
by Adrien
28:52 queued 21:58
created

GridLines::setShadowAngle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 8
loc 8
ccs 0
cts 0
cp 0
crap 6
rs 9.4285
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 12
    public function getObjectState()
87
    {
88 12
        return $this->objectState;
89
    }
90
91
    /**
92
     * Change Object State to True.
93
     *
94
     * @return GridLines
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 $type
109
     */
110
    public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD)
111
    {
112
        $this->activateObject()
113
            ->lineProperties['color'] = $this->setColorProperties(
114
                $value,
115
                $alpha,
116
                $type
117
            );
118
    }
119
120
    /**
121
     * Set Line Color Properties.
122
     *
123
     * @param float $line_width
124
     * @param string $compound_type
125
     * @param string $dash_type
126
     * @param string $cap_type
127
     * @param string $join_type
128
     * @param string $head_arrow_type
129
     * @param string $head_arrow_size
130
     * @param string $end_arrow_type
131
     * @param string $end_arrow_size
132
     */
133
    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)
134
    {
135
        $this->activateObject();
136
        (!is_null($line_width))
137
                ? $this->lineProperties['style']['width'] = $this->getExcelPointsWidth((float) $line_width)
138
                : null;
139
        (!is_null($compound_type))
140
                ? $this->lineProperties['style']['compound'] = (string) $compound_type
141
                : null;
142
        (!is_null($dash_type))
143
                ? $this->lineProperties['style']['dash'] = (string) $dash_type
144
                : null;
145
        (!is_null($cap_type))
146
                ? $this->lineProperties['style']['cap'] = (string) $cap_type
147
                : null;
148
        (!is_null($join_type))
149
                ? $this->lineProperties['style']['join'] = (string) $join_type
150
                : null;
151
        (!is_null($head_arrow_type))
152
                ? $this->lineProperties['style']['arrow']['head']['type'] = (string) $head_arrow_type
153
                : null;
154
        (!is_null($head_arrow_size))
155
                ? $this->lineProperties['style']['arrow']['head']['size'] = (string) $head_arrow_size
156
                : null;
157
        (!is_null($end_arrow_type))
158
                ? $this->lineProperties['style']['arrow']['end']['type'] = (string) $end_arrow_type
159
                : null;
160
        (!is_null($end_arrow_size))
161
                ? $this->lineProperties['style']['arrow']['end']['size'] = (string) $end_arrow_size
162
                : null;
163
    }
164
165
    /**
166
     * Get Line Color Property.
167
     *
168
     * @param string $parameter
169
     *
170
     * @return string
171
     */
172 12
    public function getLineColorProperty($parameter)
173
    {
174 12
        return $this->lineProperties['color'][$parameter];
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 $color_value
194
     * @param int $color_alpha
195
     * @param string $color_type
196
     */
197
    public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null)
198
    {
199
        $this
200
                ->activateObject()
201
                ->setGlowSize($size)
202
                ->setGlowColor($color_value, $color_alpha, $color_type);
203
    }
204
205
    /**
206
     * Get Glow Color Property.
207
     *
208
     * @param string $property
209
     *
210
     * @return string
211
     */
212
    public function getGlowColor($property)
213
    {
214
        return $this->glowProperties['color'][$property];
215
    }
216
217
    /**
218
     * Get Glow Size.
219
     *
220
     * @return string
221
     */
222 12
    public function getGlowSize()
223
    {
224 12
        return $this->glowProperties['size'];
225
    }
226
227
    /**
228
     * Set Glow Size.
229
     *
230
     * @param float $size
231
     *
232
     * @return GridLines
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 $type
247
     *
248
     * @return GridLines
249
     */
250 View Code Duplication
    private function setGlowColor($color, $alpha, $type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
251
    {
252
        if (!is_null($color)) {
253
            $this->glowProperties['color']['value'] = (string) $color;
254
        }
255
        if (!is_null($alpha)) {
256
            $this->glowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
257
        }
258
        if (!is_null($type)) {
259
            $this->glowProperties['color']['type'] = (string) $type;
260
        }
261
262
        return $this;
263
    }
264
265
    /**
266
     * Get Line Style Arrow Parameters.
267
     *
268
     * @param string $arrow_selector
269
     * @param string $property_selector
270
     *
271
     * @return string
272
     */
273
    public function getLineStyleArrowParameters($arrow_selector, $property_selector)
274
    {
275
        return $this->getLineStyleArrowSize($this->lineProperties['style']['arrow'][$arrow_selector]['size'], $property_selector);
276
    }
277
278
    /**
279
     * Set Shadow Properties.
280
     *
281
     * @param int $sh_presets
282
     * @param string $sh_color_value
283
     * @param string $sh_color_type
284
     * @param int $sh_color_alpha
285
     * @param string $sh_blur
286
     * @param int $sh_angle
287
     * @param float $sh_distance
288
     */
289 View Code Duplication
    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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
    {
291
        $this->activateObject()
292
            ->setShadowPresetsProperties((int) $sh_presets)
293
            ->setShadowColor(
294
                is_null($sh_color_value) ? $this->shadowProperties['color']['value'] : $sh_color_value,
295
                is_null($sh_color_alpha) ? (int) $this->shadowProperties['color']['alpha'] : $this->getTrueAlpha($sh_color_alpha),
296
                is_null($sh_color_type) ? $this->shadowProperties['color']['type'] : $sh_color_type
297
            )
298
            ->setShadowBlur($sh_blur)
299
            ->setShadowAngle($sh_angle)
300
            ->setShadowDistance($sh_distance);
301
    }
302
303
    /**
304
     * Set Shadow Presets Properties.
305
     *
306
     * @param int $shadow_presets
307
     *
308
     * @return GridLines
309
     */
310
    private function setShadowPresetsProperties($shadow_presets)
311
    {
312
        $this->shadowProperties['presets'] = $shadow_presets;
313
        $this->setShadowProperiesMapValues($this->getShadowPresetsMap($shadow_presets));
314
315
        return $this;
316
    }
317
318
    /**
319
     * Set Shadow Properties Values.
320
     *
321
     * @param array $properties_map
322
     * @param * $reference
323
     *
324
     * @return GridLines
325
     */
326 View Code Duplication
    private function setShadowProperiesMapValues(array $properties_map, &$reference = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
327
    {
328
        $base_reference = $reference;
329
        foreach ($properties_map as $property_key => $property_val) {
330
            if (is_array($property_val)) {
331
                if ($reference === null) {
332
                    $reference = &$this->shadowProperties[$property_key];
333
                } else {
334
                    $reference = &$reference[$property_key];
335
                }
336
                $this->setShadowProperiesMapValues($property_val, $reference);
337
            } else {
338
                if ($base_reference === null) {
339
                    $this->shadowProperties[$property_key] = $property_val;
340
                } else {
341
                    $reference[$property_key] = $property_val;
342
                }
343
            }
344
        }
345
346
        return $this;
347
    }
348
349
    /**
350
     * Set Shadow Color.
351
     *
352
     * @param string $color
353
     * @param int $alpha
354
     * @param string $type
355
     *
356
     * @return GridLines
357
     */
358 View Code Duplication
    private function setShadowColor($color, $alpha, $type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
359
    {
360
        if (!is_null($color)) {
361
            $this->shadowProperties['color']['value'] = (string) $color;
362
        }
363
        if (!is_null($alpha)) {
364
            $this->shadowProperties['color']['alpha'] = $this->getTrueAlpha((int) $alpha);
365
        }
366
        if (!is_null($type)) {
367
            $this->shadowProperties['color']['type'] = (string) $type;
368
        }
369
370
        return $this;
371
    }
372
373
    /**
374
     * Set Shadow Blur.
375
     *
376
     * @param float $blur
377
     *
378
     * @return GridLines
379
     */
380 View Code Duplication
    private function setShadowBlur($blur)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
381
    {
382
        if ($blur !== null) {
383
            $this->shadowProperties['blur'] = (string) $this->getExcelPointsWidth($blur);
384
        }
385
386
        return $this;
387
    }
388
389
    /**
390
     * Set Shadow Angle.
391
     *
392
     * @param int $angle
393
     *
394
     * @return GridLines
395
     */
396 View Code Duplication
    private function setShadowAngle($angle)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
    {
398
        if ($angle !== null) {
399
            $this->shadowProperties['direction'] = (string) $this->getExcelPointsAngle($angle);
400
        }
401
402
        return $this;
403
    }
404
405
    /**
406
     * Set Shadow Distance.
407
     *
408
     * @param float $distance
409
     *
410
     * @return GridLines
411
     */
412 View Code Duplication
    private function setShadowDistance($distance)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
    {
414
        if ($distance !== null) {
415
            $this->shadowProperties['distance'] = (string) $this->getExcelPointsWidth($distance);
416
        }
417
418
        return $this;
419
    }
420
421
    /**
422
     * Get Shadow Property.
423
     *
424
     * @param string $elements
425
     * @param array $elements
426
     *
427
     * @return string
428
     */
429 12
    public function getShadowProperty($elements)
430
    {
431 12
        return $this->getArrayElementsValue($this->shadowProperties, $elements);
432
    }
433
434
    /**
435
     * Set Soft Edges Size.
436
     *
437
     * @param float $size
438
     */
439
    public function setSoftEdgesSize($size)
440
    {
441
        if (!is_null($size)) {
442
            $this->activateObject();
443
            $softEdges['size'] = (string) $this->getExcelPointsWidth($size);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$softEdges was never initialized. Although not strictly required by PHP, it is generally a good practice to add $softEdges = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
444
        }
445
    }
446
447
    /**
448
     * Get Soft Edges Size.
449
     *
450
     * @return string
451
     */
452 12
    public function getSoftEdgesSize()
453
    {
454 12
        return $this->softEdges['size'];
455
    }
456
}
457