UploadFile   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 217
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 217
rs 10
c 1
b 1
f 0
wmc 18

17 Methods

Rating   Name   Duplication   Size   Complexity  
A prePersistUpdate() 0 5 2
A __toString() 0 2 1
A getFile() 0 3 1
A getId() 0 3 1
A setStatusError() 0 4 1
A getEncode() 0 2 1
A getTs() 0 3 1
A setStatus() 0 4 1
A getLoaderClass() 0 2 1
A setFile() 0 5 1
A setEncode() 0 4 1
A setLoaderClass() 0 4 1
A setMessage() 0 4 1
A move() 0 5 1
A getMessage() 0 2 1
A getImportLog() 0 3 1
A getStatus() 0 2 1
1
<?php
2
3
namespace Doctrs\SonataImportBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping 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...
6
use Symfony\Component\HttpFoundation\File\File;
7
use Symfony\Component\HttpFoundation\File\UploadedFile;
8
9
/**
10
 * UploadFile
11
 *
12
 * @ORM\Table("ext_sonata_import_file")
13
 * @ORM\Entity(repositoryClass="Doctrs\SonataImportBundle\Repository\DefaultRepository")
14
 * @ORM\HasLifecycleCallbacks()
15
 */
16
class UploadFile
17
{
18
19
    const STATUS_LOAD = 1;
20
    const STATUS_SUCCESS = 2;
21
    const STATUS_ERROR = 3;
22
23
    /**
24
     * @var integer
25
     *
26
     * @ORM\Column(name="id", type="integer")
27
     * @ORM\Id
28
     * @ORM\GeneratedValue(strategy="AUTO")
29
     */
30
    private $id;
31
32
    /**
33
     * @var \DateTime
34
     *
35
     * @ORM\Column(name="ts", type="datetime")
36
     */
37
    private $ts;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(name="file", type="string")
43
     * @var UploadedFile
44
     */
45
    private $file;
46
47
    /**
48
     * @var string
49
     *
50
     * @ORM\Column(name="encode", type="string")
51
     */
52
    private $encode;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(name="loader_class", type="string")
58
     */
59
    private $loaderClass;
60
61
    /**
62
     * @var string
63
     *
64
     * @ORM\Column(name="status", type="integer")
65
     */
66
    private $status;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(name="message", type="text", nullable=true)
72
     */
73
    private $message;
74
75
    /**
76
     * @ORM\OneToMany(targetEntity="Doctrs\SonataImportBundle\Entity\ImportLog", mappedBy="uploadFile")
77
     */
78
    private $importLog;
79
80
81
    /**
82
     * Get id
83
     *
84
     * @return integer 
85
     */
86
    public function getId()
87
    {
88
        return $this->id;
89
    }
90
91
    /**
92
     * Get ts
93
     *
94
     * @return \DateTime 
95
     */
96
    public function getTs()
97
    {
98
        return $this->ts;
99
    }
100
101
    /**
102
     * Set file
103
     *
104
     * @param string $file
105
     * @return UploadFile
106
     */
107
    public function setFile($file)
108
    {
109
        $this->file = $file;
110
111
        return $this;
112
    }
113
114
    /**
115
     * Get file
116
     *
117
     * @return UploadedFile|null
118
     */
119
    public function getFile()
120
    {
121
        return $this->file;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->file returns the type string which is incompatible with the documented return type null|Symfony\Component\H...ation\File\UploadedFile.
Loading history...
122
    }
123
124
    /**
125
     * @ORM\PrePersist()
126
     * @ORM\PreUpdate()
127
     */
128
    public function prePersistUpdate() {
129
        if (!$this->status) {
130
            $this->status = self::STATUS_LOAD;
131
        }
132
        $this->ts = new \DateTime();
133
    }
134
135
    /**
136
     * @param $encode
137
     * @return UploadFile
138
     */
139
    public function setEncode($encode) {
140
        $this->encode = $encode;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getEncode() {
149
        return $this->encode;
150
    }
151
152
    /**
153
     * @param $message
154
     * @return UploadFile
155
     */
156
    public function setMessage($message) {
157
        $this->message = $message;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @return string
164
     */
165
    public function getMessage() {
166
        return $this->message;
167
    }
168
169
    /**
170
     * @param $status
171
     * @return UploadFile
172
     */
173
    public function setStatus($status) {
174
        $this->status = $status;
175
176
        return $this;
177
    }
178
179
    /**
180
     * @return string
181
     */
182
    public function getStatus() {
183
        return $this->status;
184
    }
185
186
    /**
187
     * @param $loaderClass
188
     * @return $this
189
     */
190
    public function setLoaderClass($loaderClass) {
191
        $this->loaderClass = $loaderClass;
192
193
        return $this;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getLoaderClass() {
200
        return $this->loaderClass;
201
    }
202
203
    public function move($uploadDir) {
204
        $file = $this->getFile();
205
        $fileName = md5(uniqid() . time()) . '.' . $file->guessExtension();
206
        $file->move($uploadDir, $fileName);
207
        $this->setFile($uploadDir . '/' . $fileName);
208
    }
209
210
    /**
211
     * @param $message
212
     * @return $this
213
     */
214
    public function setStatusError($message) {
215
        $this->setStatus(self::STATUS_ERROR);
216
        $this->setMessage($message);
217
        return $this;
218
    }
219
220
    /**
221
     * @return string
222
     */
223
    public function __toString() {
224
        return (string)$this->message;
225
    }
226
227
    /**
228
     * @return mixed
229
     */
230
    public function getImportLog()
231
    {
232
        return $this->importLog;
233
    }
234
}
235