File::setPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Compolomus\BinaryFileStorage;
4
5
class File
6
{
7
    protected $name;
8
9
    protected $size;
10
11
    protected $ext;
12
13
    protected $type;
14
15
    protected $md5;
16
17
    protected $path;
18
19
    public function __construct(array $data)
20
    {
21
        $this->name = $data['name'];
22
        $this->md5 = $this->generateMd5Hash($data['tmp']);
23
        $this->size = $data['size'];
24
        $this->ext = 'bin';
25
        if (preg_match("#\.#", $data['name'])) {
26
            $ext = explode('.', $data['name']);
27
            $this->ext = end($ext);
28
        }
29
        $this->type = $data['type'];
30
    }
31
32
    public function getMd5(): string
33
    {
34
        return $this->md5;
35
    }
36
37
    public function setPath(string $path): void
38
    {
39
        $this->path = $path;
40
    }
41
42
    public function getData(): array
43
    {
44
        return [
45
            'name' => $this->name,
46
            'md5' => $this->md5,
47
            'size' => $this->size,
48
            'ext' => $this->ext,
49
            'type' => $this->type,
50
            'path' => $this->path
51
        ];
52
    }
53
54
    public function generateMd5Hash(string $file): string
55
    {
56
        return md5_file($file);
57
    }
58
}
59