Directory::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3.0261
1
<?php declare(strict_types=1);
2
3
namespace Gitilicious\GitClient\FileSystem;
4
5 View Code Duplication
class Directory
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 22
    public function __construct(string $path)
10
    {
11 22
        if (!is_dir($path)) {
12 1
            throw new NotFoundException(sprintf('The directory `%s` does not exist.', $path));
13
        }
14
15 21
        $this->path = $path;
16 21
    }
17
18 17
    public static function create(string $path, int $permissions = 0770): Directory
19
    {
20 17
        if (is_dir($path)) {
21 1
            throw new ExistsException(sprintf('The directory `%s` already exists.', $path));
22
        }
23
24 16
        @mkdir($path, $permissions, true);
25
26 16
        if (!is_dir($path)) {
27
            throw new PermissionDeniedException(error_get_last()['message'], error_get_last()['type']);
28
        }
29
30 16
        return new self($path);
31
    }
32
33 17
    public function getPath(): string
34
    {
35 17
        return $this->path;
36
    }
37
}
38