Entity::onPrePersist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Common;
5
6
use DateTime;
7
use Doctrine\ORM\Mapping as ORM;
8
9
/**
10
 * @author Thiago Paes <[email protected]>
11
 * @ORM\MappedSuperclass(repositoryClass="Doctrine\ORM\EntityRepository")
12
 */
13
trait Entity
14
{
15
    /**
16
     * @ORM\PrePersist
17
     */
18
    public function onPrePersist()
19
    {
20
        $this->created = new DateTime();
0 ignored issues
show
Bug introduced by
The property created 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...
21
        $this->updated = new DateTime();
0 ignored issues
show
Bug introduced by
The property updated 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...
22
    }
23
24
    /**
25
     * @ORM\PreUpdate
26
     */
27
    public function onPreUpdate()
28
    {
29
        $this->updated = new DateTime();
30
    }
31
}
32