Completed
Push — master ( e51964...81b8f9 )
by James Ekow Abaka
01:59
created

Filesystem::checkReadable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
namespace ntentan\utils;
3
4
use ntentan\utils\filesystem\Directory;
5
use ntentan\utils\filesystem\File;
6
7
class Filesystem
8
{   
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
9 2
    public static function checkWritable($path)
10
    {
11 2
        if(!is_writable($path)) {
12 2
            throw new exceptions\FileNotWriteableException("File $path is not writeable");
13
        }
14 2
        return true;
15
    }
16
    
17
    public static function checkReadable($path)
18
    {
19
        if(!is_readable($path)) {
20
            throw new exceptions\FileNotReadableException("File $path is not readable");
21
        }
22
        return true;
23
    }
24
    
25 2
    public static function checkExists($path)
26
    {
27 2
        if(!file_exists($path)) {
28 2
            throw new exceptions\FileNotFoundException("File $path does not exist");
29
        }
30 2
        return true;
31
    }
32
    
33
    public static function checkWriteSafety($path)
34
    {
35
        Filesystem::checkExists($path);
36
        Filesystem::checkWritable($path);        
37
    }
38
    
39
    public static function createDirectoryStructure($structure, $basePath)
40
    {
41
        foreach($structure as $key => $value) {
42
            if(is_numeric($key)) {
43
                Directory::create("$basePath/$value");
44
            } else {
45
                Directory::create("$basePath/$key");
46
                self::createDirectoryStructure($value, "$basePath/$key");
47
            }
48
        }
49
    }
50
    
51
    public static function get($path)
52
    {
53
        if(is_dir($path))
54
        {
55
            return new filesystem\Directory($path);
56
        }
57
        return new filesystem\File($path);
58
    }
59
}
60