Completed
Pull Request — master (#89)
by Steve
13s
created
tests/DataExtractor/CsvTableReaderTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     public function testCsvReading()
11 11
     {
12 12
 
13
-        $csv = new CsvTableReader(__DIR__ . '/fixture/input.csv');
13
+        $csv = new CsvTableReader(__DIR__.'/fixture/input.csv');
14 14
         $this->assertEquals(['Col1', 'Col2', 'Col3'], $csv->getColumns());
15 15
 
16 16
         $extractedData = [];
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 
21 21
         $this->assertEquals(
22 22
             [
23
-                [ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ],
24
-                [ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]
23
+                ['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three'],
24
+                ['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]
25 25
             ],
26 26
             $extractedData
27 27
         );
Please login to merge, or discard this patch.
tests/DataExtractor/CsvTableWriterTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
         $csv = new CsvTableWriter('/tmp/output.csv');
17 17
 
18 18
         $csv->start(['Col1', 'Col2', 'Col3']);
19
-        $csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]);
20
-        $csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]);
19
+        $csv->writeRecord(['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three']);
20
+        $csv->writeRecord(['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]);
21 21
         $csv->finish();
22 22
 
23 23
         $csvContent = file_get_contents('/tmp/output.csv');
24 24
         unlink('/tmp/output.csv');
25 25
 
26
-        $fixture = file_get_contents(__DIR__ . '/fixture/input.csv');
26
+        $fixture = file_get_contents(__DIR__.'/fixture/input.csv');
27 27
 
28 28
         $this->assertEquals($fixture, $csvContent);
29 29
     }
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 
38 38
         $csv = new CsvTableWriter('/tmp/output.csv');
39 39
 
40
-        $csv->writeRecord([ 'Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three' ]);
41
-        $csv->writeRecord([ 'Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?" ]);
40
+        $csv->writeRecord(['Col1' => 'One', 'Col2' => 2, 'Col3' => 'Three']);
41
+        $csv->writeRecord(['Col1' => 'Hello, Sam', 'Col2' => 5, 'Col3' => "Nice to meet you\nWhat is your name?"]);
42 42
         $csv->finish();
43 43
 
44 44
         $csvContent = file_get_contents('/tmp/output.csv');
45 45
         unlink('/tmp/output.csv');
46 46
 
47
-        $fixture = file_get_contents(__DIR__ . '/fixture/input.csv');
47
+        $fixture = file_get_contents(__DIR__.'/fixture/input.csv');
48 48
 
49 49
         $this->assertEquals($fixture, $csvContent);
50 50
     }
Please login to merge, or discard this patch.
src/FilesystemEntity.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
         $this->executor = $executor;
20 20
 
21 21
         if (strpos($path, ':') !== false) {
22
-            list($this->server,$this->path) = explode(':', $path, 2);
22
+            list($this->server, $this->path) = explode(':', $path, 2);
23 23
         } else {
24 24
             $this->server = null;
25 25
             $this->path = $path;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function uploadContent($content, $dest)
92 92
     {
93
-        $this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($dest));
93
+        $this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($dest));
94 94
     }
95 95
 
96 96
     /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         }
123 123
 
124 124
         if ($this->server) {
125
-            $result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi");
125
+            $result = $this->exec("if [ -e ".escapeshellarg($file)." ]; then echo yes; fi");
126 126
             return (trim($result['output']) == 'yes');
127 127
         } else {
128 128
             return file_exists($file);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function writeFile($file, $content)
136 136
     {
137 137
         if ($this->server) {
138
-            $this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($file));
138
+            $this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($file));
139 139
         } else {
140 140
             file_put_contents($file, $content);
141 141
         }
Please login to merge, or discard this patch.
src/DataExtractor/CsvTableReader.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
             if (isset($this->columns[$i])) {
41 41
                 $record[$this->columns[$i]] = $value;
42 42
             } else {
43
-                throw new \LogicException("Row contains invalid column #$i\n" . var_export($row, true));
43
+                throw new \LogicException("Row contains invalid column #$i\n".var_export($row, true));
44 44
             }
45 45
         }
46 46
         return $record;
Please login to merge, or discard this patch.
src/DataExtractor/DatabaseConnector.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,22 +27,22 @@
 block discarded – undo
27 27
         $this->isConnected = true;
28 28
 
29 29
         // Necessary for SilverStripe's _ss_environment.php loader to work
30
-        $_SERVER['SCRIPT_FILENAME'] = $this->basePath . '/dummy.php';
30
+        $_SERVER['SCRIPT_FILENAME'] = $this->basePath.'/dummy.php';
31 31
 
32 32
         global $databaseConfig;
33 33
 
34 34
         // require composers autoloader
35
-        if (file_exists($this->basePath . '/vendor/autoload.php')) {
36
-            require_once $this->basePath . '/vendor/autoload.php';
35
+        if (file_exists($this->basePath.'/vendor/autoload.php')) {
36
+            require_once $this->basePath.'/vendor/autoload.php';
37 37
         }
38 38
 
39
-        if (file_exists($this->basePath . '/framework/core/Core.php')) {
40
-            require_once($this->basePath . '/framework/core/Core.php');
41
-        } elseif (file_exists($this->basePath . '/sapphire/core/Core.php')) {
42
-            require_once($this->basePath . '/sapphire/core/Core.php');
39
+        if (file_exists($this->basePath.'/framework/core/Core.php')) {
40
+            require_once($this->basePath.'/framework/core/Core.php');
41
+        } elseif (file_exists($this->basePath.'/sapphire/core/Core.php')) {
42
+            require_once($this->basePath.'/sapphire/core/Core.php');
43 43
         } else {
44 44
             throw new \LogicException(
45
-                "No framework/core/Core.php or sapphire/core/Core.php included in project. " .
45
+                "No framework/core/Core.php or sapphire/core/Core.php included in project. ".
46 46
                 "Perhaps $this->basePath is not a SilverStripe project?"
47 47
             );
48 48
         }
Please login to merge, or discard this patch.
src/Process.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@
 block discarded – undo
33 33
                 $ssh = "ssh -t ";
34 34
             }
35 35
             if (!empty($options['identity'])) {
36
-                $ssh .= '-i ' . escapeshellarg($options['identity']) . ' ';
36
+                $ssh .= '-i '.escapeshellarg($options['identity']).' ';
37 37
             }
38
-            $command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command);
38
+            $command = $ssh.escapeshellarg($this->remoteServer).' '.escapeshellarg($this->command);
39 39
         } else {
40 40
             $command = $this->command;
41 41
         }
Please login to merge, or discard this patch.
src/Args.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function sudo($optionalPrefix)
65 65
     {
66
-        if (!empty($this->namedArgs[$optionalPrefix . '-sudo'])) {
67
-            return $this->namedArgs[$optionalPrefix . '-sudo'];
66
+        if (!empty($this->namedArgs[$optionalPrefix.'-sudo'])) {
67
+            return $this->namedArgs[$optionalPrefix.'-sudo'];
68 68
         } elseif (!empty($this->namedArgs['sudo'])) {
69 69
             return $this->namedArgs['sudo'];
70 70
         } else {
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     {
80 80
         // Look up which parts of the sspak are going to be saved
81 81
         $pakParks = array();
82
-        foreach (array('assets','db','git-remote') as $part) {
82
+        foreach (array('assets', 'db', 'git-remote') as $part) {
83 83
             $pakParts[$part] = !empty($this->namedArgs[$part]);
84 84
         }
85 85
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function requireUnnamed($items)
94 94
     {
95 95
         if (sizeof($this->unnamedArgs) < sizeof($items)) {
96
-            echo "Usage: {$_SERVER['argv'][0]} " . $this->action . " (";
96
+            echo "Usage: {$_SERVER['argv'][0]} ".$this->action." (";
97 97
             echo implode(") (", $items);
98 98
             echo ")\n";
99 99
             throw new Exception('Arguments missing.');
Please login to merge, or discard this patch.
src/Webroot.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
         global $snifferFileContent;
38 38
 
39 39
         if (!$snifferFileContent) {
40
-            $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php');
40
+            $snifferFileContent = file_get_contents(PACKAGE_ROOT.'src/sspak-sniffer.php');
41 41
         }
42 42
 
43
-        $remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000, 999999) . '.php';
43
+        $remoteSniffer = '/tmp/sspak-sniffer-'.rand(100000, 999999).'.php';
44 44
         $this->uploadContent($snifferFileContent, $remoteSniffer);
45 45
 
46 46
         $result = $this->execSudo(array('/usr/bin/env', 'php', $remoteSniffer, $this->path));
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             }
68 68
             // Try running sudo without asking for a password
69 69
             try {
70
-                return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command, $options);
70
+                return $this->exec("sudo -n -u ".escapeshellarg($this->sudo)." ".$command, $options);
71 71
 
72 72
             // Otherwise capture SUDO password ourselves and pass it in through STDIN
73 73
             } catch (Exception $e) {
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 $password = fgets($stdin);
77 77
 
78 78
                 return $this->exec(
79
-                    "sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command,
79
+                    "sudo -S -p '' -u ".escapeshellarg($this->sudo)." ".$command,
80 80
                     array('inputContent' => $password)
81 81
                 );
82 82
             }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         // Check the database type
99 99
         $dbFunction = 'putdb_'.$details['db_type'];
100 100
         if (!method_exists($this, $dbFunction)) {
101
-            throw new Exception("Can't process database type '" . $details['db_type'] . "'");
101
+            throw new Exception("Can't process database type '".$details['db_type']."'");
102 102
         }
103 103
 
104 104
         // Extract DB direct from sspak file
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $hostArg = '';
120 120
         $portArg = '';
121 121
         if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') {
122
-            if (strpos($conf['db_server'], ':')!==false) {
122
+            if (strpos($conf['db_server'], ':') !== false) {
123 123
                 // Handle "server:port" format.
124 124
                 $server = explode(':', $conf['db_server'], 2);
125 125
                 $hostArg = escapeshellarg("--host=".$server[0]);
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
                 $hostArg = escapeshellarg("--host=".$conf['db_server']);
129 129
             }
130 130
         }
131
-        $dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`";
131
+        $dbCommand = "create database if not exists `".addslashes($conf['db_database'])."`";
132 132
         if ($dropdb) {
133
-            $dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand;
133
+            $dbCommand = "drop database if exists `".addslashes($conf['db_database'])."`; ".$dbCommand;
134 134
         }
135 135
 
136 136
         $this->exec("echo '$dbCommand' | mysql $usernameArg $passwordArg $hostArg $portArg");
137 137
 
138 138
         $stream = $sspak->readStreamForFile('database.sql.gz');
139
-        $this->exec("gunzip -c | sed '/^CREATE DATABASE/d;/^USE/d' | mysql --default-character-set=utf8 " .
139
+        $this->exec("gunzip -c | sed '/^CREATE DATABASE/d;/^USE/d' | mysql --default-character-set=utf8 ".
140 140
         "$usernameArg $passwordArg $hostArg $portArg $databaseArg", array('inputStream' => $stream));
141 141
         fclose($stream);
142 142
         return true;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         $hostArg = escapeshellarg("--host=".$conf['db_server']);
152 152
 
153 153
         // Create database if needed
154
-        $result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | " .
154
+        $result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | ".
155 155
         "$passwordArg psql $usernameArg $hostArg $databaseArg -qt");
156 156
         if (trim($result['output']) == '0') {
157 157
             $this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg");
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         );
182 182
         $assetsPath = trim($assetsPathExec["output"]);
183 183
 
184
-        $assetsOldPath = $assetsPath . '.old';
184
+        $assetsOldPath = $assetsPath.'.old';
185 185
         $assetsParentArg = escapeshellarg(dirname($assetsPath));
186 186
 
187 187
         // Move existing assets to assets.old
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     public function putgit($details)
212 212
     {
213 213
         $this->exec(array('git', 'clone', $details['remote'], $this->path));
214
-        $this->exec("cd $this->path && git checkout " . escapeshellarg($details['branch']));
214
+        $this->exec("cd $this->path && git checkout ".escapeshellarg($details['branch']));
215 215
         return true;
216 216
     }
217 217
 }
Please login to merge, or discard this patch.
src/SSPak.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
                 "method" => "load",
46 46
             ),
47 47
             "saveexisting" => array(
48
-                "description" => "Create an .sspak file from database SQL dump and/or assets. " .
48
+                "description" => "Create an .sspak file from database SQL dump and/or assets. ".
49 49
                 "Does not require a SilverStripe site.",
50 50
                 "unnamedArgs" => array("sspak file"),
51 51
                 "namedArgs" => array("db", "assets"),
52 52
                 "method" => "saveexisting"
53 53
             ),
54 54
             "extract" => array(
55
-                "description" => "Extract an .sspak file into the current working directory. Does not require a " .
55
+                "description" => "Extract an .sspak file into the current working directory. Does not require a ".
56 56
                  "SilverStripe site.",
57 57
                 "unnamedArgs" => array("sspak file", "destination path"),
58 58
                 "method" => "extract"
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         // from other formats.
174 174
         // There is no cross-platform way of checking the assets.tar.gz size without unpacking, so we assume the size
175 175
         // of database is negligible which lets us approximate the size of assets.
176
-        if (filesize($file) > 8*1024*1024*1024) {
176
+        if (filesize($file) > 8 * 1024 * 1024 * 1024) {
177 177
             $msg = <<<EOM
178 178
 
179 179
 ERROR: SSPak is unable to extract archives over 8 GB.
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
         $db = new DatabaseConnector($webroot);
231 231
 
232 232
         foreach ($db->getTables() as $table) {
233
-            $filename = $destPath . '/' . $table . '.csv';
234
-            echo $filename . "...\n";
233
+            $filename = $destPath.'/'.$table.'.csv';
234
+            echo $filename."...\n";
235 235
             touch($filename);
236 236
             $writer = new CsvTableWriter($filename);
237 237
             $db->saveTable($table, $writer);
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
         $db = new DatabaseConnector($webroot);
255 255
 
256 256
         foreach ($db->getTables() as $table) {
257
-            $filename = $srcPath . '/' . $table . '.csv';
257
+            $filename = $srcPath.'/'.$table.'.csv';
258 258
             if (file_exists($filename)) {
259
-                echo $filename . "...\n";
259
+                echo $filename."...\n";
260 260
                 $reader = new CsvTableReader($filename);
261 261
                 $db->loadTable($table, $reader);
262 262
             } else {
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             // Check the database type
318 318
             $dbFunction = 'getdb_'.$details['db_type'];
319 319
             if (!method_exists($this, $dbFunction)) {
320
-                throw new Exception("Can't process database type '" . $details['db_type'] . "'");
320
+                throw new Exception("Can't process database type '".$details['db_type']."'");
321 321
             }
322 322
             $this->$dbFunction($webroot, $details, $sspak, basename($dbFile));
323 323
         }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         $hostArg = '';
351 351
         $portArg = '';
352 352
         if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') {
353
-            if (strpos($conf['db_server'], ':')!==false) {
353
+            if (strpos($conf['db_server'], ':') !== false) {
354 354
                 // Handle "server:port" format.
355 355
                 $server = explode(':', $conf['db_server'], 2);
356 356
                 $hostArg = escapeshellarg("--host=".$server[0]);
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
         $filenameArg = escapeshellarg($filename);
364 364
 
365 365
         $process = $webroot->createProcess(
366
-            "mysqldump --no-tablespaces --skip-opt --add-drop-table --extended-insert --create-options --quick " .
367
-            "--set-charset --default-character-set=utf8 --column-statistics=0 $usernameArg $passwordArg $hostArg " .
366
+            "mysqldump --no-tablespaces --skip-opt --add-drop-table --extended-insert --create-options --quick ".
367
+            "--set-charset --default-character-set=utf8 --column-statistics=0 $usernameArg $passwordArg $hostArg ".
368 368
             "$portArg $databaseArg | gzip -c"
369 369
         );
370 370
         $sspak->writeFileFromProcess($filename, $process);
@@ -398,17 +398,17 @@  discard block
 block discarded – undo
398 398
     public function getgitremote($webroot, $sspak, $gitRemoteFile)
399 399
     {
400 400
         // Only do anything if we're copying from a git checkout
401
-        $gitRepo = $webroot->getPath() .'/.git';
401
+        $gitRepo = $webroot->getPath().'/.git';
402 402
         if ($webroot->exists($gitRepo)) {
403 403
             // Identify current branch
404 404
             $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'branch'));
405 405
             if (preg_match("/\* ([^ \n]*)/", $output['output'], $matches) &&
406
-                strpos("(no branch)", $matches[1])===false
406
+                strpos("(no branch)", $matches[1]) === false
407 407
             ) {
408 408
                 // If there is a current branch, use that branch's remove
409 409
                 $currentBranch = trim($matches[1]);
410 410
                 $output = $webroot->exec(
411
-                    array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote")
411
+                    array('git', '--git-dir='.$gitRepo, 'config', '--get', "branch.$currentBranch.remote")
412 412
                 );
413 413
                 $remoteName = trim($output['output']);
414 414
                 if (!$remoteName) {
@@ -422,11 +422,11 @@  discard block
 block discarded – undo
422 422
             }
423 423
 
424 424
             // Determine the URL of that remote
425
-            $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"remote.$remoteName.url"));
425
+            $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "remote.$remoteName.url"));
426 426
             $remoteURL = trim($output['output']);
427 427
 
428 428
             // Determine the current SHA
429
-            $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log','-1','--format=%H'));
429
+            $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log', '-1', '--format=%H'));
430 430
             $sha = trim($output['output']);
431 431
 
432 432
             $content = "remote = $remoteURL\nbranch = $currentBranch\nsha = $sha\n";
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
         $sspakScript = str_replace('$isSelfExtracting = false;', '$isSelfExtracting = true;', $sspakScript);
548 548
 
549 549
         // Load the sniffer file
550
-        $snifferFile = dirname(__FILE__) . '/sspak-sniffer.php';
550
+        $snifferFile = dirname(__FILE__).'/sspak-sniffer.php';
551 551
         $sspakScript = str_replace(
552 552
             "\$snifferFileContent = '';\n",
553 553
             "\$snifferFileContent = '"
554
-            . str_replace(array("\\","'"), array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n",
554
+            . str_replace(array("\\", "'"), array("\\\\", "\\'"), file_get_contents($snifferFile))."';\n",
555 555
             $sspakScript
556 556
         );
557 557
 
Please login to merge, or discard this patch.