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

DateTimeWizard   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 1
b 0
f 0
dl 0
loc 38
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A padSeparatorArray() 0 5 1
A escapeSingleCharacter() 0 7 2
A wrapLiteral() 0 8 2
A __toString() 0 3 1
A intersperse() 0 3 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
4
5
abstract class DateTimeWizard implements Wizard
6
{
7
    protected const NO_ESCAPING_NEEDED = "$+-/():!^&'~{}<>= ";
8
9 14
    protected function padSeparatorArray(array $separators, int $count): array
10
    {
11 14
        $lastSeparator = array_pop($separators);
12
13 14
        return $separators + array_fill(0, $count, $lastSeparator);
14
    }
15
16 2
    protected function escapeSingleCharacter(string $value): string
17
    {
18 2
        if (strpos(self::NO_ESCAPING_NEEDED, $value) !== false) {
19 1
            return $value;
20
        }
21
22 1
        return "\\{$value}";
23
    }
24
25 5
    protected function wrapLiteral(string $value): string
26
    {
27 5
        if (mb_strlen($value, 'UTF-8') === 1) {
28 2
            return $this->escapeSingleCharacter($value);
29
        }
30
31
        // Wrap any other string literals in quotes, so that they're clearly defined as string literals
32 4
        return '"' . str_replace('"', '""', $value) . '"';
33
    }
34
35 14
    protected function intersperse(string $formatBlock, ?string $separator): string
36
    {
37 14
        return "{$formatBlock}{$separator}";
38
    }
39
40 14
    public function __toString(): string
41
    {
42 14
        return $this->format();
43
    }
44
}
45