File   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 51.22%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 57
ccs 21
cts 41
cp 0.5122
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 16 5
A copy() 0 13 4
A delete() 0 10 3
A makeExecutable() 0 7 2
1
<?php
2
3
namespace Genesis\Commands\Filesystem;
4
5
6
use Genesis\Commands\Command;
7
8
/**
9
 * @author Adam Bisek <[email protected]>
10
 */
11
class File extends Command
12
{
13
14 1
	public function create($file, $contents = NULL, $chmod = NULL)
15
	{
16 1
		if (is_file($file)) {
17
			$this->error("File '$file' already exists.");
18
		}
19 1
		$result = file_put_contents($file, $contents);
20 1
		if (!$result) {
21
			$this->error("Cannot create file '$file'.");
22
		}
23 1
		if ($chmod !== NULL) {
24
			$result = chmod($file, $chmod);
25
			if (!$result) {
26
				$this->error("Cannot chmod file '$file'.");
27
			}
28
		}
29 1
	}
30
31
32 5
	public function copy($source, $destination)
33
	{
34 5
		if (!is_file($source)) {
35
			$this->error("Source file '$source' does not exists.");
36
		}
37 5
		if (is_file($destination)) {
38
			$this->error("Destination file '$destination' already exists.");
39
		}
40 5
		$result = copy($source, $destination);
41 5
		if (!$result) {
42
			$this->error("Cannot create file '$destination'.");
43
		}
44 5
	}
45
46
47 1
	public function delete($file)
48
	{
49 1
		if (!is_file($file)) {
50
			return;
51
		}
52 1
		$result = @unlink($file);
53 1
		if (!$result) {
54
			$this->error("Cannot delete file '$file'.");
55
		}
56 1
	}
57
58
59 2
	public function makeExecutable($file)
60
	{
61 2
		exec('chmod +x ' . escapeshellarg($file), $output, $result); // native PHP chmod cannot work
62 2
		if ($result !== 0) {
63
			$this->error("Cannot make executable file '$file'.");
64
		}
65 2
	}
66
67
}