Completed
Pull Request — master (#22)
by Sergey
15:55
created

Timestampable::fillTimestamp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Isswp101\Persimmon\Traits;
4
5
use Carbon\Carbon;
6
7
trait Timestampable
8
{
9
    protected function updateTimestamps()
10
    {
11
        $utc = Carbon::now('UTC')->toDateTimeString();
12
        $this->{static::UPDATED_AT} = $utc;
13
        if (!$this->exists) {
0 ignored issues
show
Bug introduced by
The property exists does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
            $this->{static::CREATED_AT} = $utc;
15
        }
16
    }
17
}
18