File   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 14
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setContent() 0 4 2
A __destruct() 0 5 3
A getContent() 0 6 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 9/27/16
6
 * Time: 2:36 PM
7
 */
8
9
namespace execut\import\components\source;
10
11
12
use yii\base\Component;
13
14
class File extends Component
15
{
16
    public $fileName = null;
17
    public $filePath = null;
18
    public $folder = null;
19
    protected $content = null;
20 3
    public function getContent() {
21 3
        if ($this->filePath !== null && $this->content === null) {
22 1
            return file_get_contents($this->filePath);
23
        }
24
25 2
        return $this->content;
26
    }
27
28 3
    public function setContent($content) {
29 3
        $this->content = $content;
30 3
        if ($this->filePath !== null) {
31 3
            file_put_contents($this->filePath, $this->content);
32
        }
33 3
    }
34
35 10
    public function __destruct()
36
    {
37 10
        if ($this->filePath !== null && file_exists($this->filePath)) {
38 5
            unlink($this->filePath);
39 5
            @rmdir(dirname($this->filePath));
0 ignored issues
show
Security Best Practice introduced by eXeCUT
It seems like you do not handle an error condition for rmdir(). 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

39
            /** @scrutinizer ignore-unhandled */ @rmdir(dirname($this->filePath));

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...
40
        }
41
    }
42
}