DateFormatter::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Spreadsheet\Formatter;
5
6
use Spreadsheet\{
7
    CellInterface,
8
    Exception\InvalidArgumentException
9
};
10
11
final class DateFormatter implements FormatterInterface
12
{
13
    private $format;
14
15 4
    public function __construct(string $format)
16
    {
17 4
        $this->format = $format;
18 4
    }
19
20 3
    public function format(CellInterface $cell): string
21
    {
22 3
        if (!$cell->value() instanceof \DateTimeInterface) {
23 1
            throw new InvalidArgumentException;
24
        }
25
26 2
        return $cell->value()->format($this->format);
27
    }
28
}
29