Completed
Pull Request — master (#88)
by Steve
17s
created
tests/DataExtractor/CsvTableReaderTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,18 +6,18 @@
 block discarded – undo
6 6
 {
7 7
 	public function testCsvReading() {
8 8
 
9
-		$csv = new CsvTableReader(__DIR__ . '/fixture/input.csv');
9
+		$csv = new CsvTableReader(__DIR__.'/fixture/input.csv');
10 10
 		$this->assertEquals(['Col1', 'Col2', 'Col3'], $csv->getColumns());
11 11
 
12 12
 		$extractedData = [];
13
-		foreach($csv as $record) {
13
+		foreach ($csv as $record) {
14 14
 			$extractedData[] = $record;
15 15
 		}
16 16
 
17 17
 		$this->assertEquals(
18 18
 			[
19
-				[ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ],
20
-				[ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]
19
+				['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three'],
20
+				['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]
21 21
 			],
22 22
 			$extractedData
23 23
 		);
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', realpath($basePath));
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 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', realpath($basePath));
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 $_SERVER['HTTP_HOST'] = 'localhost';
24 24
 chdir(BASE_PATH);
25 25
 
26
-if(file_exists(BASE_PATH.'/sapphire/core/Core.php')) {
26
+if (file_exists(BASE_PATH.'/sapphire/core/Core.php')) {
27 27
 	//SS 2.x
28
-	require_once(BASE_PATH . '/sapphire/core/Core.php');
29
-} else if(file_exists(BASE_PATH.'/framework/core/Core.php')) {
28
+	require_once(BASE_PATH.'/sapphire/core/Core.php');
29
+} else if (file_exists(BASE_PATH.'/framework/core/Core.php')) {
30 30
 	//SS 3.x
31
-	require_once(BASE_PATH. '/framework/core/Core.php');
32
-} else if(file_exists(BASE_PATH.'/vendor/silverstripe/framework')) {
31
+	require_once(BASE_PATH.'/framework/core/Core.php');
32
+} else if (file_exists(BASE_PATH.'/vendor/silverstripe/framework')) {
33 33
 	//SS 4.x
34
-	require_once(BASE_PATH. '/vendor/autoload.php');
34
+	require_once(BASE_PATH.'/vendor/autoload.php');
35 35
 	$kernel = new SilverStripe\Core\CoreKernel(BASE_PATH);
36 36
 	//boot the parts of the kernel to populate the DB config
37 37
 	foreach (array('bootDatabaseEnvVars', 'bootDatabaseGlobals') as $bootMethod) {
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 	$databaseConfig = SilverStripe\ORM\DB::getConfig();
43 43
 } else {
44
-	echo "Couldn't locate framework's Core.php. Perhaps " . BASE_PATH . " is not a SilverStripe project?\n";
44
+	echo "Couldn't locate framework's Core.php. Perhaps ".BASE_PATH." is not a SilverStripe project?\n";
45 45
 	exit(2);
46 46
 }
47 47
 
48 48
 $output = array();
49
-foreach($databaseConfig as $k => $v) {
50
-	$output['db_' . $k] = $v;
49
+foreach ($databaseConfig as $k => $v) {
50
+	$output['db_'.$k] = $v;
51 51
 }
52 52
 $output['assets_path'] = ASSETS_PATH;
53 53
 
Please login to merge, or discard this patch.
src/Webroot.php 2 patches
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
 	public 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
 	public 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
 	public function execSudo($command, $options = array()) {
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, $options);
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 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
 	public 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
 	public 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
 
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
 	 * @return array A map containing 'return', 'output', and 'error'
47 47
 	 */
48 48
 	public function execSudo($command, $options = array()) {
49
-		if($this->sudo) {
50
-			if(is_array($command)) $command = $this->executor->commandArrayToString($command);
49
+		if ($this->sudo) {
50
+			if (is_array($command)) $command = $this->executor->commandArrayToString($command);
51 51
 			// Try running sudo without asking for a password
52 52
 			try {
53
-				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command, $options);
53
+				return $this->exec("sudo -n -u ".escapeshellarg($this->sudo)." ".$command, $options);
54 54
 
55 55
 			// Otherwise capture SUDO password ourselves and pass it in through STDIN
56
-			} catch(Exception $e) {
56
+			} catch (Exception $e) {
57 57
 				echo "[sspak sudo] Enter your password: ";
58
-				$stdin = fopen( 'php://stdin', 'r');
58
+				$stdin = fopen('php://stdin', 'r');
59 59
 				$password = fgets($stdin);
60 60
 
61
-				return $this->exec("sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command, array('inputContent' => $password));
61
+				return $this->exec("sudo -S -p '' -u ".escapeshellarg($this->sudo)." ".$command, array('inputContent' => $password));
62 62
 			}
63 63
 
64 64
 		} else {
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 
78 78
 		// Check the database type
79 79
 		$dbFunction = 'putdb_'.$details['db_type'];
80
-		if(!method_exists($this,$dbFunction)) {
81
-			throw new Exception("Can't process database type '" . $details['db_type'] . "'");
80
+		if (!method_exists($this, $dbFunction)) {
81
+			throw new Exception("Can't process database type '".$details['db_type']."'");
82 82
 		}
83 83
 
84 84
 		// Extract DB direct from sspak file
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		$hostArg = '';
98 98
 		$portArg = '';
99 99
 		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') {
100
-			if (strpos($conf['db_server'], ':')!==false) {
100
+			if (strpos($conf['db_server'], ':') !== false) {
101 101
 				// Handle "server:port" format.
102 102
 				$server = explode(':', $conf['db_server'], 2);
103 103
 				$hostArg = escapeshellarg("--host=".$server[0]);
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 				$hostArg = escapeshellarg("--host=".$conf['db_server']);
107 107
 			}
108 108
 		}
109
-		$dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`";
110
-		if($dropdb) {
111
-			$dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand;
109
+		$dbCommand = "create database if not exists `".addslashes($conf['db_database'])."`";
110
+		if ($dropdb) {
111
+			$dbCommand = "drop database if exists `".addslashes($conf['db_database'])."`; ".$dbCommand;
112 112
 		}
113 113
 
114 114
 		$this->exec("echo '$dbCommand' | mysql $usernameArg $passwordArg $hostArg $portArg");
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 
129 129
 		// Create database if needed
130 130
 		$result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | $passwordArg psql $usernameArg $hostArg $databaseArg -qt");
131
-		if(trim($result['output']) == '0') {
131
+		if (trim($result['output']) == '0') {
132 132
 			$this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg");
133 133
 		}
134 134
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		$assetsPathExec = $this->exec("if [ -L {$assetsPath} ]; then readlink -f {$assetsPath}; else echo {$assetsPath}; fi");
151 151
 		$assetsPath = trim($assetsPathExec["output"]);
152 152
 
153
-		$assetsOldPath = $assetsPath . '.old';
153
+		$assetsOldPath = $assetsPath.'.old';
154 154
 		$assetsParentArg = escapeshellarg(dirname($assetsPath));
155 155
 
156 156
 		// Move existing assets to assets.old
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 */
178 178
 	public function putgit($details) {
179 179
 		$this->exec(array('git', 'clone', $details['remote'], $this->path));
180
-		$this->exec("cd $this->path && git checkout " . escapeshellarg($details['branch']));
180
+		$this->exec("cd $this->path && git checkout ".escapeshellarg($details['branch']));
181 181
 		return true;
182 182
 	}
183 183
 }
Please login to merge, or discard this patch.