Timestamps::timestampsChip()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Timestamps of [Created|Updated]
4
 * User: moyo
5
 * Date: 25/12/2017
6
 * Time: 5:47 PM
7
 */
8
9
namespace Carno\Database\SQL\Features;
10
11
use Carno\Database\SQL\Action;
12
use Carno\Database\SQL\Builder;
13
14
trait Timestamps
15
{
16
    /**
17
     * @return array [[ACTION, Closure $program]]
18
     */
19
    protected function timestampsChip() : array
20
    {
21
        $createdF = $this->createdAt ?? 'createdAt';
22
        $updatedF = $this->updatedAt ?? 'updatedAt';
23
24
        return [
25
            [
26
                Action::INSERT,
27
                function (Builder $builder) use ($createdF, $updatedF) {
28
                    $builder->data([
29
                        $createdF => time(),
30
                        $updatedF => time(),
31
                    ]);
32
                }
33
            ],
34
            [
35
                Action::UPDATE,
36
                function (Builder $builder) use ($updatedF) {
37
                    $builder->data([
38
                        $updatedF => time(),
39
                    ]);
40
                }
41
            ],
42
        ];
43
    }
44
}
45