Passed
Pull Request — master (#4202)
by Owen
14:26
created

Layout::setLabelFont()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
use PhpOffice\PhpSpreadsheet\Style\Font;
6
7
class Layout
8
{
9
    /**
10
     * layoutTarget.
11
     */
12
    private ?string $layoutTarget = null;
13
14
    /**
15
     * X Mode.
16
     */
17
    private ?string $xMode = null;
18
19
    /**
20
     * Y Mode.
21
     */
22
    private ?string $yMode = null;
23
24
    /**
25
     * X-Position.
26
     */
27
    private ?float $xPos = null;
28
29
    /**
30
     * Y-Position.
31
     */
32
    private ?float $yPos = null;
33
34
    /**
35
     * width.
36
     */
37
    private ?float $width = null;
38
39
    /**
40
     * height.
41
     */
42
    private ?float $height = null;
43
44
    /**
45
     * Position - t=top.
46
     */
47
    private string $dLblPos = '';
48
49
    private string $numFmtCode = '';
50
51
    private bool $numFmtLinked = false;
52
53
    /**
54
     * show legend key
55
     * Specifies that legend keys should be shown in data labels.
56
     */
57
    private ?bool $showLegendKey = null;
58
59
    /**
60
     * show value
61
     * Specifies that the value should be shown in a data label.
62
     */
63
    private ?bool $showVal = null;
64
65
    /**
66
     * show category name
67
     * Specifies that the category name should be shown in the data label.
68
     */
69
    private ?bool $showCatName = null;
70
71
    /**
72
     * show data series name
73
     * Specifies that the series name should be shown in the data label.
74
     */
75
    private ?bool $showSerName = null;
76
77
    /**
78
     * show percentage
79
     * Specifies that the percentage should be shown in the data label.
80
     */
81
    private ?bool $showPercent = null;
82
83
    /**
84
     * show bubble size.
85
     */
86
    private ?bool $showBubbleSize = null;
87
88
    /**
89
     * show leader lines
90
     * Specifies that leader lines should be shown for the data label.
91
     */
92
    private ?bool $showLeaderLines = null;
93
94
    private ?ChartColor $labelFillColor = null;
95
96
    private ?ChartColor $labelBorderColor = null;
97
98
    private ?Font $labelFont = null;
99
100
    private ?Properties $labelEffects = null;
101
102
    /**
103
     * Create a new Layout.
104
     */
105 79
    public function __construct(array $layout = [])
106
    {
107 79
        if (isset($layout['layoutTarget'])) {
108 23
            $this->layoutTarget = $layout['layoutTarget'];
109
        }
110 79
        if (isset($layout['xMode'])) {
111 24
            $this->xMode = $layout['xMode'];
112
        }
113 79
        if (isset($layout['yMode'])) {
114 24
            $this->yMode = $layout['yMode'];
115
        }
116 79
        if (isset($layout['x'])) {
117 24
            $this->xPos = (float) $layout['x'];
118
        }
119 79
        if (isset($layout['y'])) {
120 24
            $this->yPos = (float) $layout['y'];
121
        }
122 79
        if (isset($layout['w'])) {
123 24
            $this->width = (float) $layout['w'];
124
        }
125 79
        if (isset($layout['h'])) {
126 24
            $this->height = (float) $layout['h'];
127
        }
128 79
        if (isset($layout['dLblPos'])) {
129 7
            $this->dLblPos = (string) $layout['dLblPos'];
130
        }
131 79
        if (isset($layout['numFmtCode'])) {
132 5
            $this->numFmtCode = (string) $layout['numFmtCode'];
133
        }
134 79
        $this->initBoolean($layout, 'showLegendKey');
135 79
        $this->initBoolean($layout, 'showVal');
136 79
        $this->initBoolean($layout, 'showCatName');
137 79
        $this->initBoolean($layout, 'showSerName');
138 79
        $this->initBoolean($layout, 'showPercent');
139 79
        $this->initBoolean($layout, 'showBubbleSize');
140 79
        $this->initBoolean($layout, 'showLeaderLines');
141 79
        $this->initBoolean($layout, 'numFmtLinked');
142 79
        $this->initColor($layout, 'labelFillColor');
143 79
        $this->initColor($layout, 'labelBorderColor');
144 79
        $labelFont = $layout['labelFont'] ?? null;
145 79
        if ($labelFont instanceof Font) {
146 8
            $this->labelFont = $labelFont;
147
        }
148 79
        $labelFontColor = $layout['labelFontColor'] ?? null;
149 79
        if ($labelFontColor instanceof ChartColor) {
150 1
            $this->setLabelFontColor($labelFontColor);
151
        }
152 79
        $labelEffects = $layout['labelEffects'] ?? null;
153 79
        if ($labelEffects instanceof Properties) {
154 3
            $this->labelEffects = $labelEffects;
155
        }
156
    }
157
158 79
    private function initBoolean(array $layout, string $name): void
159
    {
160 79
        if (isset($layout[$name])) {
161 9
            $this->$name = (bool) $layout[$name];
162
        }
163
    }
164
165 79
    private function initColor(array $layout, string $name): void
166
    {
167 79
        if (isset($layout[$name]) && $layout[$name] instanceof ChartColor) {
168 4
            $this->$name = $layout[$name];
169
        }
170
    }
171
172
    /**
173
     * Get Layout Target.
174
     */
175 48
    public function getLayoutTarget(): ?string
176
    {
177 48
        return $this->layoutTarget;
178
    }
179
180
    /**
181
     * Set Layout Target.
182
     *
183
     * @return $this
184
     */
185 2
    public function setLayoutTarget(?string $target): static
186
    {
187 2
        $this->layoutTarget = $target;
188
189 2
        return $this;
190
    }
191
192
    /**
193
     * Get X-Mode.
194
     */
195 47
    public function getXMode(): ?string
196
    {
197 47
        return $this->xMode;
198
    }
199
200
    /**
201
     * Set X-Mode.
202
     *
203
     * @return $this
204
     */
205 1
    public function setXMode(?string $mode): static
206
    {
207 1
        $this->xMode = (string) $mode;
208
209 1
        return $this;
210
    }
211
212
    /**
213
     * Get Y-Mode.
214
     */
215 47
    public function getYMode(): ?string
216
    {
217 47
        return $this->yMode;
218
    }
219
220
    /**
221
     * Set Y-Mode.
222
     *
223
     * @return $this
224
     */
225 1
    public function setYMode(?string $mode): static
226
    {
227 1
        $this->yMode = (string) $mode;
228
229 1
        return $this;
230
    }
231
232
    /**
233
     * Get X-Position.
234
     */
235 47
    public function getXPosition(): null|float|int
236
    {
237 47
        return $this->xPos;
238
    }
239
240
    /**
241
     * Set X-Position.
242
     *
243
     * @return $this
244
     */
245 1
    public function setXPosition(float $position): static
246
    {
247 1
        $this->xPos = $position;
248
249 1
        return $this;
250
    }
251
252
    /**
253
     * Get Y-Position.
254
     */
255 47
    public function getYPosition(): ?float
256
    {
257 47
        return $this->yPos;
258
    }
259
260
    /**
261
     * Set Y-Position.
262
     *
263
     * @return $this
264
     */
265 1
    public function setYPosition(float $position): static
266
    {
267 1
        $this->yPos = $position;
268
269 1
        return $this;
270
    }
271
272
    /**
273
     * Get Width.
274
     */
275 47
    public function getWidth(): ?float
276
    {
277 47
        return $this->width;
278
    }
279
280
    /**
281
     * Set Width.
282
     *
283
     * @return $this
284
     */
285 1
    public function setWidth(?float $width): static
286
    {
287 1
        $this->width = $width;
288
289 1
        return $this;
290
    }
291
292
    /**
293
     * Get Height.
294
     */
295 47
    public function getHeight(): ?float
296
    {
297 47
        return $this->height;
298
    }
299
300
    /**
301
     * Set Height.
302
     *
303
     * @return $this
304
     */
305 1
    public function setHeight(?float $height): static
306
    {
307 1
        $this->height = $height;
308
309 1
        return $this;
310
    }
311
312 47
    public function getShowLegendKey(): ?bool
313
    {
314 47
        return $this->showLegendKey;
315
    }
316
317
    /**
318
     * Set show legend key
319
     * Specifies that legend keys should be shown in data labels.
320
     */
321 43
    public function setShowLegendKey(?bool $showLegendKey): self
322
    {
323 43
        $this->showLegendKey = $showLegendKey;
324
325 43
        return $this;
326
    }
327
328 47
    public function getShowVal(): ?bool
329
    {
330 47
        return $this->showVal;
331
    }
332
333
    /**
334
     * Set show val
335
     * Specifies that the value should be shown in data labels.
336
     */
337 53
    public function setShowVal(?bool $showDataLabelValues): self
338
    {
339 53
        $this->showVal = $showDataLabelValues;
340
341 53
        return $this;
342
    }
343
344 47
    public function getShowCatName(): ?bool
345
    {
346 47
        return $this->showCatName;
347
    }
348
349
    /**
350
     * Set show cat name
351
     * Specifies that the category name should be shown in data labels.
352
     */
353 47
    public function setShowCatName(?bool $showCategoryName): self
354
    {
355 47
        $this->showCatName = $showCategoryName;
356
357 47
        return $this;
358
    }
359
360 47
    public function getShowSerName(): ?bool
361
    {
362 47
        return $this->showSerName;
363
    }
364
365
    /**
366
     * Set show data series name.
367
     * Specifies that the series name should be shown in data labels.
368
     */
369 43
    public function setShowSerName(?bool $showSeriesName): self
370
    {
371 43
        $this->showSerName = $showSeriesName;
372
373 43
        return $this;
374
    }
375
376 47
    public function getShowPercent(): ?bool
377
    {
378 47
        return $this->showPercent;
379
    }
380
381
    /**
382
     * Set show percentage.
383
     * Specifies that the percentage should be shown in data labels.
384
     */
385 51
    public function setShowPercent(?bool $showPercentage): self
386
    {
387 51
        $this->showPercent = $showPercentage;
388
389 51
        return $this;
390
    }
391
392 47
    public function getShowBubbleSize(): ?bool
393
    {
394 47
        return $this->showBubbleSize;
395
    }
396
397
    /**
398
     * Set show bubble size.
399
     * Specifies that the bubble size should be shown in data labels.
400
     */
401 43
    public function setShowBubbleSize(?bool $showBubbleSize): self
402
    {
403 43
        $this->showBubbleSize = $showBubbleSize;
404
405 43
        return $this;
406
    }
407
408 47
    public function getShowLeaderLines(): ?bool
409
    {
410 47
        return $this->showLeaderLines;
411
    }
412
413
    /**
414
     * Set show leader lines.
415
     * Specifies that leader lines should be shown in data labels.
416
     */
417 4
    public function setShowLeaderLines(?bool $showLeaderLines): self
418
    {
419 4
        $this->showLeaderLines = $showLeaderLines;
420
421 4
        return $this;
422
    }
423
424 47
    public function getLabelFillColor(): ?ChartColor
425
    {
426 47
        return $this->labelFillColor;
427
    }
428
429 2
    public function setLabelFillColor(?ChartColor $chartColor): self
430
    {
431 2
        $this->labelFillColor = $chartColor;
432
433 2
        return $this;
434
    }
435
436 47
    public function getLabelBorderColor(): ?ChartColor
437
    {
438 47
        return $this->labelBorderColor;
439
    }
440
441 1
    public function setLabelBorderColor(?ChartColor $chartColor): self
442
    {
443 1
        $this->labelBorderColor = $chartColor;
444
445 1
        return $this;
446
    }
447
448 47
    public function getLabelFont(): ?Font
449
    {
450 47
        return $this->labelFont;
451
    }
452
453 7
    public function setLabelFont(?Font $labelFont): self
454
    {
455 7
        $this->labelFont = $labelFont;
456
457
        return $this;
458 1
    }
459
460 1
    public function getLabelEffects(): ?Properties
461
    {
462
        return $this->labelEffects;
463
    }
464 1
465
    public function getLabelFontColor(): ?ChartColor
466
    {
467 2
        if ($this->labelFont === null) {
468
            return null;
469 2
        }
470 2
471 2
        return $this->labelFont->getChartColor();
472
    }
473 2
474
    public function setLabelFontColor(?ChartColor $chartColor): self
475 2
    {
476
        if ($this->labelFont === null) {
477
            $this->labelFont = new Font();
478 47
            $this->labelFont->setSize(null, true);
479
        }
480 47
        $this->labelFont->setChartColorFromObject($chartColor);
481
482
        return $this;
483 1
    }
484
485 1
    public function getDLblPos(): string
486
    {
487 1
        return $this->dLblPos;
488
    }
489
490 47
    public function setDLblPos(string $dLblPos): self
491
    {
492 47
        $this->dLblPos = $dLblPos;
493
494
        return $this;
495 2
    }
496
497 2
    public function getNumFmtCode(): string
498
    {
499 2
        return $this->numFmtCode;
500
    }
501
502 3
    public function setNumFmtCode(string $numFmtCode): self
503
    {
504 3
        $this->numFmtCode = $numFmtCode;
505
506
        return $this;
507 1
    }
508
509 1
    public function getNumFmtLinked(): bool
510
    {
511 1
        return $this->numFmtLinked;
512
    }
513
514
    public function setNumFmtLinked(bool $numFmtLinked): self
515
    {
516
        $this->numFmtLinked = $numFmtLinked;
517 5
518
        return $this;
519 5
    }
520 5
521 5
    /**
522 5
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
523
     */
524
    public function __clone()
525
    {
526
        $this->labelFillColor = ($this->labelFillColor === null) ? null : clone $this->labelFillColor;
527
        $this->labelBorderColor = ($this->labelBorderColor === null) ? null : clone $this->labelBorderColor;
528
        $this->labelFont = ($this->labelFont === null) ? null : clone $this->labelFont;
529
        $this->labelEffects = ($this->labelEffects === null) ? null : clone $this->labelEffects;
530
    }
531
}
532