Fill::asXML()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 2
nop 0
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eclipxe\XlsxExporter\Styles;
6
7
use Eclipxe\XlsxExporter\Exceptions\InvalidPropertyValueException;
8
use Eclipxe\XlsxExporter\Utils\OpenXmlColor;
0 ignored issues
show
Bug introduced by
The type Eclipxe\XlsxExporter\Utils\OpenXmlColor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * @property string $pattern Fill pattern
12
 * @property string $color Fill color
13
 */
14
class Fill extends AbstractStyle
15
{
16
    public const SOLID = 'solid';
17
18
    public const NONE = 'none';
19
20
    public const GRAY125 = 'gray125';
21
22
    private const VALUES = [
23
        self::NONE,
24
        self::GRAY125,
25
        self::SOLID,
26
    ];
27
28 26
    protected function properties(): array
29
    {
30 26
        return [
31 26
            'color',
32 26
            'pattern',
33 26
        ];
34
    }
35
36 5
    public function asXML(): string
37
    {
38 5
        if (! $this->pattern || $this->pattern == static::NONE || $this->pattern === static::GRAY125) {
39 4
            return '<fill><patternFill patternType="' . $this->pattern . '"/></fill>';
40
        }
41 3
        return '<fill>'
42 3
            . '<patternFill patternType="' . $this->pattern . '">'
43 3
            . '<fgColor rgb="' . $this->color . '"/>'
44 3
            . '<bgColor rgb="' . $this->color . '"/>'
45 3
            . '</patternFill>'
46 3
            . '</fill>'
47 3
        ;
48
    }
49
50
    /** @param scalar|null $value */
51 24
    protected function castPattern($value): string
52
    {
53 24
        $value = (string) $value;
54 24
        if (! in_array($value, self::VALUES, true)) {
55 1
            throw new InvalidPropertyValueException('Invalid fill pattern value', 'pattern', $value);
56
        }
57 24
        return $value;
58
    }
59
60
    /** @param scalar|null $value */
61 22
    protected function castColor($value): string
62
    {
63 22
        if (! is_string($value) && ! is_int($value)) {
64
            $value = (string) $value;
65
        }
66 22
        $color = OpenXmlColor::cast($value);
67 22
        if (false === $color) {
68 1
            throw new InvalidPropertyValueException('Invalid fill color value', 'color', $value);
69
        }
70 22
        return $color;
71
    }
72
}
73