Completed
Push — master ( e2a448...4810fe )
by Greg
02:48
created

FileSystemUtils::mkdirParents()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Consolidation\Cgr;
4
5
/**
6
 * A few convenience utility functions for filesystem operations.
7
 */
8
class FileSystemUtils
9
{
10
    /**
11
     * Set the current working directory if it was specified.
12
     */
13
    public static function applyDir($dir)
14
    {
15
        if (empty($dir)) {
16
            return $dir;
17
        }
18
        $origDir = getcwd();
19
        static::mkdirParents($dir);
20
        chdir($dir);
21
        return $origDir;
22
    }
23
24
    /**
25
     * Create a directory at the specified path. Also create any parent
26
     * directories that do not yet exist.
27
     *
28
     * @param $path The directory path to create.
29
     * @return boolean
30
     */
31
    public static function mkdirParents($path)
32
    {
33
        if (is_dir($path)) {
34
            return true;
35
        }
36
37
        if (static::mkdirParents(dirname($path))) {
38
            return mkdir($path);
39
        }
40
    }
41
}
42