Completed
Push — master ( a15851...522585 )
by Harry
02:42
created

MakeDirectory::makeDirectory()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 6
nc 2
nop 2
crap 3.0261
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
        $madeDirectory = $file->getFilesystem()->createDir($file->getDirectory(), [
26 10
            'visibility' => $visibility ?: static::VISIBILITY_PUBLIC,
27 10
        ]);
28 10
        if (!$madeDirectory) {
29
            throw new MakeDirectoryFailedException($file, error_get_last()['message']);
30
        }
31
32 10
        return $file;
33
    }
34
}
35