Completed
Push — master ( 2076b7...2510e5 )
by Afshin
02:23
created

FileService::delete()   A

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
2
namespace Core\Services;
3
4
use Core\Interfaces\_Service;
5
use Slim\Http\UploadedFile;
6
7
class FileService extends _Service
8
{
9
	public function moveUploadedFile($directory,$fileName, UploadedFile $uploadedFile)
10
	{
11
	    $extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
12
	    $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...
13
	    $filename = sprintf('%s.%0.8s', $fileName, $extension);
14
	    $uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
15
	    return $directory . DIRECTORY_SEPARATOR . $filename;
16
	}
17
	public function delete($file)
18
	{
19
		@unlink($file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

19
		/** @scrutinizer ignore-unhandled */ @unlink($file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
20
	}
21
22
}