Completed
Pull Request — master (#31)
by
unknown
02:42
created
src/MySql/Helper/CompoundSyntaxStore.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@
 block discarded – undo
114 114
     if ($trim) $line = trim($line);
115 115
 
116 116
     $words = explode(' ', $line);
117
-    if (count($words)>0)
117
+    if (count($words) > 0)
118 118
     {
119 119
       switch ($words[0])
120 120
       {
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -10,150 +10,150 @@
 block discarded – undo
10 10
  */
11 11
 class CompoundSyntaxStore
12 12
 {
13
-  //--------------------------------------------------------------------------------------------------------------------
14
-  /**
15
-   * The the number of spaces per indent level.
16
-   *
17
-   * @var int
18
-   */
19
-  public static $indentation = 2;
20
-
21
-  /**
22
-   * The current indent level of the code.
23
-   *
24
-   * @var int
25
-   */
26
-  private $indentLevel = 0;
27
-
28
-  /**
29
-   * The source code. Each element is a line.
30
-   *
31
-   * @var string[]
32
-   */
33
-  private $lines = [];
34
-
35
-  //--------------------------------------------------------------------------------------------------------------------
36
-  /**
37
-   * Object constructor.
38
-   */
39
-  public function __construct()
40
-  {
13
+    //--------------------------------------------------------------------------------------------------------------------
14
+    /**
15
+     * The the number of spaces per indent level.
16
+     *
17
+     * @var int
18
+     */
19
+    public static $indentation = 2;
20
+
21
+    /**
22
+     * The current indent level of the code.
23
+     *
24
+     * @var int
25
+     */
26
+    private $indentLevel = 0;
27
+
28
+    /**
29
+     * The source code. Each element is a line.
30
+     *
31
+     * @var string[]
32
+     */
33
+    private $lines = [];
34
+
35
+    //--------------------------------------------------------------------------------------------------------------------
36
+    /**
37
+     * Object constructor.
38
+     */
39
+    public function __construct()
40
+    {
41 41
     // Nothing to do.
42
-  }
43
-
44
-  //--------------------------------------------------------------------------------------------------------------------
45
-  /**
46
-   * Appends a line or lines of code this this code.
47
-   *
48
-   * @param null|string|string[] $line The line or lines of code to be appended.
49
-   * @param bool                 $trim If true the line or lines of code will be trimmed before appending.
50
-   */
51
-  public function append($line, $trim = true)
52
-  {
42
+    }
43
+
44
+    //--------------------------------------------------------------------------------------------------------------------
45
+    /**
46
+     * Appends a line or lines of code this this code.
47
+     *
48
+     * @param null|string|string[] $line The line or lines of code to be appended.
49
+     * @param bool                 $trim If true the line or lines of code will be trimmed before appending.
50
+     */
51
+    public function append($line, $trim = true)
52
+    {
53 53
     switch (true)
54 54
     {
55
-      case is_string($line):
55
+        case is_string($line):
56 56
         $this->appendLine($line, $trim);
57 57
         break;
58 58
 
59
-      case is_array($line):
59
+        case is_array($line):
60 60
         $this->appendLines($line, $trim);
61 61
         break;
62 62
 
63
-      case is_null($line):
63
+        case is_null($line):
64 64
         // Nothing to do.
65 65
         break;
66 66
 
67
-      default:
67
+        default:
68 68
         throw new RuntimeException('Nor a string or array.');
69 69
     }
70
-  }
71
-
72
-  //--------------------------------------------------------------------------------------------------------------------
73
-  /**
74
-   * Appends a part of code to the last line of code.
75
-   *
76
-   * @param string $part The part of code to be to the last line.
77
-   */
78
-  public function appendToLastLine($part)
79
-  {
70
+    }
71
+
72
+    //--------------------------------------------------------------------------------------------------------------------
73
+    /**
74
+     * Appends a part of code to the last line of code.
75
+     *
76
+     * @param string $part The part of code to be to the last line.
77
+     */
78
+    public function appendToLastLine($part)
79
+    {
80 80
     $this->lines[count($this->lines) - 1] .= $part;
81
-  }
82
-
83
-  //--------------------------------------------------------------------------------------------------------------------
84
-  /**
85
-   * Returns the generated code as a single string.
86
-   */
87
-  public function getCode()
88
-  {
81
+    }
82
+
83
+    //--------------------------------------------------------------------------------------------------------------------
84
+    /**
85
+     * Returns the generated code as a single string.
86
+     */
87
+    public function getCode()
88
+    {
89 89
     return implode(PHP_EOL, $this->lines);
90
-  }
91
-
92
-  //--------------------------------------------------------------------------------------------------------------------
93
-  /**
94
-   * Returns a line of code with the proper amount of indentation.
95
-   *
96
-   * @param string $line The line of code.
97
-   *
98
-   * @return string The indented line of code.
99
-   */
100
-  private function addIndentation($line)
101
-  {
90
+    }
91
+
92
+    //--------------------------------------------------------------------------------------------------------------------
93
+    /**
94
+     * Returns a line of code with the proper amount of indentation.
95
+     *
96
+     * @param string $line The line of code.
97
+     *
98
+     * @return string The indented line of code.
99
+     */
100
+    private function addIndentation($line)
101
+    {
102 102
     return str_repeat(' ', self::$indentation * $this->indentLevel).$line;
103
-  }
104
-
105
-  //--------------------------------------------------------------------------------------------------------------------
106
-  /**
107
-   * Appends a line of code this this code.
108
-   *
109
-   * @param string $line The line of code to be appended.
110
-   * @param bool   $trim If true the line of code will be trimmed before appending.
111
-   */
112
-  private function appendLine($line, $trim)
113
-  {
103
+    }
104
+
105
+    //--------------------------------------------------------------------------------------------------------------------
106
+    /**
107
+     * Appends a line of code this this code.
108
+     *
109
+     * @param string $line The line of code to be appended.
110
+     * @param bool   $trim If true the line of code will be trimmed before appending.
111
+     */
112
+    private function appendLine($line, $trim)
113
+    {
114 114
     if ($trim) $line = trim($line);
115 115
 
116 116
     $words = explode(' ', $line);
117 117
     if (count($words)>0)
118 118
     {
119
-      switch ($words[0])
120
-      {
119
+        switch ($words[0])
120
+        {
121 121
         case 'begin':
122 122
         case 'if':
123 123
           $line = $this->addIndentation($line);
124
-          $this->indentLevel += 1;
125
-          break;
124
+            $this->indentLevel += 1;
125
+            break;
126 126
 
127 127
         case 'end':
128 128
           $this->indentLevel = max(0, $this->indentLevel - 1);
129
-          $line              = $this->addIndentation($line);
130
-          break;
129
+            $line              = $this->addIndentation($line);
130
+            break;
131 131
 
132 132
         default:
133 133
           $line = $this->addIndentation($line);
134
-          break;
135
-      }
134
+            break;
135
+        }
136 136
     }
137 137
 
138 138
     $this->lines[] = $line;
139
-  }
140
-
141
-  //--------------------------------------------------------------------------------------------------------------------
142
-  /**
143
-   * Appends lines of code this this code.
144
-   *
145
-   * @param string[] $lines The lines of code to be appended.
146
-   * @param bool     $trim  If true the lines of code will be trimmed before appending.
147
-   */
148
-  private function appendLines($lines, $trim)
149
-  {
139
+    }
140
+
141
+    //--------------------------------------------------------------------------------------------------------------------
142
+    /**
143
+     * Appends lines of code this this code.
144
+     *
145
+     * @param string[] $lines The lines of code to be appended.
146
+     * @param bool     $trim  If true the lines of code will be trimmed before appending.
147
+     */
148
+    private function appendLines($lines, $trim)
149
+    {
150 150
     foreach ($lines as $line)
151 151
     {
152
-      $this->appendLine($line, $trim);
152
+        $this->appendLine($line, $trim);
153
+    }
153 154
     }
154
-  }
155 155
 
156
-  //--------------------------------------------------------------------------------------------------------------------
156
+    //--------------------------------------------------------------------------------------------------------------------
157 157
 }
158 158
 
159 159
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -111,7 +111,9 @@
 block discarded – undo
111 111
    */
112 112
   private function appendLine($line, $trim)
113 113
   {
114
-    if ($trim) $line = trim($line);
114
+    if ($trim) {
115
+        $line = trim($line);
116
+    }
115 117
 
116 118
     $words = explode(' ', $line);
117 119
     if (count($words)>0)
Please login to merge, or discard this patch.
src/Command/AboutCommand.php 2 patches
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
     $this->io->write(<<<EOT
35 35
 <info>AuditApplication - Database Auditing</info>
36 36
 <comment>Creates audit tables and triggers to track data changes in databases.</comment>
37
-EOT
37
+eot
38 38
     );
39 39
   }
40 40
 
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class AboutCommand extends BaseCommand
14 14
 {
15
-  //--------------------------------------------------------------------------------------------------------------------
16
-  /**
17
-   * {@inheritdoc}
18
-   */
19
-  protected function configure()
20
-  {
15
+    //--------------------------------------------------------------------------------------------------------------------
16
+    /**
17
+     * {@inheritdoc}
18
+     */
19
+    protected function configure()
20
+    {
21 21
     $this->setName('about')
22
-         ->setDescription('Short information about AuditApplication')
23
-         ->setHelp('<info>audit about</info>');
24
-  }
22
+            ->setDescription('Short information about AuditApplication')
23
+            ->setHelp('<info>audit about</info>');
24
+    }
25 25
 
26
-  //--------------------------------------------------------------------------------------------------------------------
27
-  /**
28
-   * {@inheritdoc}
29
-   */
30
-  protected function execute(InputInterface $input, OutputInterface $output)
31
-  {
26
+    //--------------------------------------------------------------------------------------------------------------------
27
+    /**
28
+     * {@inheritdoc}
29
+     */
30
+    protected function execute(InputInterface $input, OutputInterface $output)
31
+    {
32 32
     $this->io = $this->io = new StratumStyle($input, $output);
33 33
 
34 34
     $this->io->write(<<<EOT
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 <comment>Creates audit tables and triggers to track data changes in databases.</comment>
37 37
 EOT
38 38
     );
39
-  }
39
+    }
40 40
 
41
-  //--------------------------------------------------------------------------------------------------------------------
41
+    //--------------------------------------------------------------------------------------------------------------------
42 42
 }
43 43
 
44 44
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/DataLayer.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -386,8 +386,7 @@
 block discarded – undo
386 386
       // Query is a multi line query.
387 387
       self::$io->logVeryVerbose('Executing query:');
388 388
       self::$io->logVeryVerbose('<sql>%s</sql>', $query);
389
-    }
390
-    else
389
+    } else
391 390
     {
392 391
       // Query is a single line query.
393 392
       self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                      $auditColumns,
119 119
                                      $skipVariable,
120 120
                                      $additionSql);
121
-    $sql    = $helper->buildStatement();
121
+    $sql = $helper->buildStatement();
122 122
 
123 123
     self::executeNone($sql);
124 124
   }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
    */
130 130
   public static function disconnect()
131 131
   {
132
-    if (self::$dl!==null)
132
+    if (self::$dl !== null)
133 133
     {
134 134
       self::$dl->disconnect();
135 135
       self::$dl = null;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     foreach ($auditColumns as $column)
311 311
     {
312 312
       $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
313
-      if (end($auditColumns)!==$column)
313
+      if (end($auditColumns) !== $column)
314 314
       {
315 315
         $sql->appendToLastLine(',');
316 316
       }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
   {
425 425
     $query = trim($query);
426 426
 
427
-    if (strpos($query, "\n")!==false)
427
+    if (strpos($query, "\n") !== false)
428 428
     {
429 429
       // Query is a multi line query.
430 430
       self::$io->logVeryVerbose('Executing query:');
Please login to merge, or discard this patch.
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -16,90 +16,90 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class DataLayer
18 18
 {
19
-  //--------------------------------------------------------------------------------------------------------------------
20
-  /**
21
-   * The connection to the MySQL instance.
22
-   *
23
-   * @var StaticDataLayer
24
-   */
25
-  private static $dl;
26
-
27
-  /**
28
-   * The Output decorator.
29
-   *
30
-   * @var StratumStyle
31
-   */
32
-  private static $io;
33
-
34
-  //--------------------------------------------------------------------------------------------------------------------
35
-  /**
36
-   * Adds new columns to an audit table.
37
-   *
38
-   * @param string                              $auditSchemaName The name of audit schema.
39
-   * @param string                              $tableName       The name of the table.
40
-   * @param \SetBased\Audit\MySql\Table\Columns $columns         The metadata of the new columns.
41
-   */
42
-  public static function addNewColumns($auditSchemaName, $tableName, $columns)
43
-  {
19
+    //--------------------------------------------------------------------------------------------------------------------
20
+    /**
21
+     * The connection to the MySQL instance.
22
+     *
23
+     * @var StaticDataLayer
24
+     */
25
+    private static $dl;
26
+
27
+    /**
28
+     * The Output decorator.
29
+     *
30
+     * @var StratumStyle
31
+     */
32
+    private static $io;
33
+
34
+    //--------------------------------------------------------------------------------------------------------------------
35
+    /**
36
+     * Adds new columns to an audit table.
37
+     *
38
+     * @param string                              $auditSchemaName The name of audit schema.
39
+     * @param string                              $tableName       The name of the table.
40
+     * @param \SetBased\Audit\MySql\Table\Columns $columns         The metadata of the new columns.
41
+     */
42
+    public static function addNewColumns($auditSchemaName, $tableName, $columns)
43
+    {
44 44
     $helper = new AlterAuditTableAddColumns($auditSchemaName, $tableName, $columns);
45 45
     $sql    = $helper->buildStatement();
46 46
 
47 47
     self::executeNone($sql);
48
-  }
49
-
50
-  //--------------------------------------------------------------------------------------------------------------------
51
-  /**
52
-   * Connects to a MySQL instance.
53
-   *
54
-   * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception
55
-   * is thrown.
56
-   *
57
-   * @param string $host     The hostname.
58
-   * @param string $user     The MySQL user name.
59
-   * @param string $passWord The password.
60
-   * @param string $database The default database.
61
-   * @param int    $port     The port number.
62
-   */
63
-  public static function connect($host, $user, $passWord, $database, $port = 3306)
64
-  {
48
+    }
49
+
50
+    //--------------------------------------------------------------------------------------------------------------------
51
+    /**
52
+     * Connects to a MySQL instance.
53
+     *
54
+     * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception
55
+     * is thrown.
56
+     *
57
+     * @param string $host     The hostname.
58
+     * @param string $user     The MySQL user name.
59
+     * @param string $passWord The password.
60
+     * @param string $database The default database.
61
+     * @param int    $port     The port number.
62
+     */
63
+    public static function connect($host, $user, $passWord, $database, $port = 3306)
64
+    {
65 65
     self::$dl = new StaticDataLayer();
66 66
 
67 67
     self::$dl->connect($host, $user, $passWord, $database, $port);
68
-  }
69
-
70
-  //--------------------------------------------------------------------------------------------------------------------
71
-  /**
72
-   * Creates an audit table.
73
-   *
74
-   * @param string  $dataSchemaName  The name of the data schema.
75
-   * @param string  $auditSchemaName The name of the audit schema.
76
-   * @param string  $tableName       The name of the table.
77
-   * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
78
-   *                                 of the data table).
79
-   */
80
-  public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns)
81
-  {
68
+    }
69
+
70
+    //--------------------------------------------------------------------------------------------------------------------
71
+    /**
72
+     * Creates an audit table.
73
+     *
74
+     * @param string  $dataSchemaName  The name of the data schema.
75
+     * @param string  $auditSchemaName The name of the audit schema.
76
+     * @param string  $tableName       The name of the table.
77
+     * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
78
+     *                                 of the data table).
79
+     */
80
+    public static function createAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns)
81
+    {
82 82
     $helper = new CreateAuditTable($dataSchemaName, $auditSchemaName, $tableName, $columns);
83 83
     $sql    = $helper->buildStatement();
84 84
 
85 85
     self::executeNone($sql);
86
-  }
87
-
88
-  //--------------------------------------------------------------------------------------------------------------------
89
-  /**
90
-   * Creates a trigger on a table.
91
-   *
92
-   * @param string                              $dataSchemaName  The name of the data schema.
93
-   * @param string                              $auditSchemaName The name of the audit schema.
94
-   * @param string                              $tableName       The name of the table.
95
-   * @param string                              $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
-   * @param string                              $triggerName     The name of the trigger.
97
-   * @param \SetBased\Audit\MySql\Table\Columns $tableColumns    The data table columns.
98
-   * @param \SetBased\Audit\MySql\Table\Columns $auditColumns    The audit table columns.
99
-   * @param string                              $skipVariable    The skip variable.
100
-   * @param string[]                            $additionSql     Additional SQL statements.
101
-   */
102
-  public static function createAuditTrigger($dataSchemaName,
86
+    }
87
+
88
+    //--------------------------------------------------------------------------------------------------------------------
89
+    /**
90
+     * Creates a trigger on a table.
91
+     *
92
+     * @param string                              $dataSchemaName  The name of the data schema.
93
+     * @param string                              $auditSchemaName The name of the audit schema.
94
+     * @param string                              $tableName       The name of the table.
95
+     * @param string                              $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
+     * @param string                              $triggerName     The name of the trigger.
97
+     * @param \SetBased\Audit\MySql\Table\Columns $tableColumns    The data table columns.
98
+     * @param \SetBased\Audit\MySql\Table\Columns $auditColumns    The audit table columns.
99
+     * @param string                              $skipVariable    The skip variable.
100
+     * @param string[]                            $additionSql     Additional SQL statements.
101
+     */
102
+    public static function createAuditTrigger($dataSchemaName,
103 103
                                             $auditSchemaName,
104 104
                                             $tableName,
105 105
                                             $triggerAction,
@@ -108,151 +108,151 @@  discard block
 block discarded – undo
108 108
                                             $auditColumns,
109 109
                                             $skipVariable,
110 110
                                             $additionSql)
111
-  {
111
+    {
112 112
     $helper = new CreateAuditTrigger($dataSchemaName,
113
-                                     $auditSchemaName,
114
-                                     $tableName,
115
-                                     $triggerAction,
116
-                                     $triggerName,
117
-                                     $tableColumns,
118
-                                     $auditColumns,
119
-                                     $skipVariable,
120
-                                     $additionSql);
113
+                                        $auditSchemaName,
114
+                                        $tableName,
115
+                                        $triggerAction,
116
+                                        $triggerName,
117
+                                        $tableColumns,
118
+                                        $auditColumns,
119
+                                        $skipVariable,
120
+                                        $additionSql);
121 121
     $sql    = $helper->buildStatement();
122 122
 
123 123
     self::executeNone($sql);
124
-  }
125
-
126
-  //--------------------------------------------------------------------------------------------------------------------
127
-  /**
128
-   * Closes the connection to the MySQL instance, if connected.
129
-   */
130
-  public static function disconnect()
131
-  {
124
+    }
125
+
126
+    //--------------------------------------------------------------------------------------------------------------------
127
+    /**
128
+     * Closes the connection to the MySQL instance, if connected.
129
+     */
130
+    public static function disconnect()
131
+    {
132 132
     if (self::$dl!==null)
133 133
     {
134
-      self::$dl->disconnect();
135
-      self::$dl = null;
134
+        self::$dl->disconnect();
135
+        self::$dl = null;
136 136
     }
137
-  }
138
-
139
-  //--------------------------------------------------------------------------------------------------------------------
140
-  /**
141
-   * Drops a trigger.
142
-   *
143
-   * @param string $triggerSchema The name of the trigger schema.
144
-   * @param string $triggerName   The mame of trigger.
145
-   */
146
-  public static function dropTrigger($triggerSchema, $triggerName)
147
-  {
137
+    }
138
+
139
+    //--------------------------------------------------------------------------------------------------------------------
140
+    /**
141
+     * Drops a trigger.
142
+     *
143
+     * @param string $triggerSchema The name of the trigger schema.
144
+     * @param string $triggerName   The mame of trigger.
145
+     */
146
+    public static function dropTrigger($triggerSchema, $triggerName)
147
+    {
148 148
     $sql = sprintf('drop trigger `%s`.`%s`', $triggerSchema, $triggerName);
149 149
 
150 150
     self::executeNone($sql);
151
-  }
152
-
153
-  //--------------------------------------------------------------------------------------------------------------------
154
-  /**
155
-   * @param string $query The SQL statement.
156
-   *
157
-   * @return int The number of affected rows (if any).
158
-   */
159
-  public static function executeNone($query)
160
-  {
151
+    }
152
+
153
+    //--------------------------------------------------------------------------------------------------------------------
154
+    /**
155
+     * @param string $query The SQL statement.
156
+     *
157
+     * @return int The number of affected rows (if any).
158
+     */
159
+    public static function executeNone($query)
160
+    {
161 161
     self::logQuery($query);
162 162
 
163 163
     return self::$dl->executeNone($query);
164
-  }
165
-
166
-  //--------------------------------------------------------------------------------------------------------------------
167
-  /**
168
-   * Executes a query that returns 0 or 1 row.
169
-   * Throws an exception if the query selects 2 or more rows.
170
-   *
171
-   * @param string $query The SQL statement.
172
-   *
173
-   * @return array|null The selected row.
174
-   */
175
-  public static function executeRow0($query)
176
-  {
164
+    }
165
+
166
+    //--------------------------------------------------------------------------------------------------------------------
167
+    /**
168
+     * Executes a query that returns 0 or 1 row.
169
+     * Throws an exception if the query selects 2 or more rows.
170
+     *
171
+     * @param string $query The SQL statement.
172
+     *
173
+     * @return array|null The selected row.
174
+     */
175
+    public static function executeRow0($query)
176
+    {
177 177
     self::logQuery($query);
178 178
 
179 179
     return self::$dl->executeRow0($query);
180
-  }
181
-
182
-  //--------------------------------------------------------------------------------------------------------------------
183
-  /**
184
-   * Executes a query that returns 1 and only 1 row.
185
-   * Throws an exception if the query selects none, 2 or more rows.
186
-   *
187
-   * @param string $query The SQL statement.
188
-   *
189
-   * @return array The selected row.
190
-   */
191
-  public static function executeRow1($query)
192
-  {
180
+    }
181
+
182
+    //--------------------------------------------------------------------------------------------------------------------
183
+    /**
184
+     * Executes a query that returns 1 and only 1 row.
185
+     * Throws an exception if the query selects none, 2 or more rows.
186
+     *
187
+     * @param string $query The SQL statement.
188
+     *
189
+     * @return array The selected row.
190
+     */
191
+    public static function executeRow1($query)
192
+    {
193 193
     self::logQuery($query);
194 194
 
195 195
     return self::$dl->executeRow1($query);
196
-  }
197
-
198
-  //--------------------------------------------------------------------------------------------------------------------
199
-  /**
200
-   * Executes a query that returns 0 or more rows.
201
-   *
202
-   * @param string $query The SQL statement.
203
-   *
204
-   * @return \array[]
205
-   */
206
-  public static function executeRows($query)
207
-  {
196
+    }
197
+
198
+    //--------------------------------------------------------------------------------------------------------------------
199
+    /**
200
+     * Executes a query that returns 0 or more rows.
201
+     *
202
+     * @param string $query The SQL statement.
203
+     *
204
+     * @return \array[]
205
+     */
206
+    public static function executeRows($query)
207
+    {
208 208
     self::logQuery($query);
209 209
 
210 210
     return self::$dl->executeRows($query);
211
-  }
212
-
213
-  //--------------------------------------------------------------------------------------------------------------------
214
-  /**
215
-   * Executes a query that returns 0 or 1 row.
216
-   * Throws an exception if the query selects 2 or more rows.
217
-   *
218
-   * @param string $query The SQL statement.
219
-   *
220
-   * @return int|string|null The selected row.
221
-   */
222
-  public static function executeSingleton0($query)
223
-  {
211
+    }
212
+
213
+    //--------------------------------------------------------------------------------------------------------------------
214
+    /**
215
+     * Executes a query that returns 0 or 1 row.
216
+     * Throws an exception if the query selects 2 or more rows.
217
+     *
218
+     * @param string $query The SQL statement.
219
+     *
220
+     * @return int|string|null The selected row.
221
+     */
222
+    public static function executeSingleton0($query)
223
+    {
224 224
     self::logQuery($query);
225 225
 
226 226
     return self::$dl->executeSingleton0($query);
227
-  }
228
-
229
-  //--------------------------------------------------------------------------------------------------------------------
230
-  /**
231
-   * Executes a query that returns 1 and only 1 row with 1 column.
232
-   * Throws an exception if the query selects none, 2 or more rows.
233
-   *
234
-   * @param string $query The SQL statement.
235
-   *
236
-   * @return int|string The selected row.
237
-   */
238
-  public static function executeSingleton1($query)
239
-  {
227
+    }
228
+
229
+    //--------------------------------------------------------------------------------------------------------------------
230
+    /**
231
+     * Executes a query that returns 1 and only 1 row with 1 column.
232
+     * Throws an exception if the query selects none, 2 or more rows.
233
+     *
234
+     * @param string $query The SQL statement.
235
+     *
236
+     * @return int|string The selected row.
237
+     */
238
+    public static function executeSingleton1($query)
239
+    {
240 240
     self::logQuery($query);
241 241
 
242 242
     return self::$dl->executeSingleton1($query);
243
-  }
244
-
245
-  //--------------------------------------------------------------------------------------------------------------------
246
-  /**
247
-   * Selects metadata of all columns of table.
248
-   *
249
-   * @param string $schemaName The name of the table schema.
250
-   * @param string $tableName  The name of the table.
251
-   *
252
-   * @return \array[]
253
-   */
254
-  public static function getTableColumns($schemaName, $tableName)
255
-  {
243
+    }
244
+
245
+    //--------------------------------------------------------------------------------------------------------------------
246
+    /**
247
+     * Selects metadata of all columns of table.
248
+     *
249
+     * @param string $schemaName The name of the table schema.
250
+     * @param string $tableName  The name of the table.
251
+     *
252
+     * @return \array[]
253
+     */
254
+    public static function getTableColumns($schemaName, $tableName)
255
+    {
256 256
     $sql = sprintf('
257 257
 select COLUMN_NAME        as column_name
258 258
 ,      COLUMN_TYPE        as column_type
@@ -263,23 +263,23 @@  discard block
 block discarded – undo
263 263
 where  TABLE_SCHEMA = %s
264 264
 and    TABLE_NAME   = %s
265 265
 order by ORDINAL_POSITION',
266
-                   self::$dl->quoteString($schemaName),
267
-                   self::$dl->quoteString($tableName));
266
+                    self::$dl->quoteString($schemaName),
267
+                    self::$dl->quoteString($tableName));
268 268
 
269 269
     return self::$dl->executeRows($sql);
270
-  }
271
-
272
-  //--------------------------------------------------------------------------------------------------------------------
273
-  /**
274
-   * Selects table engine, character_set_name and table_collation.
275
-   *
276
-   * @param string $schemaName The name of the table schema.
277
-   * @param string $tableName  The name of the table.
278
-   *
279
-   * @return array
280
-   */
281
-  public static function getTableOptions($schemaName, $tableName)
282
-  {
270
+    }
271
+
272
+    //--------------------------------------------------------------------------------------------------------------------
273
+    /**
274
+     * Selects table engine, character_set_name and table_collation.
275
+     *
276
+     * @param string $schemaName The name of the table schema.
277
+     * @param string $tableName  The name of the table.
278
+     *
279
+     * @return array
280
+     */
281
+    public static function getTableOptions($schemaName, $tableName)
282
+    {
283 283
     $sql = sprintf('
284 284
 SELECT t1.TABLE_COLLATION    as table_collation
285 285
 ,      t1.ENGINE             as engine
@@ -288,100 +288,100 @@  discard block
 block discarded – undo
288 288
 inner join information_schema.COLLATION_CHARACTER_SET_APPLICABILITY t2  on  t2.COLLATION_NAME = t1.TABLE_COLLATION
289 289
 WHERE t1.TABLE_SCHEMA = %s
290 290
 AND   t1.TABLE_NAME   = %s',
291
-                   self::$dl->quoteString($schemaName),
292
-                   self::$dl->quoteString($tableName));
291
+                    self::$dl->quoteString($schemaName),
292
+                    self::$dl->quoteString($tableName));
293 293
 
294 294
     return self::$dl->executeRow1($sql);
295
-  }
296
-
297
-  //--------------------------------------------------------------------------------------------------------------------
298
-  /**
299
-   * Create temp table for getting column type information for audit columns.
300
-   *
301
-   * @param string  $schemaName   The name of the table schema.
302
-   * @param string  $tableName    The table name.
303
-   * @param array[] $auditColumns Audit columns from config file.
304
-   */
305
-  public static function createTemporaryTable($schemaName, $tableName, $auditColumns)
306
-  {
295
+    }
296
+
297
+    //--------------------------------------------------------------------------------------------------------------------
298
+    /**
299
+     * Create temp table for getting column type information for audit columns.
300
+     *
301
+     * @param string  $schemaName   The name of the table schema.
302
+     * @param string  $tableName    The table name.
303
+     * @param array[] $auditColumns Audit columns from config file.
304
+     */
305
+    public static function createTemporaryTable($schemaName, $tableName, $auditColumns)
306
+    {
307 307
     $sql = new CompoundSyntaxStore();
308 308
     $sql->append(sprintf('create temporary table `%s`.`%s` (', $schemaName, $tableName));
309 309
     foreach ($auditColumns as $column)
310 310
     {
311
-      $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
312
-      if (end($auditColumns)!==$column)
313
-      {
311
+        $sql->append(sprintf('%s %s', $column['column_name'], $column['column_type']));
312
+        if (end($auditColumns)!==$column)
313
+        {
314 314
         $sql->appendToLastLine(',');
315
-      }
315
+        }
316 316
     }
317 317
     $sql->append(')');
318 318
 
319 319
     self::$dl->executeNone($sql->getCode());
320
-  }
321
-
322
-  //--------------------------------------------------------------------------------------------------------------------
323
-  /**
324
-   * Drop table.
325
-   *
326
-   * @param string $schemaName The name of the table schema.
327
-   * @param string $tableName  The name of the table.
328
-   *
329
-   * @return \array[]
330
-   */
331
-  public static function showColumns($schemaName, $tableName)
332
-  {
320
+    }
321
+
322
+    //--------------------------------------------------------------------------------------------------------------------
323
+    /**
324
+     * Drop table.
325
+     *
326
+     * @param string $schemaName The name of the table schema.
327
+     * @param string $tableName  The name of the table.
328
+     *
329
+     * @return \array[]
330
+     */
331
+    public static function showColumns($schemaName, $tableName)
332
+    {
333 333
     $sql = sprintf('SHOW COLUMNS FROM `%s`.`%s`', $schemaName, $tableName);
334 334
 
335 335
     return self::$dl->executeRows($sql);
336
-  }
337
-
338
-  //--------------------------------------------------------------------------------------------------------------------
339
-  /**
340
-   * Drop table.
341
-   *
342
-   * @param string $schemaName The name of the table schema.
343
-   * @param string $tableName  The name of the table.
344
-   */
345
-  public static function dropTemporaryTable($schemaName, $tableName)
346
-  {
336
+    }
337
+
338
+    //--------------------------------------------------------------------------------------------------------------------
339
+    /**
340
+     * Drop table.
341
+     *
342
+     * @param string $schemaName The name of the table schema.
343
+     * @param string $tableName  The name of the table.
344
+     */
345
+    public static function dropTemporaryTable($schemaName, $tableName)
346
+    {
347 347
     $sql = sprintf('drop temporary table `%s`.`%s`', $schemaName, $tableName);
348 348
 
349 349
     self::$dl->executeNone($sql);
350
-  }
351
-
352
-  //--------------------------------------------------------------------------------------------------------------------
353
-  /**
354
-   * Selects all triggers on a table.
355
-   *
356
-   * @param string $schemaName The name of the table schema.
357
-   * @param string $tableName  The name of the table.
358
-   *
359
-   * @return \array[]
360
-   */
361
-  public static function getTableTriggers($schemaName, $tableName)
362
-  {
350
+    }
351
+
352
+    //--------------------------------------------------------------------------------------------------------------------
353
+    /**
354
+     * Selects all triggers on a table.
355
+     *
356
+     * @param string $schemaName The name of the table schema.
357
+     * @param string $tableName  The name of the table.
358
+     *
359
+     * @return \array[]
360
+     */
361
+    public static function getTableTriggers($schemaName, $tableName)
362
+    {
363 363
     $sql = sprintf('
364 364
 select Trigger_Name as trigger_name
365 365
 from   information_schema.TRIGGERS
366 366
 where  TRIGGER_SCHEMA     = %s
367 367
 and    EVENT_OBJECT_TABLE = %s
368 368
 order by Trigger_Name',
369
-                   self::$dl->quoteString($schemaName),
370
-                   self::$dl->quoteString($tableName));
369
+                    self::$dl->quoteString($schemaName),
370
+                    self::$dl->quoteString($tableName));
371 371
 
372 372
     return self::$dl->executeRows($sql);
373
-  }
374
-
375
-  //--------------------------------------------------------------------------------------------------------------------
376
-  /**
377
-   * Selects all table names in a schema.
378
-   *
379
-   * @param string $schemaName The name of the schema.
380
-   *
381
-   * @return \array[]
382
-   */
383
-  public static function getTablesNames($schemaName)
384
-  {
373
+    }
374
+
375
+    //--------------------------------------------------------------------------------------------------------------------
376
+    /**
377
+     * Selects all table names in a schema.
378
+     *
379
+     * @param string $schemaName The name of the schema.
380
+     *
381
+     * @return \array[]
382
+     */
383
+    public static function getTablesNames($schemaName)
384
+    {
385 385
     $sql = sprintf("
386 386
 select TABLE_NAME as table_name
387 387
 from   information_schema.TABLES
@@ -390,67 +390,67 @@  discard block
 block discarded – undo
390 390
 order by TABLE_NAME", self::$dl->quoteString($schemaName));
391 391
 
392 392
     return self::$dl->executeRows($sql);
393
-  }
394
-
395
-  //--------------------------------------------------------------------------------------------------------------------
396
-  /**
397
-   * Acquires a write lock on a table.
398
-   *
399
-   * @param string $tableName The table name.
400
-   */
401
-  public static function lockTable($tableName)
402
-  {
393
+    }
394
+
395
+    //--------------------------------------------------------------------------------------------------------------------
396
+    /**
397
+     * Acquires a write lock on a table.
398
+     *
399
+     * @param string $tableName The table name.
400
+     */
401
+    public static function lockTable($tableName)
402
+    {
403 403
     $sql = sprintf('lock tables `%s` write', $tableName);
404 404
 
405 405
     self::$dl->executeNone($sql);
406
-  }
407
-
408
-  //--------------------------------------------------------------------------------------------------------------------
409
-  /**
410
-   * Sets the Output decorator.
411
-   *
412
-   * @param StratumStyle $io The Output decorator.
413
-   */
414
-  public static function setIo($io)
415
-  {
406
+    }
407
+
408
+    //--------------------------------------------------------------------------------------------------------------------
409
+    /**
410
+     * Sets the Output decorator.
411
+     *
412
+     * @param StratumStyle $io The Output decorator.
413
+     */
414
+    public static function setIo($io)
415
+    {
416 416
     self::$io = $io;
417
-  }
418
-
419
-  //--------------------------------------------------------------------------------------------------------------------
420
-  /**
421
-   * Releases all table locks.
422
-   */
423
-  public static function unlockTables()
424
-  {
417
+    }
418
+
419
+    //--------------------------------------------------------------------------------------------------------------------
420
+    /**
421
+     * Releases all table locks.
422
+     */
423
+    public static function unlockTables()
424
+    {
425 425
     $sql = 'unlock tables';
426 426
 
427 427
     self::$dl->executeNone($sql);
428
-  }
429
-
430
-  //--------------------------------------------------------------------------------------------------------------------
431
-  /**
432
-   * Logs the query on the console.
433
-   *
434
-   * @param string $query The query.
435
-   */
436
-  private static function logQuery($query)
437
-  {
428
+    }
429
+
430
+    //--------------------------------------------------------------------------------------------------------------------
431
+    /**
432
+     * Logs the query on the console.
433
+     *
434
+     * @param string $query The query.
435
+     */
436
+    private static function logQuery($query)
437
+    {
438 438
     $query = trim($query);
439 439
 
440 440
     if (strpos($query, "\n")!==false)
441 441
     {
442
-      // Query is a multi line query.
443
-      self::$io->logVeryVerbose('Executing query:');
444
-      self::$io->logVeryVerbose('<sql>%s</sql>', $query);
442
+        // Query is a multi line query.
443
+        self::$io->logVeryVerbose('Executing query:');
444
+        self::$io->logVeryVerbose('<sql>%s</sql>', $query);
445 445
     }
446 446
     else
447 447
     {
448
-      // Query is a single line query.
449
-      self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
448
+        // Query is a single line query.
449
+        self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
450
+    }
450 451
     }
451
-  }
452 452
 
453
-  //--------------------------------------------------------------------------------------------------------------------
453
+    //--------------------------------------------------------------------------------------------------------------------
454 454
 }
455 455
 
456 456
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/Sql/CreateAuditTrigger.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -155,17 +155,17 @@
 block discarded – undo
155 155
     $this->code->append('for each row');
156 156
     $this->code->append('begin');
157 157
 
158
-    if ($this->skipVariable!==null) $this->code->append(sprintf('if (%s is null) then', $this->skipVariable));
158
+    if ($this->skipVariable !== null) $this->code->append(sprintf('if (%s is null) then', $this->skipVariable));
159 159
 
160 160
     $this->code->append($this->additionalSql);
161 161
 
162 162
     $this->createInsertStatement($rowState[0]);
163
-    if (sizeof($rowState)==2)
163
+    if (sizeof($rowState) == 2)
164 164
     {
165 165
       $this->createInsertStatement($rowState[1]);
166 166
     }
167 167
 
168
-    if ($this->skipVariable!==null) $this->code->append('end if;');
168
+    if ($this->skipVariable !== null) $this->code->append('end if;');
169 169
     $this->code->append('end');
170 170
 
171 171
     return $this->code->getCode();
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -155,7 +155,9 @@  discard block
 block discarded – undo
155 155
     $this->code->append('for each row');
156 156
     $this->code->append('begin');
157 157
 
158
-    if ($this->skipVariable!==null) $this->code->append(sprintf('if (%s is null) then', $this->skipVariable));
158
+    if ($this->skipVariable!==null) {
159
+        $this->code->append(sprintf('if (%s is null) then', $this->skipVariable));
160
+    }
159 161
 
160 162
     $this->code->append($this->additionalSql);
161 163
 
@@ -165,7 +167,9 @@  discard block
 block discarded – undo
165 167
       $this->createInsertStatement($rowState[1]);
166 168
     }
167 169
 
168
-    if ($this->skipVariable!==null) $this->code->append('end if;');
170
+    if ($this->skipVariable!==null) {
171
+        $this->code->append('end if;');
172
+    }
169 173
     $this->code->append('end');
170 174
 
171 175
     return $this->code->getCode();
@@ -194,14 +198,18 @@  discard block
 block discarded – undo
194 198
     // First the audit columns.
195 199
     foreach ($this->auditColumns->getColumns() as $column)
196 200
     {
197
-      if ($columnNames) $columnNames .= ',';
201
+      if ($columnNames) {
202
+          $columnNames .= ',';
203
+      }
198 204
       $columnNames .= sprintf('`%s`', $column['column_name']);
199 205
     }
200 206
 
201 207
     // Second the audit columns.
202 208
     foreach ($this->tableColumns->getColumns() as $column)
203 209
     {
204
-      if ($columnNames) $columnNames .= ',';
210
+      if ($columnNames) {
211
+          $columnNames .= ',';
212
+      }
205 213
       $columnNames .= sprintf('`%s`', $column['column_name']);
206 214
     }
207 215
 
@@ -221,7 +229,9 @@  discard block
 block discarded – undo
221 229
     // First the values for the audit columns.
222 230
     foreach ($this->auditColumns->getColumns() as $column)
223 231
     {
224
-      if ($values) $values .= ',';
232
+      if ($values) {
233
+          $values .= ',';
234
+      }
225 235
       switch (true)
226 236
       {
227 237
         case (isset($column['audit_value_type'])):
@@ -252,7 +262,9 @@  discard block
 block discarded – undo
252 262
     // Second the values for the audit columns.
253 263
     foreach ($this->tableColumns->getColumns() as $column)
254 264
     {
255
-      if ($values) $values .= ',';
265
+      if ($values) {
266
+          $values .= ',';
267
+      }
256 268
       $values .= sprintf('%s.`%s`', $rowState, $column['column_name']);
257 269
     }
258 270
 
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -14,101 +14,101 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class CreateAuditTrigger
16 16
 {
17
-  //--------------------------------------------------------------------------------------------------------------------
18
-  /**
19
-   * Additional SQL statements.
20
-   *
21
-   * @var string[]
22
-   */
23
-  private $additionalSql;
24
-
25
-  /**
26
-   * AuditApplication columns from metadata.
27
-   *
28
-   * @var \SetBased\Audit\MySql\Table\Columns
29
-   */
30
-  private $auditColumns;
31
-
32
-  /**
33
-   * The name of the audit schema.
34
-   *
35
-   * @var string
36
-   */
37
-  private $auditSchemaName;
38
-
39
-  /**
40
-   * The generated code.
41
-   *
42
-   * @var CompoundSyntaxStore
43
-   */
44
-  private $code;
45
-
46
-  /**
47
-   * The name of the data schema.
48
-   *
49
-   * @var string
50
-   */
51
-  private $dataSchemaName;
52
-
53
-  /**
54
-   * The skip variable.
55
-   *
56
-   * @var string
57
-   */
58
-  private $skipVariable;
59
-
60
-  /**
61
-   * Table columns from metadata.
62
-   *
63
-   * @var \SetBased\Audit\MySql\Table\Columns
64
-   */
65
-  private $tableColumns;
66
-
67
-  /**
68
-   * The name of the data table.
69
-   *
70
-   * @var string
71
-   */
72
-  private $tableName;
73
-
74
-  /**
75
-   * The trigger action (.e. INSERT, UPDATE, or DELETE).
76
-   *
77
-   * @var string
78
-   */
79
-  private $triggerAction;
80
-
81
-  /**
82
-   * The name of the trigger.
83
-   *
84
-   * @var string
85
-   */
86
-  private $triggerName;
87
-
88
-  //--------------------------------------------------------------------------------------------------------------------
89
-  /**
90
-   * Creates a trigger on a table.
91
-   *
92
-   * @param string                              $dataSchemaName  The name of the data schema.
93
-   * @param string                              $auditSchemaName The name of the audit schema.
94
-   * @param string                              $tableName       The name of the table.
95
-   * @param string                              $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
-   * @param string                              $triggerName     The name of the trigger.
97
-   * @param \SetBased\Audit\MySql\Table\Columns $tableColumns    The data table columns.
98
-   * @param \SetBased\Audit\MySql\Table\Columns $auditColumns    The audit table columns.
99
-   * @param string                              $skipVariable    The skip variable.
100
-   * @param string[]                            $additionalSql   Additional SQL statements.
101
-   */
102
-  public function __construct($dataSchemaName,
103
-                              $auditSchemaName,
104
-                              $tableName,
105
-                              $triggerName,
106
-                              $triggerAction,
107
-                              $auditColumns,
108
-                              $tableColumns,
109
-                              $skipVariable,
110
-                              $additionalSql)
111
-  {
17
+    //--------------------------------------------------------------------------------------------------------------------
18
+    /**
19
+     * Additional SQL statements.
20
+     *
21
+     * @var string[]
22
+     */
23
+    private $additionalSql;
24
+
25
+    /**
26
+     * AuditApplication columns from metadata.
27
+     *
28
+     * @var \SetBased\Audit\MySql\Table\Columns
29
+     */
30
+    private $auditColumns;
31
+
32
+    /**
33
+     * The name of the audit schema.
34
+     *
35
+     * @var string
36
+     */
37
+    private $auditSchemaName;
38
+
39
+    /**
40
+     * The generated code.
41
+     *
42
+     * @var CompoundSyntaxStore
43
+     */
44
+    private $code;
45
+
46
+    /**
47
+     * The name of the data schema.
48
+     *
49
+     * @var string
50
+     */
51
+    private $dataSchemaName;
52
+
53
+    /**
54
+     * The skip variable.
55
+     *
56
+     * @var string
57
+     */
58
+    private $skipVariable;
59
+
60
+    /**
61
+     * Table columns from metadata.
62
+     *
63
+     * @var \SetBased\Audit\MySql\Table\Columns
64
+     */
65
+    private $tableColumns;
66
+
67
+    /**
68
+     * The name of the data table.
69
+     *
70
+     * @var string
71
+     */
72
+    private $tableName;
73
+
74
+    /**
75
+     * The trigger action (.e. INSERT, UPDATE, or DELETE).
76
+     *
77
+     * @var string
78
+     */
79
+    private $triggerAction;
80
+
81
+    /**
82
+     * The name of the trigger.
83
+     *
84
+     * @var string
85
+     */
86
+    private $triggerName;
87
+
88
+    //--------------------------------------------------------------------------------------------------------------------
89
+    /**
90
+     * Creates a trigger on a table.
91
+     *
92
+     * @param string                              $dataSchemaName  The name of the data schema.
93
+     * @param string                              $auditSchemaName The name of the audit schema.
94
+     * @param string                              $tableName       The name of the table.
95
+     * @param string                              $triggerAction   The trigger action (i.e. INSERT, UPDATE, or DELETE).
96
+     * @param string                              $triggerName     The name of the trigger.
97
+     * @param \SetBased\Audit\MySql\Table\Columns $tableColumns    The data table columns.
98
+     * @param \SetBased\Audit\MySql\Table\Columns $auditColumns    The audit table columns.
99
+     * @param string                              $skipVariable    The skip variable.
100
+     * @param string[]                            $additionalSql   Additional SQL statements.
101
+     */
102
+    public function __construct($dataSchemaName,
103
+                                $auditSchemaName,
104
+                                $tableName,
105
+                                $triggerName,
106
+                                $triggerAction,
107
+                                $auditColumns,
108
+                                $tableColumns,
109
+                                $skipVariable,
110
+                                $additionalSql)
111
+    {
112 112
     $this->dataSchemaName  = $dataSchemaName;
113 113
     $this->auditSchemaName = $auditSchemaName;
114 114
     $this->tableName       = $tableName;
@@ -118,35 +118,35 @@  discard block
 block discarded – undo
118 118
     $this->tableColumns    = $tableColumns;
119 119
     $this->auditColumns    = $auditColumns;
120 120
     $this->additionalSql   = $additionalSql;
121
-  }
122
-
123
-  //--------------------------------------------------------------------------------------------------------------------
124
-  /**
125
-   * Returns the SQL code for creating an audit trigger.
126
-   *
127
-   * @throws FallenException
128
-   */
129
-  public function buildStatement()
130
-  {
121
+    }
122
+
123
+    //--------------------------------------------------------------------------------------------------------------------
124
+    /**
125
+     * Returns the SQL code for creating an audit trigger.
126
+     *
127
+     * @throws FallenException
128
+     */
129
+    public function buildStatement()
130
+    {
131 131
     $this->code = new CompoundSyntaxStore();
132 132
 
133 133
     $rowState = [];
134 134
     switch ($this->triggerAction)
135 135
     {
136
-      case 'INSERT':
136
+        case 'INSERT':
137 137
         $rowState[] = 'NEW';
138 138
         break;
139 139
 
140
-      case 'DELETE':
140
+        case 'DELETE':
141 141
         $rowState[] = 'OLD';
142 142
         break;
143 143
 
144
-      case 'UPDATE':
144
+        case 'UPDATE':
145 145
         $rowState[] = 'OLD';
146 146
         $rowState[] = 'NEW';
147 147
         break;
148 148
 
149
-      default:
149
+        default:
150 150
         throw new FallenException('action', $this->triggerAction);
151 151
     }
152 152
 
@@ -162,109 +162,109 @@  discard block
 block discarded – undo
162 162
     $this->createInsertStatement($rowState[0]);
163 163
     if (sizeof($rowState)==2)
164 164
     {
165
-      $this->createInsertStatement($rowState[1]);
165
+        $this->createInsertStatement($rowState[1]);
166 166
     }
167 167
 
168 168
     if ($this->skipVariable!==null) $this->code->append('end if;');
169 169
     $this->code->append('end');
170 170
 
171 171
     return $this->code->getCode();
172
-  }
173
-
174
-  //--------------------------------------------------------------------------------------------------------------------
175
-  /**
176
-   * Adds an insert SQL statement to SQL code for a trigger.
177
-   *
178
-   * @param string $rowState The row state (i.e. OLD or NEW).
179
-   */
180
-  private function createInsertStatement($rowState)
181
-  {
172
+    }
173
+
174
+    //--------------------------------------------------------------------------------------------------------------------
175
+    /**
176
+     * Adds an insert SQL statement to SQL code for a trigger.
177
+     *
178
+     * @param string $rowState The row state (i.e. OLD or NEW).
179
+     */
180
+    private function createInsertStatement($rowState)
181
+    {
182 182
     $this->createInsertStatementInto();
183 183
     $this->createInsertStatementValues($rowState);
184
-  }
185
-
186
-  //--------------------------------------------------------------------------------------------------------------------
187
-  /**
188
-   * Adds the "insert into" part of an insert SQL statement to SQL code for a trigger.
189
-   */
190
-  private function createInsertStatementInto()
191
-  {
184
+    }
185
+
186
+    //--------------------------------------------------------------------------------------------------------------------
187
+    /**
188
+     * Adds the "insert into" part of an insert SQL statement to SQL code for a trigger.
189
+     */
190
+    private function createInsertStatementInto()
191
+    {
192 192
     $columnNames = '';
193 193
 
194 194
     // First the audit columns.
195 195
     /** @var ColumnType $column */
196 196
     foreach ($this->auditColumns->getColumns() as $column)
197 197
     {
198
-      if ($columnNames) $columnNames .= ',';
199
-      $columnNames .= sprintf('`%s`', $column->getProperty('column_name'));
198
+        if ($columnNames) $columnNames .= ',';
199
+        $columnNames .= sprintf('`%s`', $column->getProperty('column_name'));
200 200
     }
201 201
 
202 202
     // Second the audit columns.
203 203
     /** @var ColumnType $column */
204 204
     foreach ($this->tableColumns->getColumns() as $column)
205 205
     {
206
-      if ($columnNames) $columnNames .= ',';
207
-      $columnNames .= sprintf('`%s`', $column->getProperty('column_name'));
206
+        if ($columnNames) $columnNames .= ',';
207
+        $columnNames .= sprintf('`%s`', $column->getProperty('column_name'));
208 208
     }
209 209
 
210 210
     $this->code->append(sprintf('insert into `%s`.`%s`(%s)', $this->auditSchemaName, $this->tableName, $columnNames));
211
-  }
212
-
213
-  //--------------------------------------------------------------------------------------------------------------------
214
-  /**
215
-   * Adds the "values" part of an insert SQL statement to SQL code for a trigger.
216
-   *
217
-   * @param string $rowState The row state (i.e. OLD or NEW).
218
-   */
219
-  private function createInsertStatementValues($rowState)
220
-  {
211
+    }
212
+
213
+    //--------------------------------------------------------------------------------------------------------------------
214
+    /**
215
+     * Adds the "values" part of an insert SQL statement to SQL code for a trigger.
216
+     *
217
+     * @param string $rowState The row state (i.e. OLD or NEW).
218
+     */
219
+    private function createInsertStatementValues($rowState)
220
+    {
221 221
     $values = '';
222 222
 
223 223
     // First the values for the audit columns.
224 224
     /** @var ColumnType $column */
225 225
     foreach ($this->auditColumns->getColumns() as $column)
226 226
     {
227
-      $column = $column->getType();
228
-      if ($values) $values .= ',';
229
-      switch (true)
230
-      {
227
+        $column = $column->getType();
228
+        if ($values) $values .= ',';
229
+        switch (true)
230
+        {
231 231
         case (isset($column['value_type'])):
232 232
           switch ($column['value_type'])
233
-          {
233
+            {
234 234
             case 'ACTION':
235 235
               $values .= StaticDataLayer::quoteString($this->triggerAction);
236
-              break;
236
+                break;
237 237
 
238 238
             case 'STATE':
239 239
               $values .= StaticDataLayer::quoteString($rowState);
240
-              break;
240
+                break;
241 241
 
242 242
             default:
243 243
               throw new FallenException('audit_value_type', ($column['value_type']));
244
-          }
245
-          break;
244
+            }
245
+            break;
246 246
 
247 247
         case (isset($column['expression'])):
248 248
           $values .= $column['expression'];
249
-          break;
249
+            break;
250 250
 
251 251
         default:
252 252
           throw new RuntimeException('None of audit_value_type and audit_expression are set.');
253
-      }
253
+        }
254 254
     }
255 255
 
256 256
     // Second the values for the audit columns.
257 257
     /** @var ColumnType $column */
258 258
     foreach ($this->tableColumns->getColumns() as $column)
259 259
     {
260
-      if ($values) $values .= ',';
261
-      $values .= sprintf('%s.`%s`', $rowState, $column->getProperty('column_name'));
260
+        if ($values) $values .= ',';
261
+        $values .= sprintf('%s.`%s`', $rowState, $column->getProperty('column_name'));
262 262
     }
263 263
 
264 264
     $this->code->append(sprintf('values(%s);', $values));
265
-  }
265
+    }
266 266
 
267
-  //--------------------------------------------------------------------------------------------------------------------
267
+    //--------------------------------------------------------------------------------------------------------------------
268 268
 }
269 269
 
270 270
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/Sql/CreateAuditTable.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
     foreach ($columns as $column)
89 89
     {
90 90
       $code->append(sprintf($format, '`'.$column['column_name'].'`', $column['column_type']), false);
91
-      if (end($columns)!==$column)
91
+      if (end($columns) !== $column)
92 92
       {
93 93
         $code->appendToLastLine(',');
94 94
       }
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,64 +13,64 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class CreateAuditTable
15 15
 {
16
-  //--------------------------------------------------------------------------------------------------------------------
17
-  /**
18
-   * The name of the audit schema.
19
-   *
20
-   * @var string
21
-   */
22
-  private $auditSchemaName;
16
+    //--------------------------------------------------------------------------------------------------------------------
17
+    /**
18
+     * The name of the audit schema.
19
+     *
20
+     * @var string
21
+     */
22
+    private $auditSchemaName;
23 23
 
24
-  /**
25
-   * The name of the table.
26
-   *
27
-   * @var Columns
28
-   */
29
-  private $columns;
24
+    /**
25
+     * The name of the table.
26
+     *
27
+     * @var Columns
28
+     */
29
+    private $columns;
30 30
 
31
-  /**
32
-   * The name of the data schema.
33
-   *
34
-   * @var string
35
-   */
36
-  private $dataSchemaName;
31
+    /**
32
+     * The name of the data schema.
33
+     *
34
+     * @var string
35
+     */
36
+    private $dataSchemaName;
37 37
 
38
-  /**
39
-   * The name of the table.
40
-   *
41
-   * @var string
42
-   */
43
-  private $tableName;
38
+    /**
39
+     * The name of the table.
40
+     *
41
+     * @var string
42
+     */
43
+    private $tableName;
44 44
 
45
-  //--------------------------------------------------------------------------------------------------------------------
46
-  /**
47
-   * Object constructor.
48
-   *
49
-   * @param string  $dataSchemaName  The name of the data schema.
50
-   * @param string  $auditSchemaName The name of the audit schema.
51
-   * @param string  $tableName       The name of the table.
52
-   * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
53
-   *                                 of the data table).
54
-   */
55
-  public function __construct($dataSchemaName,
56
-                              $auditSchemaName,
57
-                              $tableName,
58
-                              $columns)
59
-  {
45
+    //--------------------------------------------------------------------------------------------------------------------
46
+    /**
47
+     * Object constructor.
48
+     *
49
+     * @param string  $dataSchemaName  The name of the data schema.
50
+     * @param string  $auditSchemaName The name of the audit schema.
51
+     * @param string  $tableName       The name of the table.
52
+     * @param Columns $columns         The metadata of the columns of the audit table (i.e. the audit columns and columns
53
+     *                                 of the data table).
54
+     */
55
+    public function __construct($dataSchemaName,
56
+                                $auditSchemaName,
57
+                                $tableName,
58
+                                $columns)
59
+    {
60 60
     $this->dataSchemaName  = $dataSchemaName;
61 61
     $this->auditSchemaName = $auditSchemaName;
62 62
     $this->tableName       = $tableName;
63 63
     $this->columns         = $columns;
64
-  }
64
+    }
65 65
 
66
-  //--------------------------------------------------------------------------------------------------------------------
67
-  /**
68
-   * Returns a SQL statement for creating the audit table.
69
-   *
70
-   * @return string
71
-   */
72
-  public function buildStatement()
73
-  {
66
+    //--------------------------------------------------------------------------------------------------------------------
67
+    /**
68
+     * Returns a SQL statement for creating the audit table.
69
+     *
70
+     * @return string
71
+     */
72
+    public function buildStatement()
73
+    {
74 74
     $code = new CompoundSyntaxStore();
75 75
 
76 76
     $code->append(sprintf('create table `%s`.`%s`', $this->auditSchemaName, $this->tableName));
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     /** @var ColumnType $column */
82 82
     foreach ($columns as $column)
83 83
     {
84
-      $width = max($width, mb_strlen($column->getProperty('column_name')));
84
+        $width = max($width, mb_strlen($column->getProperty('column_name')));
85 85
     }
86 86
     $format = sprintf('  %%-%ds %%s', $width + 2);
87 87
 
@@ -89,24 +89,24 @@  discard block
 block discarded – undo
89 89
     $code->append('(');
90 90
     foreach ($columns as $column)
91 91
     {
92
-      $code->append(sprintf($format, '`'.$column->getProperty('column_name').'`', $column->getProperty('column_type')), false);
93
-      if (end($columns)!==$column)
94
-      {
92
+        $code->append(sprintf($format, '`'.$column->getProperty('column_name').'`', $column->getProperty('column_type')), false);
93
+        if (end($columns)!==$column)
94
+        {
95 95
         $code->appendToLastLine(',');
96
-      }
96
+        }
97 97
     }
98 98
 
99 99
     // Create SQL for table options.
100 100
     $tableOptions = DataLayer::getTableOptions($this->dataSchemaName, $this->tableName);
101 101
     $code->append(sprintf(') engine=%s character set=%s collate=%s',
102
-                          $tableOptions['engine'],
103
-                          $tableOptions['character_set_name'],
104
-                          $tableOptions['table_collation']));
102
+                            $tableOptions['engine'],
103
+                            $tableOptions['character_set_name'],
104
+                            $tableOptions['table_collation']));
105 105
 
106 106
     return $code->getCode();
107
-  }
107
+    }
108 108
 
109
-  //--------------------------------------------------------------------------------------------------------------------
109
+    //--------------------------------------------------------------------------------------------------------------------
110 110
 }
111 111
 
112 112
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/Command/MySqlCommand.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -11,23 +11,23 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class MySqlCommand extends BaseCommand
13 13
 {
14
-  //--------------------------------------------------------------------------------------------------------------------
15
-  /**
16
-   * Disconnects from MySQL instance.
17
-   */
18
-  public function disconnect()
19
-  {
14
+    //--------------------------------------------------------------------------------------------------------------------
15
+    /**
16
+     * Disconnects from MySQL instance.
17
+     */
18
+    public function disconnect()
19
+    {
20 20
     DataLayer::disconnect();
21
-  }
21
+    }
22 22
 
23
-  //--------------------------------------------------------------------------------------------------------------------
24
-  /**
25
-   * Connects to a MySQL instance.
26
-   *
27
-   * @param array $settings The settings from the configuration file.
28
-   */
29
-  protected function connect($settings)
30
-  {
23
+    //--------------------------------------------------------------------------------------------------------------------
24
+    /**
25
+     * Connects to a MySQL instance.
26
+     *
27
+     * @param array $settings The settings from the configuration file.
28
+     */
29
+    protected function connect($settings)
30
+    {
31 31
     $host     = $this->getSetting($settings, true, 'database', 'host');
32 32
     $user     = $this->getSetting($settings, true, 'database', 'user');
33 33
     $password = $this->getSetting($settings, true, 'database', 'password');
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 
36 36
     DataLayer::setIo($this->io);
37 37
     DataLayer::connect($host, $user, $password, $database);
38
-  }
38
+    }
39 39
 
40
-  //--------------------------------------------------------------------------------------------------------------------
40
+    //--------------------------------------------------------------------------------------------------------------------
41 41
 }
42 42
 
43 43
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/MySql/Command/AuditCommand.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -88,16 +88,14 @@
 block discarded – undo
88 88
         if (!isset($this->config['tables'][$table['table_name']]['audit']))
89 89
         {
90 90
           $this->io->writeln(sprintf('<info>AuditApplication flag is not set in table %s</info>', $table['table_name']));
91
-        }
92
-        else
91
+        } else
93 92
         {
94 93
           if ($this->config['tables'][$table['table_name']]['audit'])
95 94
           {
96 95
             $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
97 96
           }
98 97
         }
99
-      }
100
-      else
98
+      } else
101 99
       {
102 100
         $this->io->writeln(sprintf('<info>Found new table %s</info>', $table['table_name']));
103 101
         $this->config['tables'][$table['table_name']] = ['audit' => false,
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                                   $this->config['audit_columns'],
155 155
                                   $this->config['tables'][$table['table_name']]['alias'],
156 156
                                   $this->config['tables'][$table['table_name']]['skip']);
157
-        $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
157
+        $res = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
158 158
         if (!isset($res))
159 159
         {
160 160
           $currentTable->createMissingAuditTable();
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
       if (isset($key))
192 192
       {
193 193
         $this->config['audit_columns'][$key]['column_type'] = $column['Type'];
194
-        if ($column['Null']==='NO')
194
+        if ($column['Null'] === 'NO')
195 195
         {
196 196
           $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
197 197
         }
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -17,113 +17,113 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class AuditCommand extends MySqlCommand
19 19
 {
20
-  //--------------------------------------------------------------------------------------------------------------------
21
-  /**
22
-   * All tables in the in the audit schema.
23
-   *
24
-   * @var array
25
-   */
26
-  protected $auditSchemaTables;
27
-
28
-  /**
29
-   * Array of tables from data schema.
30
-   *
31
-   * @var array
32
-   */
33
-  protected $dataSchemaTables;
34
-
35
-  /**
36
-   * If true remove all column information from config file.
37
-   *
38
-   * @var boolean
39
-   */
40
-  private $pruneOption;
41
-
42
-  //--------------------------------------------------------------------------------------------------------------------
43
-  /**
44
-   * Compares the tables listed in the config file and the tables found in the audit schema
45
-   *
46
-   * @param string                              $tableName Name of table
47
-   * @param \SetBased\Audit\MySql\Table\Columns $columns   The table columns.
48
-   */
49
-  public function getColumns($tableName, $columns)
50
-  {
20
+    //--------------------------------------------------------------------------------------------------------------------
21
+    /**
22
+     * All tables in the in the audit schema.
23
+     *
24
+     * @var array
25
+     */
26
+    protected $auditSchemaTables;
27
+
28
+    /**
29
+     * Array of tables from data schema.
30
+     *
31
+     * @var array
32
+     */
33
+    protected $dataSchemaTables;
34
+
35
+    /**
36
+     * If true remove all column information from config file.
37
+     *
38
+     * @var boolean
39
+     */
40
+    private $pruneOption;
41
+
42
+    //--------------------------------------------------------------------------------------------------------------------
43
+    /**
44
+     * Compares the tables listed in the config file and the tables found in the audit schema
45
+     *
46
+     * @param string                              $tableName Name of table
47
+     * @param \SetBased\Audit\MySql\Table\Columns $columns   The table columns.
48
+     */
49
+    public function getColumns($tableName, $columns)
50
+    {
51 51
     $newColumns = [];
52 52
     /** @var ColumnType $column */
53 53
     foreach ($columns->getColumns() as $column)
54 54
     {
55
-      $newColumns[] = $column->getType();
55
+        $newColumns[] = $column->getType();
56 56
     }
57 57
     $this->config['table_columns'][$tableName] = $newColumns;
58 58
 
59 59
     if ($this->pruneOption)
60 60
     {
61
-      $this->config['table_columns'] = [];
61
+        $this->config['table_columns'] = [];
62
+    }
62 63
     }
63
-  }
64
-
65
-  //--------------------------------------------------------------------------------------------------------------------
66
-  /**
67
-   * Getting list of all tables from information_schema of database from config file.
68
-   */
69
-  public function listOfTables()
70
-  {
64
+
65
+    //--------------------------------------------------------------------------------------------------------------------
66
+    /**
67
+     * Getting list of all tables from information_schema of database from config file.
68
+     */
69
+    public function listOfTables()
70
+    {
71 71
     $this->dataSchemaTables = DataLayer::getTablesNames($this->config['database']['data_schema']);
72 72
 
73 73
     $this->auditSchemaTables = DataLayer::getTablesNames($this->config['database']['audit_schema']);
74
-  }
75
-
76
-  //--------------------------------------------------------------------------------------------------------------------
77
-  /**
78
-   * Found tables in config file
79
-   *
80
-   * Compares the tables listed in the config file and the tables found in the data schema
81
-   */
82
-  public function unknownTables()
83
-  {
74
+    }
75
+
76
+    //--------------------------------------------------------------------------------------------------------------------
77
+    /**
78
+     * Found tables in config file
79
+     *
80
+     * Compares the tables listed in the config file and the tables found in the data schema
81
+     */
82
+    public function unknownTables()
83
+    {
84 84
     foreach ($this->dataSchemaTables as $table)
85 85
     {
86
-      if (isset($this->config['tables'][$table['table_name']]))
87
-      {
86
+        if (isset($this->config['tables'][$table['table_name']]))
87
+        {
88 88
         if (!isset($this->config['tables'][$table['table_name']]['audit']))
89 89
         {
90
-          $this->io->writeln(sprintf('<info>AuditApplication flag is not set in table %s</info>', $table['table_name']));
90
+            $this->io->writeln(sprintf('<info>AuditApplication flag is not set in table %s</info>', $table['table_name']));
91 91
         }
92 92
         else
93 93
         {
94
-          if ($this->config['tables'][$table['table_name']]['audit'])
95
-          {
94
+            if ($this->config['tables'][$table['table_name']]['audit'])
95
+            {
96 96
             $this->config['tables'][$table['table_name']]['alias'] = Table::getRandomAlias();
97
-          }
97
+            }
98 98
         }
99
-      }
100
-      else
101
-      {
99
+        }
100
+        else
101
+        {
102 102
         $this->io->writeln(sprintf('<info>Found new table %s</info>', $table['table_name']));
103 103
         $this->config['tables'][$table['table_name']] = ['audit' => false,
104
-                                                         'alias' => null,
105
-                                                         'skip'  => null];
106
-      }
104
+                                                            'alias' => null,
105
+                                                            'skip'  => null];
106
+        }
107 107
     }
108
-  }
109
-
110
-  //--------------------------------------------------------------------------------------------------------------------
111
-  /**
112
-   * {@inheritdoc}
113
-   */
114
-  protected function configure()
115
-  {
108
+    }
109
+
110
+    //--------------------------------------------------------------------------------------------------------------------
111
+    /**
112
+     * {@inheritdoc}
113
+     */
114
+    protected function configure()
115
+    {
116 116
     $this->setName('audit')
117
-         ->setDescription('Create (missing) audit table and (re)creates audit triggers')
118
-         ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
119
-  }
120
-
121
-  //--------------------------------------------------------------------------------------------------------------------
122
-  /**
123
-   * {@inheritdoc}
124
-   */
125
-  protected function execute(InputInterface $input, OutputInterface $output)
126
-  {
117
+            ->setDescription('Create (missing) audit table and (re)creates audit triggers')
118
+            ->addArgument('config file', InputArgument::OPTIONAL, 'The audit configuration file', 'etc/audit.json');
119
+    }
120
+
121
+    //--------------------------------------------------------------------------------------------------------------------
122
+    /**
123
+     * {@inheritdoc}
124
+     */
125
+    protected function execute(InputInterface $input, OutputInterface $output)
126
+    {
127 127
     $this->io = new StratumStyle($input, $output);
128 128
 
129 129
     $this->configFileName = $input->getArgument('config file');
@@ -140,77 +140,77 @@  discard block
 block discarded – undo
140 140
 
141 141
     foreach ($this->dataSchemaTables as $table)
142 142
     {
143
-      if ($this->config['tables'][$table['table_name']]['audit'])
144
-      {
143
+        if ($this->config['tables'][$table['table_name']]['audit'])
144
+        {
145 145
         $tableColumns = [];
146 146
         if (isset($this->config['table_columns'][$table['table_name']]))
147 147
         {
148
-          $tableColumns = $this->config['table_columns'][$table['table_name']];
148
+            $tableColumns = $this->config['table_columns'][$table['table_name']];
149 149
         }
150 150
         $currentTable = new Table($this->io,
151
-                                  $table['table_name'],
152
-                                  $this->config['database']['data_schema'],
153
-                                  $this->config['database']['audit_schema'],
154
-                                  $tableColumns,
155
-                                  $this->config['audit_columns'],
156
-                                  $this->config['tables'][$table['table_name']]['alias'],
157
-                                  $this->config['tables'][$table['table_name']]['skip']);
151
+                                    $table['table_name'],
152
+                                    $this->config['database']['data_schema'],
153
+                                    $this->config['database']['audit_schema'],
154
+                                    $tableColumns,
155
+                                    $this->config['audit_columns'],
156
+                                    $this->config['tables'][$table['table_name']]['alias'],
157
+                                    $this->config['tables'][$table['table_name']]['skip']);
158 158
         $res          = StaticDataLayer::searchInRowSet('table_name', $currentTable->getTableName(), $this->auditSchemaTables);
159 159
         if (!isset($res))
160 160
         {
161
-          $currentTable->createMissingAuditTable();
161
+            $currentTable->createMissingAuditTable();
162 162
         }
163 163
 
164 164
         $columns        = $currentTable->main($this->config['additional_sql']);
165 165
         $alteredColumns = $columns['altered_columns']->getColumns();
166 166
         if (empty($alteredColumns))
167 167
         {
168
-          $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
168
+            $this->getColumns($currentTable->getTableName(), $columns['full_columns']);
169
+        }
169 170
         }
170
-      }
171 171
     }
172 172
 
173 173
     // Drop database connection
174 174
     DataLayer::disconnect();
175 175
 
176 176
     $this->rewriteConfig();
177
-  }
178
-
179
-  //--------------------------------------------------------------------------------------------------------------------
180
-  /**
181
-   * Get canonical column types for audit columns.
182
-   */
183
-  protected function auditColumnTypes()
184
-  {
177
+    }
178
+
179
+    //--------------------------------------------------------------------------------------------------------------------
180
+    /**
181
+     * Get canonical column types for audit columns.
182
+     */
183
+    protected function auditColumnTypes()
184
+    {
185 185
     $schema    = $this->config['database']['audit_schema'];
186 186
     $tableName = 'TMP_'.uniqid();
187 187
     DataLayer::createTemporaryTable($schema, $tableName, $this->config['audit_columns']);
188 188
     $auditColumns = DataLayer::showColumns($schema, $tableName);
189 189
     foreach ($auditColumns as $column)
190 190
     {
191
-      $key = StaticDataLayer::searchInRowSet('column_name', $column['Field'], $this->config['audit_columns']);
192
-      if (isset($key))
193
-      {
191
+        $key = StaticDataLayer::searchInRowSet('column_name', $column['Field'], $this->config['audit_columns']);
192
+        if (isset($key))
193
+        {
194 194
         $this->config['audit_columns'][$key]['column_type'] = $column['Type'];
195 195
         if ($column['Null']==='NO')
196 196
         {
197
-          $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
197
+            $this->config['audit_columns'][$key]['column_type'] = sprintf('%s not null', $this->config['audit_columns'][$key]['column_type']);
198
+        }
198 199
         }
199
-      }
200 200
     }
201 201
     DataLayer::dropTemporaryTable($schema, $tableName);
202
-  }
203
-
204
-  //--------------------------------------------------------------------------------------------------------------------
205
-  /**
206
-   * Write new data to config file.
207
-   */
208
-  private function rewriteConfig()
209
-  {
202
+    }
203
+
204
+    //--------------------------------------------------------------------------------------------------------------------
205
+    /**
206
+     * Write new data to config file.
207
+     */
208
+    private function rewriteConfig()
209
+    {
210 210
     $this->writeTwoPhases($this->configFileName, json_encode($this->config, JSON_PRETTY_PRINT));
211
-  }
211
+    }
212 212
 
213
-  //--------------------------------------------------------------------------------------------------------------------
213
+    //--------------------------------------------------------------------------------------------------------------------
214 214
 }
215 215
 
216 216
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/Application/AuditApplication.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -14,23 +14,23 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class AuditApplication extends Application
16 16
 {
17
-  //--------------------------------------------------------------------------------------------------------------------
18
-  /**
19
-   * Object constructor.
20
-   */
21
-  public function __construct()
22
-  {
17
+    //--------------------------------------------------------------------------------------------------------------------
18
+    /**
19
+     * Object constructor.
20
+     */
21
+    public function __construct()
22
+    {
23 23
     parent::__construct('AuditApplication');
24
-  }
24
+    }
25 25
 
26
-  //--------------------------------------------------------------------------------------------------------------------
27
-  /**
28
-   * Gets the default commands that should always be available.
29
-   *
30
-   * @return Command[] An array of default Command instances.
31
-   */
32
-  protected function getDefaultCommands()
33
-  {
26
+    //--------------------------------------------------------------------------------------------------------------------
27
+    /**
28
+     * Gets the default commands that should always be available.
29
+     *
30
+     * @return Command[] An array of default Command instances.
31
+     */
32
+    protected function getDefaultCommands()
33
+    {
34 34
     $commands = parent::getDefaultCommands();
35 35
 
36 36
     $commands[] = new AboutCommand();
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
     $commands[] = new DiffCommand();
39 39
 
40 40
     return $commands;
41
-  }
41
+    }
42 42
 
43
-  //--------------------------------------------------------------------------------------------------------------------
43
+    //--------------------------------------------------------------------------------------------------------------------
44 44
 }
45 45
 
46 46
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
src/Command/BaseCommand.php 3 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -13,148 +13,148 @@
 block discarded – undo
13 13
  */
14 14
 class BaseCommand extends Command
15 15
 {
16
-  //--------------------------------------------------------------------------------------------------------------------
17
-  /**
18
-   * All config file as array.
19
-   *
20
-   * @var array
21
-   */
22
-  protected $config;
23
-
24
-  /**
25
-   * The name of the configuration file.
26
-   *
27
-   * @var string
28
-   */
29
-  protected $configFileName;
30
-
31
-  /**
32
-   * The Output decorator.
33
-   *
34
-   * @var StratumStyle
35
-   */
36
-  protected $io;
37
-
38
-  //--------------------------------------------------------------------------------------------------------------------
39
-  /**
40
-   * Returns the value of a setting.
41
-   *
42
-   * @param array  $settings    The settings as returned by parse_ini_file.
43
-   * @param bool   $mandatory   If set and setting $settingName is not found in section $sectionName an exception
44
-   *                            will be thrown.
45
-   * @param string $sectionName The name of the section of the requested setting.
46
-   * @param string $settingName The name of the setting of the requested setting.
47
-   *
48
-   * @return null|string
49
-   *
50
-   * @throws RuntimeException
51
-   */
52
-  protected static function getSetting($settings, $mandatory, $sectionName, $settingName)
53
-  {
16
+    //--------------------------------------------------------------------------------------------------------------------
17
+    /**
18
+     * All config file as array.
19
+     *
20
+     * @var array
21
+     */
22
+    protected $config;
23
+
24
+    /**
25
+     * The name of the configuration file.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $configFileName;
30
+
31
+    /**
32
+     * The Output decorator.
33
+     *
34
+     * @var StratumStyle
35
+     */
36
+    protected $io;
37
+
38
+    //--------------------------------------------------------------------------------------------------------------------
39
+    /**
40
+     * Returns the value of a setting.
41
+     *
42
+     * @param array  $settings    The settings as returned by parse_ini_file.
43
+     * @param bool   $mandatory   If set and setting $settingName is not found in section $sectionName an exception
44
+     *                            will be thrown.
45
+     * @param string $sectionName The name of the section of the requested setting.
46
+     * @param string $settingName The name of the setting of the requested setting.
47
+     *
48
+     * @return null|string
49
+     *
50
+     * @throws RuntimeException
51
+     */
52
+    protected static function getSetting($settings, $mandatory, $sectionName, $settingName)
53
+    {
54 54
     // Test if the section exists.
55 55
     if (!array_key_exists($sectionName, $settings))
56 56
     {
57
-      if ($mandatory)
58
-      {
57
+        if ($mandatory)
58
+        {
59 59
         throw new RuntimeException("Section '%s' not found in configuration file.", $sectionName);
60
-      }
61
-      else
62
-      {
60
+        }
61
+        else
62
+        {
63 63
         return null;
64
-      }
64
+        }
65 65
     }
66 66
 
67 67
     // Test if the setting in the section exists.
68 68
     if (!array_key_exists($settingName, $settings[$sectionName]))
69 69
     {
70
-      if ($mandatory)
71
-      {
70
+        if ($mandatory)
71
+        {
72 72
         throw new RuntimeException("Setting '%s' not found in section '%s' configuration file.",
73
-                                   $settingName,
74
-                                   $sectionName);
75
-      }
76
-      else
77
-      {
73
+                                    $settingName,
74
+                                    $sectionName);
75
+        }
76
+        else
77
+        {
78 78
         return null;
79
-      }
79
+        }
80 80
     }
81 81
 
82 82
     return $settings[$sectionName][$settingName];
83
-  }
84
-
85
-  //--------------------------------------------------------------------------------------------------------------------
86
-  /**
87
-   * Reads configuration parameters from the configuration file.
88
-   */
89
-  public function readConfigFile()
90
-  {
83
+    }
84
+
85
+    //--------------------------------------------------------------------------------------------------------------------
86
+    /**
87
+     * Reads configuration parameters from the configuration file.
88
+     */
89
+    public function readConfigFile()
90
+    {
91 91
     $content = file_get_contents($this->configFileName);
92 92
 
93 93
     $this->config = (array)json_decode($content, true);
94 94
     if (json_last_error()!=JSON_ERROR_NONE)
95 95
     {
96
-      throw new RuntimeException("Error decoding JSON: '%s'.", json_last_error_msg());
96
+        throw new RuntimeException("Error decoding JSON: '%s'.", json_last_error_msg());
97 97
     }
98 98
 
99 99
     if (!is_array($this->config['audit_columns']))
100 100
     {
101
-      $this->config['audit_columns'] = [];
101
+        $this->config['audit_columns'] = [];
102 102
     }
103 103
 
104 104
     if (!is_array($this->config['additional_sql']))
105 105
     {
106
-      $this->config['additional_sql'] = [];
106
+        $this->config['additional_sql'] = [];
107 107
     }
108 108
 
109 109
     if (!is_array($this->config['tables']))
110 110
     {
111
-      $this->config['tables'] = [];
111
+        $this->config['tables'] = [];
112 112
     }
113 113
 
114 114
     foreach ($this->config['tables'] as $table_name => $params)
115 115
     {
116
-      $this->config['tables'][$table_name]['audit'] = filter_var($params['audit'], FILTER_VALIDATE_BOOLEAN);
116
+        $this->config['tables'][$table_name]['audit'] = filter_var($params['audit'], FILTER_VALIDATE_BOOLEAN);
117 117
     }
118
-  }
119
-
120
-  //--------------------------------------------------------------------------------------------------------------------
121
-  /**
122
-   * Writes a file in two phase to the filesystem.
123
-   *
124
-   * First write the data to a temporary file (in the same directory) and than renames the temporary file. If the file
125
-   * already exists and its content is equal to the data that must be written no action  is taken. This has the
126
-   * following advantages:
127
-   * * In case of some write error (e.g. disk full) the original file is kept in tact and no file with partially data
128
-   * is written.
129
-   * * Renaming a file is atomic. So, running processes will never read a partially written data.
130
-   *
131
-   * @param string $filename The name of the file were the data must be stored.
132
-   * @param string $data     The data that must be written.
133
-   */
134
-  protected function writeTwoPhases($filename, $data)
135
-  {
118
+    }
119
+
120
+    //--------------------------------------------------------------------------------------------------------------------
121
+    /**
122
+     * Writes a file in two phase to the filesystem.
123
+     *
124
+     * First write the data to a temporary file (in the same directory) and than renames the temporary file. If the file
125
+     * already exists and its content is equal to the data that must be written no action  is taken. This has the
126
+     * following advantages:
127
+     * * In case of some write error (e.g. disk full) the original file is kept in tact and no file with partially data
128
+     * is written.
129
+     * * Renaming a file is atomic. So, running processes will never read a partially written data.
130
+     *
131
+     * @param string $filename The name of the file were the data must be stored.
132
+     * @param string $data     The data that must be written.
133
+     */
134
+    protected function writeTwoPhases($filename, $data)
135
+    {
136 136
     $write_flag = true;
137 137
     if (file_exists($filename))
138 138
     {
139
-      $old_data = file_get_contents($filename);
140
-      if ($data==$old_data) $write_flag = false;
139
+        $old_data = file_get_contents($filename);
140
+        if ($data==$old_data) $write_flag = false;
141 141
     }
142 142
 
143 143
     if ($write_flag)
144 144
     {
145
-      $tmp_filename = $filename.'.tmp';
146
-      file_put_contents($tmp_filename, $data);
147
-      rename($tmp_filename, $filename);
145
+        $tmp_filename = $filename.'.tmp';
146
+        file_put_contents($tmp_filename, $data);
147
+        rename($tmp_filename, $filename);
148 148
 
149
-      $this->io->text(sprintf('Wrote <fso>%s</fso>', OutputFormatter::escape($filename)));
149
+        $this->io->text(sprintf('Wrote <fso>%s</fso>', OutputFormatter::escape($filename)));
150 150
     }
151 151
     else
152 152
     {
153
-      $this->io->text(sprintf('File <fso>%s</fso> is up to date', OutputFormatter::escape($filename)));
153
+        $this->io->text(sprintf('File <fso>%s</fso> is up to date', OutputFormatter::escape($filename)));
154
+    }
154 155
     }
155
-  }
156 156
 
157
-  //--------------------------------------------------------------------------------------------------------------------
157
+    //--------------------------------------------------------------------------------------------------------------------
158 158
 }
159 159
 
160 160
 //----------------------------------------------------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
   {
91 91
     $content = file_get_contents($this->configFileName);
92 92
 
93
-    $this->config = (array)json_decode($content, true);
94
-    if (json_last_error()!=JSON_ERROR_NONE)
93
+    $this->config = (array) json_decode($content, true);
94
+    if (json_last_error() != JSON_ERROR_NONE)
95 95
     {
96 96
       throw new RuntimeException("Error decoding JSON: '%s'.", json_last_error_msg());
97 97
     }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     if (file_exists($filename))
138 138
     {
139 139
       $old_data = file_get_contents($filename);
140
-      if ($data==$old_data) $write_flag = false;
140
+      if ($data == $old_data) $write_flag = false;
141 141
     }
142 142
 
143 143
     if ($write_flag)
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -57,8 +57,7 @@  discard block
 block discarded – undo
57 57
       if ($mandatory)
58 58
       {
59 59
         throw new RuntimeException("Section '%s' not found in configuration file.", $sectionName);
60
-      }
61
-      else
60
+      } else
62 61
       {
63 62
         return null;
64 63
       }
@@ -72,8 +71,7 @@  discard block
 block discarded – undo
72 71
         throw new RuntimeException("Setting '%s' not found in section '%s' configuration file.",
73 72
                                    $settingName,
74 73
                                    $sectionName);
75
-      }
76
-      else
74
+      } else
77 75
       {
78 76
         return null;
79 77
       }
@@ -137,7 +135,9 @@  discard block
 block discarded – undo
137 135
     if (file_exists($filename))
138 136
     {
139 137
       $old_data = file_get_contents($filename);
140
-      if ($data==$old_data) $write_flag = false;
138
+      if ($data==$old_data) {
139
+          $write_flag = false;
140
+      }
141 141
     }
142 142
 
143 143
     if ($write_flag)
@@ -147,8 +147,7 @@  discard block
 block discarded – undo
147 147
       rename($tmp_filename, $filename);
148 148
 
149 149
       $this->io->text(sprintf('Wrote <fso>%s</fso>', OutputFormatter::escape($filename)));
150
-    }
151
-    else
150
+    } else
152 151
     {
153 152
       $this->io->text(sprintf('File <fso>%s</fso> is up to date', OutputFormatter::escape($filename)));
154 153
     }
Please login to merge, or discard this patch.