Completed
Push — master ( 522585...279d2c )
by Harry
04:14
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

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 2
nop 2
crap 3
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
0 ignored issues
show
Documentation introduced by
Should the type for parameter $visibility not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
19
     *
20
     * @return LocalFile The original file inputted
21
     * @throws MakeDirectoryFailedException
22
     */
23 9
    public function makeDirectory(FileNode $file, $visibility = null)
24
    {
25 9
        $madeDirectory = $file->getFilesystem()->createDir($file->getDirectory(), [
26 9
            'visibility' => $visibility ?: static::VISIBILITY_PUBLIC,
27
        ]);
28 9
        if (!$madeDirectory) {
29 1
            throw new MakeDirectoryFailedException($file, error_get_last()['message']);
30
        }
31
32 8
        return $file;
33
    }
34
}
35