Passed
Push — master ( 66b95b...1192d3 )
by Mark
21:21 queued 10:15
created

DateTime::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
4
5
class DateTime extends DateTimeWizard
6
{
7
    /**
8
     * @var string[]
9
     */
10
    protected array $separators;
11
12
    /**
13
     * @var array<DateTimeWizard|string>
14
     */
15
    protected array $formatBlocks;
16
17
    /**
18
     * @param null|string|string[] $separators
19
     *          If you want to use only a single format block, then pass a null as the separator argument
20
     * @param DateTimeWizard|string ...$formatBlocks
21
     */
22 2
    public function __construct($separators, ...$formatBlocks)
23
    {
24 2
        $this->separators = $this->padSeparatorArray(
25 2
            is_array($separators) ? $separators : [$separators],
26 2
            count($formatBlocks) - 1
27 2
        );
28 2
        $this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
29
    }
30
31
    /**
32
     * @param DateTimeWizard|string $value
33
     */
34 2
    private function mapFormatBlocks($value): string
35
    {
36
        // Any date masking codes are returned as lower case values
37 2
        if (is_object($value)) {
38
            // We can't explicitly test for Stringable until PHP >= 8.0
39 2
            return $value;
40
        }
41
42
        // Wrap any string literals in quotes, so that they're clearly defined as string literals
43 2
        return $this->wrapLiteral($value);
44
    }
45
46 2
    public function format(): string
47
    {
48 2
        return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
49
    }
50
}
51