@@ -26,19 +26,19 @@ discard block |
||
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 |
||
56 | 56 | public 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 |
||
69 | 69 | public 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 |
||
82 | 82 | public 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 |
||
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]); |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | public 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 |
||
51 | 51 | * Return the sudo argument, preferring a more specific one with the given optional prefix |
52 | 52 | */ |
53 | 53 | public 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 |
||
62 | 62 | public 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 | public 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.'); |
@@ -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 | public 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 |
@@ -6,18 +6,18 @@ |
||
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 | ); |