Completed
Push — master ( 25c873...2076b7 )
by Afshin
02:25
created

File::moveUploadedFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 9.4285
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 11/24/17
6
 * Time: 1:11 PM
7
 */
8
9
namespace Core\Services;
10
11
use Core\Interfaces\_Service;
12
use Slim\Http\UploadedFile;
13
14
class File extends _Service
15
{
16
	public function moveUploadedFile($directory,$fileName, UploadedFile $uploadedFile)
17
	{
18
	    $extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
19
	    $basename = bin2hex(random_bytes(8)); // see http://php.net/manual/en/function.random-bytes.php
0 ignored issues
show
Unused Code introduced by
The assignment to $basename is dead and can be removed.
Loading history...
20
	    $filename = sprintf('%s.%0.8s', $fileName, $extension);
21
	    $uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
22
	    return $filename;
23
	}
24
25
}