Completed
Pull Request — master (#3)
by Harry
03:17
created

MakeDirectory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A makeDirectory() 0 11 3
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Modify;
15
16
use Graze\DataFile\Modify\Exception\MakeDirectoryFailedException;
17
use Graze\DataFile\Node\FileNode;
18
use Graze\DataFile\Node\LocalFile;
19
20
class MakeDirectory
21
{
22
    const VISIBILITY_PUBLIC  = 'public';
23
    const VISIBILITY_PRIVATE = 'private';
24
25
    /**
26
     * Create the directory specified by the $file if it does not exist
27
     *
28
     * @param FileNode $file
29
     * @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...
30
     *
31
     * @return LocalFile The original file inputted
32
     * @throws MakeDirectoryFailedException
33
     */
34 9
    public function makeDirectory(FileNode $file, $visibility = null)
35
    {
36 9
        $madeDirectory = $file->getFilesystem()->createDir($file->getDirectory(), [
37 9
            'visibility' => $visibility ?: static::VISIBILITY_PUBLIC,
38 9
        ]);
39 9
        if (!$madeDirectory) {
40 1
            throw new MakeDirectoryFailedException($file, error_get_last()['message']);
41
        }
42
43 8
        return $file;
44
    }
45
}
46