Completed
Push — master ( 043afa...c1d4a3 )
by James Ekow Abaka
01:16
created

Directory::getSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace ntentan\utils\filesystem;
4
5
use ntentan\utils\Filesystem;
6
use ntentan\utils\exceptions\FilesystemException;
7
8
/**
9
 * 
10
 */
11
class Directory implements FileInterface {
12
13
    private $path;
14
15
    public function __construct($path = null) {
16
        $this->path = $path;
17
    }
18
19
    public function copyTo($destination) {
20
        Filesystem::checkWritable($destination);
21
        if (!file_exists($destination)) {
22
            self::create($destination);
23
        }
24
        
25
        $files = glob("$this->path/*");
26
        foreach ($files as $file) {
27
            $newFile = "$destination/" . basename("$file");
28
            if (is_dir($file)) {
29
                self::create($newFile);
30
                (new Directory($file))->copyTo($newFile);
31
            } else {
32
                copy($file, $newFile);
33
            }
34
        }
35
    }
36
37
    public function getSize() {
38
        
39
    }
40
41
    public function moveTo($destination) {
42
        
43
    }
44
45
    public static function create($path, $permissions = 0755) {
46
        if (file_exists($path) && !is_dir($path)) {
47
            throw new FilesystemException("A file already exists in the location of [$path]");
48
        }
49
        if (!file_exists($path)) {
50
            mkdir($path, $permissions, true);
51
        }
52
        return new Directory($path);
53
    }
54
55
    public function delete() {
56
        
57
    }
58
59
    public function getPath() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
60
        return $this->path;
61
    }
62
63
    public function __toString() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
64
        return $this->path;
65
    }
66
67
}
68