Completed
Push — master ( 9bc3b7...a15851 )
by Harry
02:46
created

MakeDirectory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 30
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A makeDirectory() 0 15 4
1
<?php
2
3
namespace Graze\DataFile\Modify;
4
5
use Graze\DataFile\Modify\Exception\MakeDirectoryFailedException;
6
use Graze\DataFile\Node\FileNode;
7
use Graze\DataFile\Node\LocalFile;
8
9
class MakeDirectory
10
{
11
    const VISIBILITY_PUBLIC  = 'public';
12
    const VISIBILITY_PRIVATE = 'private';
13
14
    /**
15
     * Create the directory specified by the $file if it does not exist
16
     *
17
     * @param FileNode $file
18
     * @param string   $visibility public or private visibility
19
     *
20
     * @return LocalFile The original file inputted
21
     * @throws MakeDirectoryFailedException
22
     */
23 10
    public function makeDirectory(FileNode $file, $visibility = null)
24
    {
25 10
        if (!($file instanceof FileNode)) {
26
            throw new \InvalidArgumentException("Node: $file is not a FileNode");
27
        }
28
29 10
        $madeDirectory = $file->getFilesystem()->createDir($file->getDirectory(), [
30 10
            'visibility' => $visibility ?: static::VISIBILITY_PUBLIC,
31
        ]);
32 10
        if (!$madeDirectory) {
33
            throw new MakeDirectoryFailedException($file, error_get_last()['message']);
34
        }
35
36 10
        return $file;
37
    }
38
}
39