Passed
Push — master ( e6d07d...6228a9 )
by Patrick
01:54
created
library/Trapdirector/TrapsActions/UIDatabase.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
      * @param int $code
25 25
      * @param Exception $previous
26 26
      */
27
-    public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
27
+    public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null)
28 28
     {
29
-        parent::__construct($message,$code,$previous);
30
-        $this->returnArray = $retarray;
29
+        parent::__construct($message, $code, $previous);
30
+        $this->returnArray=$retarray;
31 31
     }
32 32
     
33 33
     /**
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
      * @return bool true if OK, false if version < min version
84 84
      * @throws Exception if error and test = true
85 85
      */
86
-    protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
86
+    protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname)
87 87
     {
88 88
         try
89 89
         {
90
-            $query = $dbAdapter->select()
91
-            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
90
+            $query=$dbAdapter->select()
91
+            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value')
92 92
             ->where('name=\'db_version\'');
93 93
             $version=$dbAdapter->fetchRow($query);
94
-            if ( ($version == null) || ! property_exists($version,'value') )
94
+            if (($version == null) || !property_exists($version, 'value'))
95 95
             {
96 96
                 if ($test === true) 
97 97
                 {
98
-                    $this->testResult = array(4,$DBname);
98
+                    $this->testResult=array(4, $DBname);
99 99
                     return false;
100 100
                 }
101 101
                 $this->trapController->redirectNow('trapdirector/settings?dberror=4');
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             {
106 106
                 if ($test === true) 
107 107
                 {
108
-                    $this->testResult = array(5,$version->value,$min);
108
+                    $this->testResult=array(5, $version->value, $min);
109 109
                     return false;
110 110
                 }
111 111
                 $this->trapController->redirectNow('trapdirector/settings?dberror=5');
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         {
117 117
             if ($test === true) 
118 118
             {
119
-                $this->testResult = array(3,$DBname,$e->getMessage());
119
+                $this->testResult=array(3, $DBname, $e->getMessage());
120 120
                 return false;
121 121
             }
122 122
             $this->trapController->redirectNow('trapdirector/settings?dberror=4');
@@ -132,17 +132,17 @@  discard block
 block discarded – undo
132 132
      *  @throws DBException if test = true and error
133 133
      *	@return Zend_Db_Adapter_Abstract|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
134 134
      */
135
-    protected function getDbByName($DBname , $test = false , $test_version = true)
135
+    protected function getDbByName($DBname, $test=false, $test_version=true)
136 136
     {
137 137
         try
138 138
         {
139
-            $dbconn = IcingaDbConnection::fromResourceName($DBname);
139
+            $dbconn=IcingaDbConnection::fromResourceName($DBname);
140 140
         }
141 141
         catch (Exception $e)
142 142
         {
143 143
             if ($test === true) 
144 144
             {
145
-                throw new DBException(array(2,$DBname));
145
+                throw new DBException(array(2, $DBname));
146 146
             }
147 147
             $this->trapController->redirectNow('trapdirector/settings?dberror=2');
148 148
             return null;
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         {
158 158
             if ($test === true)
159 159
             {
160
-                throw new DBException(array(3,$DBname,$e->getMessage()));
160
+                throw new DBException(array(3, $DBname, $e->getMessage()));
161 161
             }
162 162
             $this->trapController->redirectNow('trapdirector/settings?dberror=3');
163 163
             return null;
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public function getDb($test=false)
183 183
     {
184
-        if ($this->trapDB != null && $test = false) return $this->trapDB;
184
+        if ($this->trapDB != null && $test=false) return $this->trapDB;
185 185
         
186 186
         $dbresource=$this->trapController->Config()->get('config', 'database');
187 187
         
188
-        if ( ! $dbresource )
188
+        if (!$dbresource)
189 189
         {
190 190
             if ($test === true) 
191 191
             {
192
-                throw new DBException(array(1,''));
192
+                throw new DBException(array(1, ''));
193 193
             }
194 194
             $this->trapController->redirectNow('trapdirector/settings?dberror=1');
195 195
             return null;
196 196
         }
197 197
 
198
-        $this->trapDB = $this->getDbByName($dbresource,$test,true);
198
+        $this->trapDB=$this->getDbByName($dbresource, $test, true);
199 199
         
200 200
         return $this->trapDB;
201 201
     }
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
     {
210 210
         if ($this->idoDB != null && $test === false) return $this->idoDB;
211 211
         // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
212
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
212
+        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ;
213 213
         
214
-        if ( ! $dbresource )
214
+        if (!$dbresource)
215 215
         {
216 216
             if ($test === true) 
217 217
             {
218
-                throw new DBException(array(1,'No database in config.ini'));
218
+                throw new DBException(array(1, 'No database in config.ini'));
219 219
             }
220 220
             $this->redirectNow('trapdirector/settings?idodberror=1');
221 221
             return null;
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
         
224 224
         try
225 225
         {
226
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
226
+            $dbconn=IcingaDbConnection::fromResourceName($dbresource);
227 227
         }
228 228
         catch (Exception $e)
229 229
         {
230 230
             if ($test === true)
231 231
             {
232
-                throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
232
+                throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2"));
233 233
             }
234 234
             $this->redirectNow('trapdirector/settings?idodberror=2');
235 235
             return null;
@@ -237,23 +237,23 @@  discard block
 block discarded – undo
237 237
         
238 238
         if ($test === false)
239 239
         {
240
-            $this->idoDB = $dbconn->getDbAdapter();
240
+            $this->idoDB=$dbconn->getDbAdapter();
241 241
             return $this->idoDB;
242 242
         }
243 243
         
244 244
         try
245 245
         {
246
-            $query = $dbconn->select()
247
-            ->from('icinga_dbversion',array('version'));
246
+            $query=$dbconn->select()
247
+            ->from('icinga_dbversion', array('version'));
248 248
             $version=$dbconn->fetchRow($query);
249
-            if ( ($version == null) || ! property_exists($version,'version') )
249
+            if (($version == null) || !property_exists($version, 'version'))
250 250
             {
251
-                return array(4,"$dbresource does not look like an IDO database");
251
+                return array(4, "$dbresource does not look like an IDO database");
252 252
             }
253 253
         }
254 254
         catch (Exception $e)
255 255
         {
256
-            throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
256
+            throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage()));
257 257
         }
258 258
         
259 259
         return $this->idoDB;
Please login to merge, or discard this patch.