FileService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A moveUploadedFile() 0 7 1
A delete() 0 3 1
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
}