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

Symlink   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 0
cbo 3
dl 0
loc 32
ccs 12
cts 18
cp 0.6667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 2
A createRelative() 0 14 3
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
}