DateColumn::format()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace hamburgscleanest\DataTables\Models\ColumnFormatters;
4
5
use Carbon\Carbon;
6
use hamburgscleanest\DataTables\Interfaces\ColumnFormatter;
7
use Illuminate\Database\Eloquent\Model;
8
9
/**
10
 * Class DateColumn
11
 * @package hamburgscleanest\DataTables\Models\ColumnFormatters
12
 */
13
class DateColumn implements ColumnFormatter {
14
15
    private $_dateFormat;
16
17
    /**
18
     * DateColumn constructor.
19
     * @param string $dateFormat
20
     */
21 5
    public function __construct(string $dateFormat = 'Y-m-d H:i:s')
22
    {
23 5
        $this->_dateFormat = $dateFormat;
24 5
    }
25
26
    /**
27
     * Set the format of the date column, e.g. "Y-m-d H:i:s".
28
     *
29
     * @param string $dateFormat
30
     * @return DateColumn
31
     */
32 1
    public function dateFormat(string $dateFormat) : DateColumn
33
    {
34 1
        $this->_dateFormat = $dateFormat;
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * @param Model $rowModel
41
     * @param string $column
42
     * @return string
43
     */
44 4
    public function format(Model $rowModel, string $column) : string
45
    {
46 4
        return Carbon::parse($column)->format($this->_dateFormat);
47
    }
48
}