Completed
Push — master ( c8ce79...6ffbf3 )
by Adam
03:48 queued 12s
created

SelfInit::setWorkingDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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 2
	public function setDistDirectory($distDirectory)
34 1
	{
35 2
		$this->distDirectory = $distDirectory;
36 2
	}
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 2
	public function setWorkingDirectory($workingDirectory)
52
	{
53 2
		$this->workingDirectory = $workingDirectory;
54 2
	}
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 2
	public function setDirname($dirname)
70
	{
71 2
		$this->dirname = $dirname;
72 2
	}
73
74
75 2
	public function execute()
76
	{
77 2
		$buildDir = $this->workingDirectory . DIRECTORY_SEPARATOR . $this->dirname;
78 2
		if(is_dir($buildDir)){
79 1
			$this->error("Directory '$this->dirname' in working directory '$this->workingDirectory' already exists.");
80
		}
81 1
		$directory = new Filesystem\Directory();
82 1
		$directory->create($buildDir);
83
84 1
		$file = new Filesystem\File();
85 1
		foreach ($directory->read($this->distDirectory) as $fileInfo) {
86 1
			$newFile = $buildDir . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
87 1
			$file->copy($fileInfo->getPathName(), $newFile);
88 1
			if($fileInfo->getFilename() === 'build'){
89 1
				$file->makeExecutable($newFile);
90 1
			}
91 1
		}
92
93 1
		$this->log("Build initialized in '$buildDir'.", self::SUCCESS);
94 1
		$this->log("You can start by typing '$this->dirname/build' in '$this->workingDirectory'.", self::SUCCESS);
95 1
	}
96
97
}