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

DateTimeWizard::padSeparatorArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 2
crap 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