Completed
Push — master ( 6695d4...9bc3b7 )
by Harry
04:41
created

MakeDirectory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 27
ccs 7
cts 8
cp 0.875
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\LocalFile;
7
8
class MakeDirectory
9
{
10
    /**
11
     * Create the directory specified by the $file if it does not exist
12
     *
13
     * @param LocalFile $file
14
     * @param int       $mode
15
     *
16
     * @return LocalFile The original file inputted
17
     * @throws MakeDirectoryFailedException
18
     */
19 10
    public function makeDirectory(LocalFile $file, $mode = 0777)
20
    {
21 10
        if (!($file instanceof LocalFile)) {
22
            throw new \InvalidArgumentException("Node: $file is not a LocalFile");
23
        }
24
25 10
        if (!file_exists($file->getDirectory())) {
26 8
            if (!@mkdir($file->getDirectory(), $mode, true)) {
27 1
                $lastError = error_get_last();
28 1
                throw new MakeDirectoryFailedException($file, $lastError['message']);
29
            }
30
        }
31
32 10
        return $file;
33
    }
34
}
35