Total Complexity | 10 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
5 | class Upload |
||
6 | { |
||
7 | protected $tmpDir; |
||
8 | |||
9 | public function __construct(string $dir) |
||
12 | } |
||
13 | |||
14 | public function process($files)//: array |
||
18 | } |
||
19 | |||
20 | private function addTemp(array $array): array |
||
21 | { |
||
22 | $result = []; |
||
23 | foreach ($array as $key => $file) { |
||
24 | if (!empty($file['tmp_name'])) { |
||
25 | $data = [ |
||
26 | 'tmp' => $file['tmp_name'], |
||
27 | 'name' => $file['name'], |
||
28 | 'type' => $file['type'], |
||
29 | 'size' => $file['size'] |
||
30 | ]; |
||
31 | $obj = new File($data); |
||
32 | $fileName = $this->tmpDir . DIRECTORY_SEPARATOR . $obj->getMd5(); |
||
33 | $obj->setPath($fileName); |
||
34 | \rename($file['tmp_name'], $fileName); |
||
35 | $result[] = $obj; |
||
36 | } |
||
37 | } |
||
38 | return $result; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * $inputArray => $_FILES |
||
43 | * @param array $inputArray |
||
44 | * @return array |
||
45 | */ |
||
46 | private function upload(array $inputArray): array |
||
61 | } |
||
62 | } |
||
63 |