File::copy()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 12
cp 0.5
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 8
nop 2
crap 6
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
}