Completed
Push — master ( 79443c...8117c1 )
by Adam
04:00
created

Symlink::createRelative()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.3332

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 8
cts 12
cp 0.6667
rs 9.4285
cc 3
eloc 10
nc 4
nop 3
crap 3.3332
1
<?php
2
3
namespace Genesis\Commands\Filesystem;
4
5
6
use Genesis\Commands\Command;
7
use Genesis\Commands;
8
9
/**
10
 * @author Adam Bisek <[email protected]>
11
 */
12
class Symlink extends Command
13
{
14
15 1
	public function create($target, $link)
16
	{
17 1
		$result = symlink($target, $link);
18 1
		if (!$result) {
19
			$this->error("Cannot create symlink '$target' - '$link'.");
20
		}
21 1
	}
22
23
24
	/**
25
	 * target is relative to link!
26
	 * eg: dir, ../mydir, public/symdir
27
	 */
28 1
	public function createRelative($directory, $target, $link)
29
	{
30 1
		if (!is_dir($directory)) {
31
			$this->error("Directory '$directory' not found.");
32
		}
33 1
		$cmd = 'cd ' . escapeshellarg($directory) . ' && ln -s  ' . escapeshellarg($target) . ' ' . escapeshellarg($link);
34 1
		$command = new Commands\Exec();
35 1
		$command->setCommand($cmd);
36 1
		$result = $command->execute();
37 1
		if ($result->getResult() !== 0) {
38
			$this->error("Cannot create symlink '$target' - '$link' in directory '$directory'.");
39
		}
40 1
		return $result;
41
	}
42
43
}