DateFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 8 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