Timestampable::touch()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Isswp101\Persimmon\Concerns;
4
5
use DateTime;
6
7
trait Timestampable
8
{
9
    protected bool $timestamps = true;
10
11
    private function touch(bool $exists): void
12
    {
13
        if (!$this->timestamps) {
14
            return;
15
        }
16
17
        $dt = new DateTime();
18
19
        $now = $dt->format(DateTime::ISO8601);
20
21
        $this->created_at = !$exists ? $now : $this->created_at;
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->updated_at = $now;
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
    }
24
}
25