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

Directory   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A delete() 0 3 1
A getPath() 0 3 1
A __toString() 0 3 1
A copyTo() 0 17 4
A getSize() 0 3 1
A moveTo() 0 3 1
A create() 0 9 4
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