Completed
Branch win (f8da4c)
by Adam
03:33
created

Symlink   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 68.18%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 6
c 5
b 0
f 2
lcom 0
cbo 3
dl 0
loc 36
ccs 15
cts 22
cp 0.6818
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 2
A createRelative() 0 18 4
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
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
34
			$cmd = 'cd ' . escapeshellarg($directory) . ' && mklink ' . ' /D ' . escapeshellarg($link) . ' ' . escapeshellarg($target);
35
		} else {
36 1
			$cmd = 'cd ' . escapeshellarg($directory) . ' && ln -s ' . escapeshellarg($target) . ' ' . escapeshellarg($link);
37
		}
38 1
		$command = new Commands\Exec();
39 1
		$command->setCommand($cmd);
40 1
		$result = $command->execute();
41 1
		if ($result->getResult() !== 0) {
42
			$this->error("Cannot create symlink '$target' - '$link' in directory '$directory'.");
43 1
		}
44 1
		return $result;
45 1
	}
46
47
}