File::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Gitilicious\GitClient\FileSystem;
4
5 View Code Duplication
class File
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    private $path;
8
9 3
    public function __construct(string $path)
10
    {
11 3
        if (!is_file($path)) {
12 1
            throw new NotFoundException(sprintf('The file `%s` does not exist.', $path));
13
        }
14
15 2
        $this->path = $path;
16 2
    }
17
18 3
    public static function create(string $path, string $content): File
19
    {
20 3
        if (is_file($path)) {
21 1
            throw new ExistsException(sprintf('The file `%s` already exists.', $path));
22
        }
23
24 2
        @file_put_contents($path, $content);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

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...
25
26 2
        if (!is_file($path)) {
27 1
            throw new PermissionDeniedException(error_get_last()['message'], error_get_last()['type']);
28
        }
29
30 1
        return new self($path);
31
    }
32
33 2
    public function getPath(): string
34
    {
35 2
        return $this->path;
36
    }
37
}
38