Completed
Pull Request — master (#51)
by Robbie
02:37 queued 48s
created
src/Executor.php 3 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -18,9 +18,6 @@
 block discarded – undo
18 18
 
19 19
 	/**
20 20
 	 * @param string $command The command
21
-	 * @param boolean $throwException If true, an Exception will be thrown on a nonzero error code
22
-	 * @param boolean $returnOutput If true, output will be captured
23
-	 * @param boolean $inputContent Content for STDIN. Otherwise the parent script's STDIN is used
24 21
 	 * @return A map containing 'return', 'output', and 'error'
25 22
 	 */
26 23
 	function execLocal($command, $options = array()) {
Please login to merge, or discard this patch.
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 
36 36
 	function createLocal($command, $options) {
37 37
 		$options = array_merge($this->defaultOptions, $options);
38
-		if(is_array($command)) $command = $this->commandArrayToString($command);
38
+		if(is_array($command)) {
39
+			$command = $this->commandArrayToString($command);
40
+		}
39 41
 
40 42
 		return new Process($command, $options);
41 43
 	}
@@ -81,8 +83,11 @@  discard block
 block discarded – undo
81 83
 
82 84
 		// Modify command for remote execution, if necessary.
83 85
 		if($this->remoteServer) {
84
-			if(!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T ";
85
-			else $ssh = "ssh -t ";
86
+			if(!empty($options['outputFile']) || !empty($options['outputStream'])) {
87
+				$ssh = "ssh -T ";
88
+			} else {
89
+				$ssh = "ssh -t ";
90
+			}
86 91
 			$command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command);
87 92
 		} else {
88 93
 			$command = $this->command;
@@ -96,7 +101,9 @@  discard block
 block discarded – undo
96 101
 		);
97 102
 
98 103
 		// Alternatives
99
-		if($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r');
104
+		if($options['inputContent'] || $options['inputStream']) {
105
+			$pipeSpec[0] = array('pipe', 'r');
106
+		}
100 107
 		
101 108
 		if($options['outputFile']) {
102 109
 			$pipeSpec[1] = array('file',
@@ -114,7 +121,9 @@  discard block
 block discarded – undo
114 121
 				fwrite($pipes[0], $content);
115 122
 			}
116 123
 		}
117
-		if(isset($pipes[0])) fclose($pipes[0]);
124
+		if(isset($pipes[0])) {
125
+			fclose($pipes[0]);
126
+		}
118 127
 	
119 128
 		$result = array();
120 129
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 	function createLocal($command, $options) {
37 37
 		$options = array_merge($this->defaultOptions, $options);
38
-		if(is_array($command)) $command = $this->commandArrayToString($command);
38
+		if (is_array($command)) $command = $this->commandArrayToString($command);
39 39
 
40 40
 		return new Process($command, $options);
41 41
 	}
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	function commandArrayToString($command) {
55 55
 		$string = escapeshellcmd(array_shift($command));
56
-		foreach($command as $arg) {
57
-			$string .= ' ' . escapeshellarg($arg);
56
+		foreach ($command as $arg) {
57
+			$string .= ' '.escapeshellarg($arg);
58 58
 		}
59 59
 		return $string;
60 60
 	}
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
 		$options = array_merge($this->options, $options);
81 81
 
82 82
 		// Modify command for remote execution, if necessary.
83
-		if($this->remoteServer) {
84
-			if(!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T ";
83
+		if ($this->remoteServer) {
84
+			if (!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T ";
85 85
 			else $ssh = "ssh -t ";
86 86
 			if (!empty($options['identity'])) {
87
-				$ssh .= '-i ' . escapeshellarg($options['identity']) . ' ';
87
+				$ssh .= '-i '.escapeshellarg($options['identity']).' ';
88 88
 			}
89
-			$command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command);
89
+			$command = $ssh.escapeshellarg($this->remoteServer).' '.escapeshellarg($this->command);
90 90
 		} else {
91 91
 			$command = $this->command;
92 92
 		}
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 		);
100 100
 
101 101
 		// Alternatives
102
-		if($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r');
102
+		if ($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r');
103 103
 
104
-		if($options['outputFile']) {
104
+		if ($options['outputFile']) {
105 105
 			$pipeSpec[1] = array('file',
106 106
 				$options['outputFile'],
107 107
 				$options['outputFileAppend'] ? 'a' : 'w');
@@ -109,24 +109,24 @@  discard block
 block discarded – undo
109 109
 
110 110
 		$process = proc_open($command, $pipeSpec, $pipes);
111 111
 
112
-		if($options['inputContent']) {
112
+		if ($options['inputContent']) {
113 113
 			fwrite($pipes[0], $options['inputContent']);
114 114
 
115
-		} else if($options['inputStream']) {
116
-			while($content = fread($options['inputStream'], 8192)) {
115
+		} else if ($options['inputStream']) {
116
+			while ($content = fread($options['inputStream'], 8192)) {
117 117
 				fwrite($pipes[0], $content);
118 118
 			}
119 119
 		}
120
-		if(isset($pipes[0])) fclose($pipes[0]);
120
+		if (isset($pipes[0])) fclose($pipes[0]);
121 121
 
122 122
 		$result = array();
123 123
 
124
-		if(isset($pipes[1])) {
124
+		if (isset($pipes[1])) {
125 125
 			// If a stream was provided, then pipe all the content
126 126
 			// Doing it this way rather than passing outputStream to $pipeSpec
127 127
 			// Means that streams as well as simple FDs can be used
128
-			if($options['outputStream']) {
129
-				while($content = fread($pipes[1], 8192)) {
128
+			if ($options['outputStream']) {
129
+				while ($content = fread($pipes[1], 8192)) {
130 130
 					fwrite($options['outputStream'], $content);
131 131
 				}
132 132
 
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 			}
137 137
 			fclose($pipes[1]);
138 138
 		}
139
-		if(isset($pipes[2])) {
139
+		if (isset($pipes[2])) {
140 140
 			$result['error'] = stream_get_contents($pipes[2]);
141 141
 			fclose($pipes[2]);
142 142
 		}
143 143
 
144 144
 		$result['return'] = proc_close($process);
145 145
 
146
-		if($options['throwException'] && $result['return'] != 0)	{
146
+		if ($options['throwException'] && $result['return'] != 0) {
147 147
 			throw new Exception("Command: $command\nExecution failed: returned {$result['return']}.\n"
148 148
 				. (empty($result['output']) ? "" : "Output:\n{$result['output']}"));
149 149
 		}
Please login to merge, or discard this patch.
src/FilesystemEntity.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,6 +22,10 @@  discard block
 block discarded – undo
22 22
 	function isLocal() {
23 23
 		return $this->server == null;
24 24
 	}
25
+
26
+	/**
27
+	 * @return string|null
28
+	 */
25 29
 	function getPath() {
26 30
 		return $this->path;
27 31
 	}
@@ -52,7 +56,6 @@  discard block
 block discarded – undo
52 56
 
53 57
 	/**
54 58
 	 * Upload a file to the given destination on the server
55
-	 * @param string $file The file to upload
56 59
 	 * @param string $dest The remote filename/dir to upload to
57 60
 	 */
58 61
 	function upload($source, $dest) {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 	function __construct($path, $executor) {
13 13
 		$this->executor = $executor;
14 14
 
15
-		if(strpos($path,':') !== false) {
16
-			list($this->server,$this->path) = explode(':', $path, 2);
15
+		if (strpos($path, ':') !== false) {
16
+			list($this->server, $this->path) = explode(':', $path, 2);
17 17
 		} else {
18 18
 			$this->server = null;
19 19
 			$this->path = $path;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @return Process
48 48
 	 */
49 49
 	function createProcess($command, $options = array()) {
50
-		if($this->server) {
50
+		if ($this->server) {
51 51
 			if ($this->identity && !isset($options['identity'])) {
52 52
 				$options['identity'] = $this->identity;
53 53
 			}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @param string $dest The remote filename/dir to upload to
64 64
 	 */
65 65
 	function upload($source, $dest) {
66
-		if($this->server) {
66
+		if ($this->server) {
67 67
 			$this->executor->execLocal(array("scp", $source, "$this->server:$dest"));
68 68
 		} else {
69 69
 			$this->executor->execLocal(array("cp", $source, $dest));
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @param string $dest The remote filename/dir to upload to
77 77
 	 */
78 78
 	function uploadContent($content, $dest) {
79
-		$this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($dest));
79
+		$this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($dest));
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @param string $dest The local filename/dir to download to
86 86
 	 */
87 87
 	function download($source, $dest) {
88
-		if($this->server) {
88
+		if ($this->server) {
89 89
 			$this->executor->execLocal(array("scp", "$this->server:$source", $dest));
90 90
 		} else {
91 91
 			$this->executor->execLocal(array("cp", $file, $dest));
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	 * @return boolean
99 99
 	 */
100 100
 	function exists($file = null) {
101
-		if(!$file) $file = $this->path;
102
-		if($file == '@self') return true;
101
+		if (!$file) $file = $this->path;
102
+		if ($file == '@self') return true;
103 103
 
104
-		if($this->server) {
105
-			$result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi");
104
+		if ($this->server) {
105
+			$result = $this->exec("if [ -e ".escapeshellarg($file)." ]; then echo yes; fi");
106 106
 			return (trim($result['output']) == 'yes');
107 107
 
108 108
 		} else {
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * Create the given file with the given content
115 115
 	 */
116 116
 	function writeFile($file, $content) {
117
-		if($this->server) {
118
-			$this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($file));
117
+		if ($this->server) {
118
+			$this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($file));
119 119
 
120 120
 		} else {
121 121
 			file_put_contents($file, $content);
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @param string $file The file to remove
129 129
 	 */
130 130
 	function unlink($file) {
131
-		if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'");
131
+		if (!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'");
132 132
 		$this->exec(array('rm', '-rf', $file));
133 133
 		return true;
134 134
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -98,8 +98,12 @@  discard block
 block discarded – undo
98 98
 	 * @return boolean
99 99
 	 */
100 100
 	function exists($file = null) {
101
-		if(!$file) $file = $this->path;
102
-		if($file == '@self') return true;
101
+		if(!$file) {
102
+			$file = $this->path;
103
+		}
104
+		if($file == '@self') {
105
+			return true;
106
+		}
103 107
 
104 108
 		if($this->server) {
105 109
 			$result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi");
@@ -128,7 +132,9 @@  discard block
 block discarded – undo
128 132
 	 * @param string $file The file to remove
129 133
 	 */
130 134
 	function unlink($file) {
131
-		if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'");
135
+		if(!$file || $file == '/' || $file == '.') {
136
+			throw new Exception("Can't unlink file '$file'");
137
+		}
132 138
 		$this->exec(array('rm', '-rf', $file));
133 139
 		return true;
134 140
 	}
Please login to merge, or discard this patch.
src/SSPak.php 3 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -234,6 +234,11 @@  discard block
 block discarded – undo
234 234
 		return true;
235 235
 	}
236 236
 
237
+	/**
238
+	 * @param Webroot $webroot
239
+	 * @param SSPakFile $sspak
240
+	 * @param string $filename
241
+	 */
237 242
 	function getassets($webroot, $assetsPath, $sspak, $filename) {
238 243
 		$assetsParentArg = escapeshellarg(dirname($assetsPath));
239 244
 		$assetsBaseArg = escapeshellarg(basename($assetsPath));
@@ -242,6 +247,11 @@  discard block
 block discarded – undo
242 247
 		$sspak->writeFileFromProcess($filename, $process);
243 248
 	}
244 249
 
250
+	/**
251
+	 * @param Webroot $webroot
252
+	 * @param SSPakFile $sspak
253
+	 * @param string $gitRemoteFile
254
+	 */
245 255
 	function getgitremote($webroot, $sspak, $gitRemoteFile) {
246 256
 		// Only do anything if we're copying from a git checkout
247 257
 		$gitRepo = $webroot->getPath() .'/.git';
Please login to merge, or discard this patch.
Braces   +32 added lines, -11 removed lines patch added patch discarded remove patch
@@ -67,13 +67,19 @@  discard block
 block discarded – undo
67 67
 		foreach($this->getActions() as $action => $info) {
68 68
 			echo "sspak $action";
69 69
 			if(!empty($info['unnamedArgs'])) {
70
-				foreach($info['unnamedArgs'] as $arg) echo " ($arg)";
70
+				foreach($info['unnamedArgs'] as $arg) {
71
+					echo " ($arg)";
72
+				}
71 73
 			}
72 74
 			if(!empty($info['namedFlags'])) {
73
-				foreach($info['namedFlags'] as $arg) echo " (--$arg)";
75
+				foreach($info['namedFlags'] as $arg) {
76
+					echo " (--$arg)";
77
+				}
74 78
 			}
75 79
 			if(!empty($info['namedArgs'])) {
76
-				foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\"";
80
+				foreach($info['namedArgs'] as $arg) {
81
+					echo " --$arg=\"$arg value\"";
82
+				}
77 83
 			}
78 84
 			echo "\n  {$info['description']}\n\n";
79 85
 		}
@@ -126,7 +132,9 @@  discard block
 block discarded – undo
126 132
 		$sspak = new SSPakFile($file, $executor);
127 133
 
128 134
 		// Validation
129
-		if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist.");
135
+		if(!$sspak->exists()) {
136
+			throw new Exception("File '$file' doesn't exist.");
137
+		}
130 138
 
131 139
 		$phar = $sspak->getPhar();
132 140
 		$phar->extractTo($dest);
@@ -145,12 +153,17 @@  discard block
 block discarded – undo
145 153
 
146 154
 		$webroot = new Webroot($unnamedArgs[0], $executor);
147 155
 		$file = $unnamedArgs[1];
148
-		if(file_exists($file)) throw new Exception( "File '$file' already exists.");
156
+		if(file_exists($file)) {
157
+			throw new Exception( "File '$file' already exists.");
158
+		}
149 159
 
150 160
 		$sspak = new SSPakFile($file, $executor);
151 161
 
152
-		if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']);
153
-		else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']);
162
+		if(!empty($namedArgs['from-sudo'])) {
163
+			$webroot->setSudo($namedArgs['from-sudo']);
164
+		} else if(!empty($namedArgs['sudo'])) {
165
+			$webroot->setSudo($namedArgs['sudo']);
166
+		}
154 167
 
155 168
 		// Look up which parts of the sspak are going to be saved
156 169
 		$pakParts = $args->pakParts();
@@ -253,7 +266,9 @@  discard block
 block discarded – undo
253 266
 				$currentBranch = trim($matches[1]);
254 267
 				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote"));
255 268
 				$remoteName = trim($output['output']);
256
-				if(!$remoteName) $remoteName = 'origin';
269
+				if(!$remoteName) {
270
+					$remoteName = 'origin';
271
+				}
257 272
 
258 273
 			// Default to origin
259 274
 			} else {
@@ -294,7 +309,9 @@  discard block
 block discarded – undo
294 309
 		$pakParts = $args->pakParts();
295 310
 
296 311
 		// Validation
297
-		if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist.");
312
+		if(!$sspak->exists()) {
313
+			throw new Exception( "File '$file' doesn't exist.");
314
+		}
298 315
 
299 316
 		// Push database, if necessary
300 317
 		$namedArgs = $args->getNamedArgs();
@@ -325,8 +342,12 @@  discard block
 block discarded – undo
325 342
 		$pakParts = $args->pakParts();
326 343
 
327 344
 		// Validation
328
-		if($webroot->exists($webroot->getPath())) throw new Exception( "Webroot '$webrootDir' already exists.");
329
-		if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist.");
345
+		if($webroot->exists($webroot->getPath())) {
346
+			throw new Exception( "Webroot '$webrootDir' already exists.");
347
+		}
348
+		if(!$sspak->exists()) {
349
+			throw new Exception( "File '$file' doesn't exist.");
350
+		}
330 351
 
331 352
 		// Create new dir
332 353
 		$webroot->exec(array('mkdir', $webroot->getPath()));
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
 
89 89
 	function help($args) {
90 90
 		echo "SSPak: manage SilverStripe .sspak archives.\n\nUsage:\n";
91
-		foreach($this->getActions() as $action => $info) {
91
+		foreach ($this->getActions() as $action => $info) {
92 92
 			echo "sspak $action";
93
-			if(!empty($info['unnamedArgs'])) {
94
-				foreach($info['unnamedArgs'] as $arg) echo " ($arg)";
93
+			if (!empty($info['unnamedArgs'])) {
94
+				foreach ($info['unnamedArgs'] as $arg) echo " ($arg)";
95 95
 			}
96
-			if(!empty($info['namedFlags'])) {
97
-				foreach($info['namedFlags'] as $arg) echo " (--$arg)";
96
+			if (!empty($info['namedFlags'])) {
97
+				foreach ($info['namedFlags'] as $arg) echo " (--$arg)";
98 98
 			}
99
-			if(!empty($info['namedArgs'])) {
100
-				foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\"";
99
+			if (!empty($info['namedArgs'])) {
100
+				foreach ($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\"";
101 101
 			}
102 102
 			echo "\n  {$info['description']}\n\n";
103 103
 		}
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 
122 122
 		$filesystem = new FilesystemEntity(null, $executor);
123 123
 
124
-		if($pakParts['db']) {
124
+		if ($pakParts['db']) {
125 125
 			$dbPath = escapeshellarg($namedArgs['db']);
126 126
 			$process = $filesystem->createProcess("cat $dbPath | gzip -c");
127 127
 			$sspak->writeFileFromProcess('database.sql.gz', $process);
128 128
 		}
129 129
 
130
-		if($pakParts['assets']) {
130
+		if ($pakParts['assets']) {
131 131
 			$assetsParentArg = escapeshellarg(dirname($namedArgs['assets']));
132 132
 			$assetsBaseArg = escapeshellarg(basename($namedArgs['assets']));
133 133
 			$process = $filesystem->createProcess("cd $assetsParentArg && tar cfh - $assetsBaseArg | gzip -c");
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		$sspak = new SSPakFile($file, $executor);
151 151
 
152 152
 		// Validation
153
-		if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist.");
153
+		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist.");
154 154
 
155 155
 		$phar = $sspak->getPhar();
156 156
 		$phar->extractTo($dest);
@@ -181,9 +181,9 @@  discard block
 block discarded – undo
181 181
 
182 182
 		$db = new DatabaseConnector($webroot);
183 183
 
184
-		foreach($db->getTables() as $table) {
185
-			$filename = $destPath . '/' . $table . '.csv';
186
-			echo $filename . "...\n";
184
+		foreach ($db->getTables() as $table) {
185
+			$filename = $destPath.'/'.$table.'.csv';
186
+			echo $filename."...\n";
187 187
 			touch($filename);
188 188
 			$writer = new CsvTableWriter($filename);
189 189
 			$db->saveTable($table, $writer);
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 
205 205
 		$db = new DatabaseConnector($webroot);
206 206
 
207
-		foreach($db->getTables() as $table) {
208
-			$filename = $srcPath . '/' . $table . '.csv';
209
-			if(file_exists($filename)) {
210
-				echo $filename . "...\n";
207
+		foreach ($db->getTables() as $table) {
208
+			$filename = $srcPath.'/'.$table.'.csv';
209
+			if (file_exists($filename)) {
210
+				echo $filename."...\n";
211 211
 				$reader = new CsvTableReader($filename);
212 212
 				$db->loadTable($table, $reader);
213 213
 			} else {
@@ -229,16 +229,16 @@  discard block
 block discarded – undo
229 229
 
230 230
 		$webroot = new Webroot($unnamedArgs[0], $executor);
231 231
 		$file = $unnamedArgs[1];
232
-		if(file_exists($file)) throw new Exception( "File '$file' already exists.");
232
+		if (file_exists($file)) throw new Exception("File '$file' already exists.");
233 233
 
234 234
 		$sspak = new SSPakFile($file, $executor);
235 235
 
236
-		if(!empty($namedArgs['identity'])) {
236
+		if (!empty($namedArgs['identity'])) {
237 237
 			// SSH private key
238 238
 			$webroot->setSSHItentityFile($namedArgs['identity']);
239 239
 		}
240
-		if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']);
241
-		else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']);
240
+		if (!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']);
241
+		else if (!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']);
242 242
 
243 243
 		// Look up which parts of the sspak are going to be saved
244 244
 		$pakParts = $args->pakParts();
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 		$details = $webroot->sniff();
248 248
 
249 249
 		// Create a build folder for the sspak file
250
-		$buildFolder = "/tmp/sspak-" . rand(100000,999999);
250
+		$buildFolder = "/tmp/sspak-".rand(100000, 999999);
251 251
 		$webroot->exec(array('mkdir', $buildFolder));
252 252
 
253 253
 		$dbFile = "$buildFolder/database.sql.gz";
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
 		$fileList = array();
259 259
 
260 260
 		// Save DB
261
-		if($pakParts['db']) {
261
+		if ($pakParts['db']) {
262 262
 			// Check the database type
263 263
 			$dbFunction = 'getdb_'.$details['db_type'];
264
-			if(!method_exists($this,$dbFunction)) {
265
-				throw new Exception("Can't process database type '" . $details['db_type'] . "'");
264
+			if (!method_exists($this, $dbFunction)) {
265
+				throw new Exception("Can't process database type '".$details['db_type']."'");
266 266
 			}
267 267
 			$this->$dbFunction($webroot, $details, $sspak, basename($dbFile));
268 268
 		}
269 269
 
270 270
 		// Save Assets
271
-		if($pakParts['assets']) {
271
+		if ($pakParts['assets']) {
272 272
 			$this->getassets($webroot, $details['assets_path'], $sspak, basename($assetsFile));
273 273
 		}
274 274
 
275 275
 		// Save git-remote
276
-		if($pakParts['git-remote']) {
276
+		if ($pakParts['git-remote']) {
277 277
 			$this->getgitremote($webroot, $sspak, basename($gitRemoteFile));
278 278
 		}
279 279
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		$hostArg = '';
294 294
 		$portArg = '';
295 295
 		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') {
296
-			if (strpos($conf['db_server'], ':')!==false) {
296
+			if (strpos($conf['db_server'], ':') !== false) {
297 297
 				// Handle "server:port" format.
298 298
 				$server = explode(':', $conf['db_server'], 2);
299 299
 				$hostArg = escapeshellarg("--host=".$server[0]);
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 
333 333
 	function getgitremote($webroot, $sspak, $gitRemoteFile) {
334 334
 		// Only do anything if we're copying from a git checkout
335
-		$gitRepo = $webroot->getPath() .'/.git';
336
-		if($webroot->exists($gitRepo)) {
335
+		$gitRepo = $webroot->getPath().'/.git';
336
+		if ($webroot->exists($gitRepo)) {
337 337
 			// Identify current branch
338 338
 			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'branch'));
339
-			if(preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1])===false) {
339
+			if (preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1]) === false) {
340 340
 				// If there is a current branch, use that branch's remove
341 341
 				$currentBranch = trim($matches[1]);
342
-				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote"));
342
+				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "branch.$currentBranch.remote"));
343 343
 				$remoteName = trim($output['output']);
344
-				if(!$remoteName) $remoteName = 'origin';
344
+				if (!$remoteName) $remoteName = 'origin';
345 345
 
346 346
 			// Default to origin
347 347
 			} else {
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 			}
351 351
 
352 352
 			// Determine the URL of that remote
353
-			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"remote.$remoteName.url"));
353
+			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "remote.$remoteName.url"));
354 354
 			$remoteURL = trim($output['output']);
355 355
 
356 356
 			// Determine the current SHA
357
-			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log','-1','--format=%H'));
357
+			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log', '-1', '--format=%H'));
358 358
 			$sha = trim($output['output']);
359 359
 
360 360
 			$content = "remote = $remoteURL\nbranch = $currentBranch\nsha = $sha\n";
@@ -382,22 +382,22 @@  discard block
 block discarded – undo
382 382
 		$pakParts = $args->pakParts();
383 383
 
384 384
 		$namedArgs = $args->getNamedArgs();
385
-		if(!empty($namedArgs['identity'])) {
385
+		if (!empty($namedArgs['identity'])) {
386 386
 			// SSH private key
387 387
 			$webroot->setSSHItentityFile($namedArgs['identity']);
388 388
 		}
389 389
 
390 390
 		// Validation
391
-		if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist.");
391
+		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist.");
392 392
 
393 393
 		// Push database, if necessary
394 394
 		$namedArgs = $args->getNamedArgs();
395
-		if($pakParts['db'] && $sspak->contains('database.sql.gz')) {
395
+		if ($pakParts['db'] && $sspak->contains('database.sql.gz')) {
396 396
 			$webroot->putdb($sspak, isset($namedArgs['drop-db']));
397 397
 		}
398 398
 
399 399
 		// Push assets, if neccessary
400
-		if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) {
400
+		if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) {
401 401
 			$webroot->putassets($sspak);
402 402
 		}
403 403
 	}
@@ -419,13 +419,13 @@  discard block
 block discarded – undo
419 419
 		$pakParts = $args->pakParts();
420 420
 
421 421
 		// Validation
422
-		if($webroot->exists($webroot->getPath())) throw new Exception( "Webroot '$webrootDir' already exists.");
423
-		if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist.");
422
+		if ($webroot->exists($webroot->getPath())) throw new Exception("Webroot '$webrootDir' already exists.");
423
+		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist.");
424 424
 
425 425
 		// Create new dir
426 426
 		$webroot->exec(array('mkdir', $webroot->getPath()));
427 427
 
428
-		if($sspak->contains('git-remote')) {
428
+		if ($sspak->contains('git-remote')) {
429 429
 			$details = $sspak->gitRemoteDetails();
430 430
 			$webroot->putgit($details);
431 431
 		}
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 
435 435
 		// Push database, if necessary
436 436
 		$namedArgs = $args->getNamedArgs();
437
-		if($pakParts['db'] && $sspak->contains('database.sql.gz')) {
437
+		if ($pakParts['db'] && $sspak->contains('database.sql.gz')) {
438 438
 			$webroot->putdb($sspak, isset($namedArgs['drop-db']));
439 439
 		}
440 440
 
441 441
 		// Push assets, if neccessary
442
-		if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) {
442
+		if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) {
443 443
 			$webroot->putassets($sspak);
444 444
 		}
445 445
 	}
@@ -466,10 +466,10 @@  discard block
 block discarded – undo
466 466
 		$sspakScript = str_replace('$isSelfExtracting = false;', '$isSelfExtracting = true;', $sspakScript);
467 467
 
468 468
 		// Load the sniffer file
469
-		$snifferFile = dirname(__FILE__) . '/sspak-sniffer.php';
469
+		$snifferFile = dirname(__FILE__).'/sspak-sniffer.php';
470 470
 		$sspakScript = str_replace("\$snifferFileContent = '';\n",
471 471
 			"\$snifferFileContent = '"
472
-			. str_replace(array("\\","'"),array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n", $sspakScript);
472
+			. str_replace(array("\\", "'"), array("\\\\", "\\'"), file_get_contents($snifferFile))."';\n", $sspakScript);
473 473
 
474 474
 		file_put_contents($destFile, $sspakScript);
475 475
 		chmod($destFile, 0775);
Please login to merge, or discard this patch.
src/SSPakFile.php 3 patches
Doc Comments   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,6 +6,9 @@  discard block
 block discarded – undo
6 6
 	protected $pharAlias;
7 7
 	protected $pharPath;
8 8
 
9
+	/**
10
+	 * @param Executor $executor
11
+	 */
9 12
 	function __construct($path, $executor, $pharAlias = 'sspak.phar') {
10 13
 		parent::__construct($path, $executor);
11 14
 		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots.");
@@ -73,6 +76,7 @@  discard block
 block discarded – undo
73 76
 
74 77
 	/**
75 78
 	 * Returns the content of a file from this sspak
79
+	 * @param string $file
76 80
 	 */
77 81
 	function content($file) {
78 82
 		return file_get_contents($this->phar[$file]);
@@ -105,7 +109,7 @@  discard block
 block discarded – undo
105 109
 	/**
106 110
 	 * Return a writeable stream corresponding to the given file within the .sspak
107 111
 	 * @param  string $filename The name of the file within the .sspak
108
-	 * @return Stream context
112
+	 * @return resource context
109 113
 	 */
110 114
 	function writeStreamForFile($filename) {
111 115
 		return fopen('phar://' . $this->pharAlias . '/' . $filename, 'w');
@@ -114,7 +118,7 @@  discard block
 block discarded – undo
114 118
 	/**
115 119
 	 * Return a readable stream corresponding to the given file within the .sspak
116 120
 	 * @param  string $filename The name of the file within the .sspak
117
-	 * @return Stream context
121
+	 * @return resource context
118 122
 	 */
119 123
 	function readStreamForFile($filename) {
120 124
 		// Note: using pharAlias here doesn't work on Debian Wheezy (nor on Windows for that matter).
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 
9 9
 	function __construct($path, $executor, $pharAlias = 'sspak.phar') {
10 10
 		parent::__construct($path, $executor);
11
-		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots.");
11
+		if (!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots.");
12 12
 
13 13
 		$this->pharAlias = $pharAlias;
14 14
 		$this->pharPath = $path;
15 15
 
16 16
 		// Executable Phar version
17
-		if(substr($path,-5) === '.phar') {
17
+		if (substr($path, -5) === '.phar') {
18 18
 			$this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
19 19
 				$this->pharAlias);
20
-			if(!file_exists($this->path)) $this->makeExecutable();
20
+			if (!file_exists($this->path)) $this->makeExecutable();
21 21
 
22 22
 		// Non-executable Tar version
23 23
 		} else {
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
 	 * Add the SSPak executable information into this SSPak file
35 35
 	 */
36 36
 	function makeExecutable() {
37
-		if(ini_get('phar.readonly')) {
37
+		if (ini_get('phar.readonly')) {
38 38
 			throw new Exception("Please set phar.readonly to false in your php.ini.");
39 39
 		}
40 40
 
41
-		passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT) . " --no-dev");
41
+		passthru("composer install -d ".escapeshellarg(PACKAGE_ROOT)." --no-dev");
42 42
 
43 43
 		$root = PACKAGE_ROOT;
44 44
 		$srcRoots = [
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
 		];
48 48
 
49 49
 		// Add the bin file, but strip of the #! exec header.
50
-		$this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak"));
50
+		$this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root."bin/sspak"));
51 51
 
52
-		foreach($srcRoots as $srcRoot) {
53
-			foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root . $srcRoot)) as $fileObj) {
54
-				if($fileObj->isFile()) {
52
+		foreach ($srcRoots as $srcRoot) {
53
+			foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root.$srcRoot)) as $fileObj) {
54
+				if ($fileObj->isFile()) {
55 55
 					$file = $fileObj->getRealPath();
56 56
 
57 57
 					$relativeFile = str_replace($root, '', $file);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		$this->phar->setStub($stub);
75 75
 		chmod($this->path, 0775);
76 76
 
77
-		passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT));
77
+		passthru("composer install -d ".escapeshellarg(PACKAGE_ROOT));
78 78
 	}
79 79
 
80 80
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 		// Non-executable Phars can't have content streamed into them
104 104
 		// This means that we need to create a temp file, which is a pain, if that file happens to be a 3GB
105 105
 		// asset dump. :-/
106
-		if($this->phar instanceof PharData) {
107
-			$tmpFile = '/tmp/sspak-content-' .rand(100000,999999);
106
+		if ($this->phar instanceof PharData) {
107
+			$tmpFile = '/tmp/sspak-content-'.rand(100000, 999999);
108 108
 			$process->exec(array('outputFile' => $tmpFile));
109 109
 			$this->phar->addFile($tmpFile, $filename);
110 110
 			unlink($tmpFile);
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 * @return Stream context
124 124
 	 */
125 125
 	function writeStreamForFile($filename) {
126
-		return fopen('phar://' . $this->pharAlias . '/' . $filename, 'w');
126
+		return fopen('phar://'.$this->pharAlias.'/'.$filename, 'w');
127 127
 	}
128 128
 
129 129
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	function readStreamForFile($filename) {
135 135
 		// Note: using pharAlias here doesn't work on Debian Wheezy (nor on Windows for that matter).
136 136
 		//return fopen('phar://' . $this->pharAlias . '/' . $filename, 'r');
137
-		return fopen('phar://' . $this->pharPath . '/' . $filename, 'r');
137
+		return fopen('phar://'.$this->pharPath.'/'.$filename, 'r');
138 138
 	}
139 139
 
140 140
 	/**
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 	function gitRemoteDetails() {
154 154
 		$content = $this->content('git-remote');
155 155
 		$details = array();
156
-		foreach(explode("\n", trim($content)) as $line) {
157
-			if(!$line) continue;
156
+		foreach (explode("\n", trim($content)) as $line) {
157
+			if (!$line) continue;
158 158
 
159
-			if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) {
159
+			if (preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) {
160 160
 				$details[$matches[1]] = $matches[2];
161 161
 			} else {
162 162
 				throw new Exception("Bad line '$line'");
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
 
9 9
 	function __construct($path, $executor, $pharAlias = 'sspak.phar') {
10 10
 		parent::__construct($path, $executor);
11
-		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots.");
11
+		if(!$this->isLocal()) {
12
+			throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots.");
13
+		}
12 14
 
13 15
 		$this->pharAlias = $pharAlias;
14 16
 		$this->pharPath = $path;
@@ -17,7 +19,9 @@  discard block
 block discarded – undo
17 19
 		if(substr($path,-5) === '.phar') {
18 20
 			$this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
19 21
 				$this->pharAlias);
20
-			if(!file_exists($this->path)) $this->makeExecutable();
22
+			if(!file_exists($this->path)) {
23
+				$this->makeExecutable();
24
+			}
21 25
 
22 26
 		// Non-executable Tar version
23 27
 		} else {
@@ -154,7 +158,9 @@  discard block
 block discarded – undo
154 158
 		$content = $this->content('git-remote');
155 159
 		$details = array();
156 160
 		foreach(explode("\n", trim($content)) as $line) {
157
-			if(!$line) continue;
161
+			if(!$line) {
162
+				continue;
163
+			}
158 164
 
159 165
 			if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) {
160 166
 				$details[$matches[1]] = $matches[2];
Please login to merge, or discard this patch.
src/Webroot.php 3 patches
Doc Comments   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,9 +66,8 @@  discard block
 block discarded – undo
66 66
 
67 67
 	/**
68 68
 	 * Put the database from the given sspak file into this webroot.
69
-	 * @param array $details The previously sniffed details of this webroot
70 69
 	 * @param bool $dropdb Drop the DB prior to install
71
-	 * @param string $sspakFile Filename
70
+	 * @param SSPakFile $sspak Filename
72 71
 	 */
73 72
 	function putdb($sspak, $dropdb) {
74 73
 		$details = $this->details();
@@ -131,6 +130,9 @@  discard block
 block discarded – undo
131 130
 		fclose($stream);
132 131
 	}
133 132
 
133
+	/**
134
+	 * @param SSPakFile $sspak
135
+	 */
134 136
 	function putassets($sspak) {
135 137
 		$details = $this->details();
136 138
 		$assetsPath = $details['assets_path'];
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
 	 * Calls sniff once and then caches
17 17
 	 */
18 18
 	function details() {
19
-		if(!$this->details) $this->details = $this->sniff();
19
+		if(!$this->details) {
20
+			$this->details = $this->sniff();
21
+		}
20 22
 		return $this->details;
21 23
 	}
22 24
 
@@ -26,7 +28,9 @@  discard block
 block discarded – undo
26 28
 	function sniff() {
27 29
 		global $snifferFileContent;
28 30
 
29
-		if(!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php');
31
+		if(!$snifferFileContent) {
32
+			$snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php');
33
+		}
30 34
 
31 35
 		$remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000,999999) . '.php';
32 36
 		$this->uploadContent($snifferFileContent, $remoteSniffer);
@@ -35,7 +39,9 @@  discard block
 block discarded – undo
35 39
 		$this->unlink($remoteSniffer);
36 40
 
37 41
 		$parsed = @unserialize($result['output']);
38
-		if(!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n");
42
+		if(!$parsed) {
43
+			throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n");
44
+		}
39 45
 		return $parsed;
40 46
 	}
41 47
 
@@ -45,7 +51,9 @@  discard block
 block discarded – undo
45 51
 	 */
46 52
 	function execSudo($command) {
47 53
 		if($this->sudo) {
48
-			if(is_array($command)) $command = $this->executor->commandArrayToString($command);
54
+			if(is_array($command)) {
55
+				$command = $this->executor->commandArrayToString($command);
56
+			}
49 57
 			// Try running sudo without asking for a password
50 58
 			try {
51 59
 				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command);
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	 * Calls sniff once and then caches
17 17
 	 */
18 18
 	function details() {
19
-		if(!$this->details) $this->details = $this->sniff();
19
+		if (!$this->details) $this->details = $this->sniff();
20 20
 		return $this->details;
21 21
 	}
22 22
 
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 	function sniff() {
27 27
 		global $snifferFileContent;
28 28
 
29
-		if(!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php');
29
+		if (!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT.'src/sspak-sniffer.php');
30 30
 
31
-		$remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000,999999) . '.php';
31
+		$remoteSniffer = '/tmp/sspak-sniffer-'.rand(100000, 999999).'.php';
32 32
 		$this->uploadContent($snifferFileContent, $remoteSniffer);
33 33
 
34 34
 		$result = $this->execSudo(array('/usr/bin/env', 'php', $remoteSniffer, $this->path));
35 35
 		$this->unlink($remoteSniffer);
36 36
 
37 37
 		$parsed = @unserialize($result['output']);
38
-		if(!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n");
38
+		if (!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n");
39 39
 		return $parsed;
40 40
 	}
41 41
 
@@ -44,19 +44,19 @@  discard block
 block discarded – undo
44 44
 	 * @param  string $command Shell command, either a fully escaped string or an array
45 45
 	 */
46 46
 	function execSudo($command) {
47
-		if($this->sudo) {
48
-			if(is_array($command)) $command = $this->executor->commandArrayToString($command);
47
+		if ($this->sudo) {
48
+			if (is_array($command)) $command = $this->executor->commandArrayToString($command);
49 49
 			// Try running sudo without asking for a password
50 50
 			try {
51
-				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command);
51
+				return $this->exec("sudo -n -u ".escapeshellarg($this->sudo)." ".$command);
52 52
 
53 53
 			// Otherwise capture SUDO password ourselves and pass it in through STDIN
54
-			} catch(Exception $e) {
54
+			} catch (Exception $e) {
55 55
 				echo "[sspak sudo] Enter your password: ";
56
-				$stdin = fopen( 'php://stdin', 'r');
56
+				$stdin = fopen('php://stdin', 'r');
57 57
 				$password = fgets($stdin);
58 58
 
59
-				return $this->exec("sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command, array('inputContent' => $password));
59
+				return $this->exec("sudo -S -p '' -u ".escapeshellarg($this->sudo)." ".$command, array('inputContent' => $password));
60 60
 			}
61 61
 		
62 62
 		} else {
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 
76 76
 		// Check the database type
77 77
 		$dbFunction = 'putdb_'.$details['db_type'];
78
-		if(!method_exists($this,$dbFunction)) {
79
-			throw new Exception("Can't process database type '" . $details['db_type'] . "'");
78
+		if (!method_exists($this, $dbFunction)) {
79
+			throw new Exception("Can't process database type '".$details['db_type']."'");
80 80
 		}
81 81
 
82 82
 		// Extract DB direct from sspak file
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		$hostArg = '';
96 96
 		$portArg = '';
97 97
 		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') {
98
-			if (strpos($conf['db_server'], ':')!==false) {
98
+			if (strpos($conf['db_server'], ':') !== false) {
99 99
 				// Handle "server:port" format.
100 100
 				$server = explode(':', $conf['db_server'], 2);
101 101
 				$hostArg = escapeshellarg("--host=".$server[0]);
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 				$hostArg = escapeshellarg("--host=".$conf['db_server']);
105 105
 			}
106 106
 		}
107
-		$dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`";
108
-		if($dropdb) {
109
-			$dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand;
107
+		$dbCommand = "create database if not exists `".addslashes($conf['db_database'])."`";
108
+		if ($dropdb) {
109
+			$dbCommand = "drop database if exists `".addslashes($conf['db_database'])."`; ".$dbCommand;
110 110
 		}
111 111
 
112 112
 		$this->exec("echo '$dbCommand' | mysql $usernameArg $passwordArg $hostArg $portArg");
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
 		// Create database if needed
128 128
 		$result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | $passwordArg psql $usernameArg $hostArg $databaseArg -qt");
129
-		if(trim($result['output']) == '0') {
129
+		if (trim($result['output']) == '0') {
130 130
 			$this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg");
131 131
 		}
132 132
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	function putgit($details) {
165 165
 		$this->exec(array('git', 'clone', $details['remote'], $this->path));
166
-		$this->exec("cd $this->path && git checkout " . escapeshellarg($details['branch']));
166
+		$this->exec("cd $this->path && git checkout ".escapeshellarg($details['branch']));
167 167
 		return true;
168 168
 	}
169 169
 }
Please login to merge, or discard this patch.
src/sspak-sniffer.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@
 block discarded – undo
13 13
 }
14 14
 
15 15
 $basePath = $_SERVER['argv'][1];
16
-if($basePath[0] != '/') $basePath = getcwd() . '/' . $basePath;
16
+if($basePath[0] != '/') {
17
+	$basePath = getcwd() . '/' . $basePath;
18
+}
17 19
 
18 20
 // SilverStripe bootstrap
19 21
 define('BASE_PATH', $basePath);
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Argument parsing
10
-if(empty($_SERVER['argv'][1])) {
10
+if (empty($_SERVER['argv'][1])) {
11 11
 	echo "Usage: {$_SERVER['argv'][0]} (site-docroot)\n";
12 12
 	exit(1);
13 13
 }
14 14
 
15 15
 $basePath = $_SERVER['argv'][1];
16
-if($basePath[0] != '/') $basePath = getcwd() . '/' . $basePath;
16
+if ($basePath[0] != '/') $basePath = getcwd().'/'.$basePath;
17 17
 
18 18
 // SilverStripe bootstrap
19 19
 define('BASE_PATH', $basePath);
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
 $_SERVER['HTTP_HOST'] = 'localhost';
22 22
 chdir(BASE_PATH);
23 23
 
24
-if(file_exists(BASE_PATH.'/framework/core/Core.php')) {
25
-	require_once(BASE_PATH. '/framework/core/Core.php');
26
-} else if(file_exists(BASE_PATH.'/sapphire/core/Core.php')) {
27
-	require_once(BASE_PATH. '/sapphire/core/Core.php');
24
+if (file_exists(BASE_PATH.'/framework/core/Core.php')) {
25
+	require_once(BASE_PATH.'/framework/core/Core.php');
26
+} else if (file_exists(BASE_PATH.'/sapphire/core/Core.php')) {
27
+	require_once(BASE_PATH.'/sapphire/core/Core.php');
28 28
 } else {
29
-	echo "No framework/core/Core.php or sapphire/core/Core.php included in project.  Perhaps " . BASE_PATH . " is not a SilverStripe project?\n";
29
+	echo "No framework/core/Core.php or sapphire/core/Core.php included in project.  Perhaps ".BASE_PATH." is not a SilverStripe project?\n";
30 30
 	exit(2);
31 31
 }
32 32
 
33 33
 $output = array();
34
-foreach($databaseConfig as $k => $v) {
35
-	$output['db_' . $k] = $v;
34
+foreach ($databaseConfig as $k => $v) {
35
+	$output['db_'.$k] = $v;
36 36
 }
37 37
 $output['assets_path'] = ASSETS_PATH;
38 38
 
Please login to merge, or discard this patch.
src/Args.php 2 patches
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,9 +51,13 @@  discard block
 block discarded – undo
51 51
 	 * Return the sudo argument, preferring a more specific one with the given optional prefix
52 52
 	 */
53 53
 	function sudo($optionalPrefix) {
54
-		if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) return $this->namedArgs[$optionalPrefix . '-sudo'];
55
-		else if(!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo'];
56
-		else return null;
54
+		if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) {
55
+			return $this->namedArgs[$optionalPrefix . '-sudo'];
56
+		} else if(!empty($this->namedArgs['sudo'])) {
57
+			return $this->namedArgs['sudo'];
58
+		} else {
59
+			return null;
60
+		}
57 61
 	}
58 62
 
59 63
 	/**
@@ -67,7 +71,9 @@  discard block
 block discarded – undo
67 71
 		}
68 72
 
69 73
 		// Default to db and assets
70
-		if(!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true);
74
+		if(!array_filter($pakParts)) {
75
+			$pakParts = array('db' => true, 'assets' => true, 'git-remote' => true);
76
+		}
71 77
 		return $pakParts;
72 78
 	}
73 79
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
11 11
 	function __construct($args) {
12 12
 		array_shift($args);
13 13
 
14
-		foreach($args as $arg) {
15
-			if(preg_match('/^--([^=]+)=(.*)$/', $arg, $matches)) {
14
+		foreach ($args as $arg) {
15
+			if (preg_match('/^--([^=]+)=(.*)$/', $arg, $matches)) {
16 16
 				$this->namedArgs[$matches[1]] = $matches[2];
17
-			} else if(preg_match('/^--([^=]+)$/', $arg, $matches)) {
17
+			} else if (preg_match('/^--([^=]+)$/', $arg, $matches)) {
18 18
 				$this->namedArgs[$matches[1]] = true;
19 19
 			} else {
20 20
 				$this->unnamedArgs[] = $arg;
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 * Return the sudo argument, preferring a more specific one with the given optional prefix
52 52
 	 */
53 53
 	function sudo($optionalPrefix) {
54
-		if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) return $this->namedArgs[$optionalPrefix . '-sudo'];
55
-		else if(!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo'];
54
+		if (!empty($this->namedArgs[$optionalPrefix.'-sudo'])) return $this->namedArgs[$optionalPrefix.'-sudo'];
55
+		else if (!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo'];
56 56
 		else return null;
57 57
 	}
58 58
 
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
 	function pakParts() {
63 63
 		// Look up which parts of the sspak are going to be saved
64 64
 		$pakParks = array();
65
-		foreach(array('assets','db','git-remote') as $part) {
65
+		foreach (array('assets', 'db', 'git-remote') as $part) {
66 66
 			$pakParts[$part] = !empty($this->namedArgs[$part]);
67 67
 		}
68 68
 
69 69
 		// Default to db and assets
70
-		if(!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true);
70
+		if (!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true);
71 71
 		return $pakParts;
72 72
 	}
73 73
 
74 74
 	function requireUnnamed($items) {
75
-		if(sizeof($this->unnamedArgs) < sizeof($items)) {
76
-			echo "Usage: {$_SERVER['argv'][0]} " . $this->action . " (";
75
+		if (sizeof($this->unnamedArgs) < sizeof($items)) {
76
+			echo "Usage: {$_SERVER['argv'][0]} ".$this->action." (";
77 77
 			echo implode(") (", $items);
78 78
 			echo ")\n";
79 79
 			throw new Exception('Arguments missing.');
Please login to merge, or discard this patch.
src/DataExtractor/CsvTableWriter.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -9,6 +9,9 @@
 block discarded – undo
9 9
 	private $handle;
10 10
 	private $columns;
11 11
 
12
+	/**
13
+	 * @param string $filename
14
+	 */
12 15
 	function __construct($filename) {
13 16
 		$this->filename = $filename;
14 17
 	}
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 
34 34
 	private function mapFromColumns($record) {
35 35
 		$row = [];
36
-		foreach($this->columns as $i => $column)
36
+		foreach ($this->columns as $i => $column)
37 37
 		{
38 38
 			$row[$i] = isset($record[$column]) ? $record[$column] : null;
39 39
 		}
Please login to merge, or discard this patch.
src/DataExtractor/DatabaseConnector.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
 		$this->isConnected = true;
27 27
 
28 28
 		// Necessary for SilverStripe's _ss_environment.php loader to work
29
-		$_SERVER['SCRIPT_FILENAME'] = $this->basePath . '/dummy.php';
29
+		$_SERVER['SCRIPT_FILENAME'] = $this->basePath.'/dummy.php';
30 30
 
31 31
 		global $databaseConfig;
32 32
 
33 33
 		// require composers autoloader
34
-		if (file_exists($this->basePath . '/vendor/autoload.php')) {
35
-			require_once $this->basePath . '/vendor/autoload.php';
34
+		if (file_exists($this->basePath.'/vendor/autoload.php')) {
35
+			require_once $this->basePath.'/vendor/autoload.php';
36 36
 		}
37 37
 
38
-		if (file_exists($this->basePath . '/framework/core/Core.php')) {
39
-			require_once($this->basePath . '/framework/core/Core.php');
40
-		} elseif (file_exists($this->basePath . '/sapphire/core/Core.php')) {
41
-			require_once($this->basePath . '/sapphire/core/Core.php');
38
+		if (file_exists($this->basePath.'/framework/core/Core.php')) {
39
+			require_once($this->basePath.'/framework/core/Core.php');
40
+		} elseif (file_exists($this->basePath.'/sapphire/core/Core.php')) {
41
+			require_once($this->basePath.'/sapphire/core/Core.php');
42 42
 		} else {
43 43
 			throw new \LogicException("No framework/core/Core.php or sapphire/core/Core.php included in project.  Perhaps $this->basePath is not a SilverStripe project?");
44 44
 		}
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	function getDatabase() {
57 57
 		$this->connect();
58 58
 
59
-		if(method_exists('DB', 'get_conn')) {
59
+		if (method_exists('DB', 'get_conn')) {
60 60
 			return DB::get_conn();
61 61
 		} else {
62 62
 			return DB::getConn();
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	function getTables() {
70 70
 		$this->connect();
71 71
 
72
-		if(method_exists('DB', 'table_list')) {
72
+		if (method_exists('DB', 'table_list')) {
73 73
 			return DB::table_list();
74 74
 		} else {
75 75
 			return DB::tableList();
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	function getFieldsForTable($tableName) {
83 83
 		$this->connect();
84 84
 
85
-		if(method_exists('DB', 'field_list')) {
85
+		if (method_exists('DB', 'field_list')) {
86 86
 			return DB::field_list($tableName);
87 87
 		} else {
88 88
 			return DB::fieldList($tableName);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
 		$fields = $this->getFieldsForTable($tableName);
112 112
 
113
-		foreach($reader as $record) {
113
+		foreach ($reader as $record) {
114 114
 			foreach ($record as $k => $v) {
115 115
 				if (!isset($fields[$k])) {
116 116
 					unset($record[$k]);
Please login to merge, or discard this patch.