SelfInit::execute()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4.0027

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 17
cts 18
cp 0.9444
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 14
nc 6
nop 0
crap 4.0027
1
<?php
2
3
4
namespace Genesis\Commands;
5
6
7
/**
8
 * @author Adam Bisek <[email protected]>
9
 * @internal You should NOT use
10
 */
11
class SelfInit extends Command
12
{
13
14
	private $distDirectory;
15
16
	private $workingDirectory;
17
18
	private $dirname = 'build';
19
20
21
	/**
22
	 * @return mixed
23
	 */
24 1
	public function getDistDirectory()
25
	{
26 1
		return $this->distDirectory;
27
	}
28
29
30
	/**
31
	 * @param mixed $distDirectory
32
	 */
33 3
	public function setDistDirectory($distDirectory)
34
	{
35 3
		$this->distDirectory = $distDirectory;
36 3
	}
37
38
39
	/**
40
	 * @return mixed
41
	 */
42 1
	public function getWorkingDirectory()
43
	{
44 1
		return $this->workingDirectory;
45
	}
46
47
48
	/**
49
	 * @param mixed $workingDirectory
50
	 */
51 3
	public function setWorkingDirectory($workingDirectory)
52
	{
53 3
		$this->workingDirectory = $workingDirectory;
54 3
	}
55
56
57
	/**
58
	 * @return string
59
	 */
60 1
	public function getDirname()
61
	{
62 1
		return $this->dirname;
63
	}
64
65
66
	/**
67
	 * @param string $dirname
68
	 */
69 3
	public function setDirname($dirname)
70
	{
71 3
		$this->dirname = $dirname;
72 3
	}
73
74
75 3
	public function execute()
76
	{
77 3
		$buildDir = $this->workingDirectory . DIRECTORY_SEPARATOR . $this->dirname;
78 3
		if (is_dir($buildDir)) {
79 1
			$this->error("Directory '$this->dirname' in working directory '$this->workingDirectory' already exists.");
80
		}
81 2
		$directory = new Filesystem\Directory();
82 2
		$directory->create($buildDir);
83
84 2
		$file = new Filesystem\File();
85 2
		foreach ($directory->read($this->distDirectory) as $fileInfo) {
86 2
			$newFile = $buildDir . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
87 2
			$file->copy($fileInfo->getPathName(), $newFile);
88 2
			if ($fileInfo->getFilename() === 'build') {
89 2
				$file->makeExecutable($newFile);
90 2
			}
91 2
		}
92
93 2
		$this->log("Build initialized in '$buildDir'.", self::SUCCESS);
94 2
		$this->log("You can start by typing '$this->dirname/build' in '$this->workingDirectory'.", self::SUCCESS);
95 2
	}
96
97
}