Passed
Push — main ( 2e6155...ac1e84 )
by Michael
03:13
created

DateFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Formatters;
6
7
use Illuminate\Support\Carbon;
8
use Illuminate\Support\Collection;
9
use MichaelRubel\Formatters\Formatter;
10
11
class DateFormatter implements Formatter
12
{
13
    /**
14
     * @var string
15
     */
16
    public string $date_format = 'Y.m.d';
17
18
    /**
19
     * Format the date.
20
     *
21
     * @param Collection $items
22
     *
23
     * @return string
24
     */
25
    public function format(Collection $items): string
26
    {
27
        $date = $items->first();
28
29
        if ($date instanceof Carbon) {
30
            return $date->format($this->date_format);
31
        }
32
33
        return app(Carbon::class)
34
            ->parse($date)
35
            ->format($this->date_format);
36
    }
37
}
38