@@ -16,7 +16,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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); |
@@ -35,7 +35,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -67,13 +67,19 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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())); |
@@ -13,7 +13,9 @@ |
||
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); |
@@ -8,7 +8,9 @@ discard block |
||
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 |
||
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 { |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | $this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak")); |
46 | 50 | |
47 | 51 | foreach(scandir($srcRoot) as $file) { |
48 | - if($file[0] == '.') continue; |
|
52 | + if($file[0] == '.') { |
|
53 | + continue; |
|
54 | + } |
|
49 | 55 | $this->phar['src/'.$file] = file_get_contents($srcRoot . $file); |
50 | 56 | } |
51 | 57 | |
@@ -139,7 +145,9 @@ discard block |
||
139 | 145 | $content = $this->content('git-remote'); |
140 | 146 | $details = array(); |
141 | 147 | foreach(explode("\n", trim($content)) as $line) { |
142 | - if(!$line) continue; |
|
148 | + if(!$line) { |
|
149 | + continue; |
|
150 | + } |
|
143 | 151 | |
144 | 152 | if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { |
145 | 153 | $details[$matches[1]] = $matches[2]; |
@@ -51,9 +51,13 @@ discard block |
||
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 |
||
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 |
@@ -98,8 +98,12 @@ discard block |
||
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 |
||
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 | } |