Test Setup Failed
Push — master ( a515d0...24a3ce )
by Raí
07:35 queued 02:54
created

BaseEntity::fillable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Bludata\Doctrine\ORM\Entities;
4
5
use Bludata\Doctrine\Common\Annotations as BdAnnotations;
6
use Bludata\Doctrine\Common\Contracts\EntityContract;
7
use Bludata\Doctrine\Common\Contracts\RepositoryContract;
8
use Bludata\Doctrine\ORM\Traits\ToArrayTrait;
9
use DateTime;
10
use Doctrine\ORM\Mapping as ORM;
11
use EntityManager;
0 ignored issues
show
Bug introduced by
The type EntityManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Gedmo\Mapping\Annotation as Gedmo;
13
14
/**
15
 * @ORM\MappedSuperclass
16
 * @ORM\HasLifecycleCallbacks
17
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
18
 */
19
abstract class BaseEntity implements EntityContract
20
{
21
    use ToArrayTrait;
22
    
23
    /**
24
     * @ORM\Id
25
     * @ORM\Column(type="guid", name="id")
26
     * @ORM\GeneratedValue(strategy="UUID")
27
     * BdAnnotations\ToArray
28
     */
29
    protected $id;
30
31
    /**
32
     * @Gedmo\Timestampable(on="create")
33
     * @ORM\Column(type="datetime", name="createdAt")
34
     * BdAnnotations\ToArray
35
     */
36
    protected $createdAt;
37
38
    /**
39
     * @Gedmo\Timestampable(on="update")
40
     * @ORM\Column(type="datetime", name="updatedAt")
41
     * BdAnnotations\ToArray
42
     */
43
    protected $updatedAt;
44
45
    /**
46
     * @ORM\Column(type="datetime", name="deletedAt", nullable=true)
47
     * BdAnnotations\ToArray
48
     */
49
    protected $deletedAt;
50
51
    public function getId()
52
    {
53
        return $this->id;
54
    }
55
56
    public function getCreatedAt(): DateTime
57
    {
58
        return $this->createdAt;
59
    }
60
61
    public function getUpdatedAt(): DateTime
62
    {
63
        return $this->createdAt;
64
    }
65
66
    public function getDeletedAt(): DateTime
67
    {
68
        return $this->deletedAt;
69
    }
70
71
    public function getRepository(): RepositoryContract
72
    {
73
        return EntityManager::getRepository(get_class($this));
74
    }
75
76
    /**
77
     * @ORM\PreRemove
78
     */
79
    public function preRemove()
80
    {
81
    }
82
83
    /**
84
     * @ORM\PostRemove
85
     */
86
    public function postRemove()
87
    {
88
    }
89
90
    /**
91
     * @ORM\PrePersist
92
     */
93
    public function prePersist()
94
    {
95
    }
96
97
    /**
98
     * @ORM\PostPersist
99
     */
100
    public function postPersist()
101
    {
102
    }
103
104
    /**
105
     * @ORM\PreUpdate
106
     */
107
    public function preUpdate()
108
    {
109
    }
110
111
    /**
112
     * @ORM\PostUpdate
113
     */
114
    public function postUpdate()
115
    {
116
    }
117
118
    /**
119
     * @ORM\PreFlush
120
     */
121
    public function preFlush()
122
    {
123
    }
124
125
    public function persist(): EntityContract
126
    {
127
        $this->getRepository()
128
             ->em()
0 ignored issues
show
Bug introduced by
The method em() does not exist on Bludata\Doctrine\Common\...acts\RepositoryContract. Since it exists in all sub-types, consider adding an abstract or default implementation to Bludata\Doctrine\Common\...acts\RepositoryContract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

128
             ->/** @scrutinizer ignore-call */ em()
Loading history...
129
             ->persist($this);
130
131
        return $this;
132
    }
133
134
    public function flush(): EntityContract
135
    {
136
        $this->getRepository()
137
             ->em()
138
             ->flush($this);
139
140
        return $this;
141
    }
142
143
    public function remove(): EntityContract
144
    {
145
        $this->getRepository()
146
             ->em()
147
             ->remove($this);
148
149
        return $this;
150
    }
151
152
    public function undelete(): EntityContract
153
    {
154
        $this->deletedAt = null;
155
156
        $this->persist();
157
158
        return $this;
159
    }
160
}
161