Test Failed
Push — master ( eaa667...0d9623 )
by Evgenii
38:52
created
tests/unit/BackupCreateTest.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,8 +101,9 @@
 block discarded – undo
101 101
     {
102 102
         $config_id = 'backup_test_folder';
103 103
         $creator = new BackupCreate($config_id);
104
-        for ($i = 0; $i < 5; $i++)
105
-            $creator->run();
104
+        for ($i = 0; $i < 5; $i++) {
105
+                    $creator->run();
106
+        }
106 107
     }
107 108
 
108 109
 
Please login to merge, or discard this patch.
src/Module.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -81,14 +81,16 @@  discard block
 block discarded – undo
81 81
         $this->backupRootPath = Yii::getAlias($this->backupFolder);
82 82
 
83 83
         try {
84
-            if (!file_exists($this->backupRootPath))
85
-                mkdir($this->backupRootPath);
84
+            if (!file_exists($this->backupRootPath)) {
85
+                            mkdir($this->backupRootPath);
86
+            }
86 87
         } catch (ErrorException $e) {
87 88
             throw new ErrorException("Backup folder not exists. Its impossible to create it because of permission error.");
88 89
         }
89 90
 
90
-        if (!is_writable($this->backupRootPath))
91
-            throw new ErrorException("Backup folder is not writable.");
91
+        if (!is_writable($this->backupRootPath)) {
92
+                    throw new ErrorException("Backup folder is not writable.");
93
+        }
92 94
 
93 95
         $this->checkSqliteDb();
94 96
         $this->registerTranslations();
@@ -129,9 +131,10 @@  discard block
 block discarded – undo
129 131
      */
130 132
     public function checkConfig(string $config_id)
131 133
     {
132
-        foreach (Yii::$app->getModule('backup')->configs as $config)
133
-            if ($config['id'] == $config_id)
134
+        foreach (Yii::$app->getModule('backup')->configs as $config) {
135
+                    if ($config['id'] == $config_id)
134 136
                 return true;
137
+        }
135 138
         return false;
136 139
     }
137 140
 
Please login to merge, or discard this patch.
src/logic/DatabaseBackuper.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,9 @@
 block discarded – undo
47 47
      */
48 48
     public function backup()
49 49
     {
50
-        if (file_exists($this->backupFilePath))
51
-            throw new Exception("Backup file exists.");
50
+        if (file_exists($this->backupFilePath)) {
51
+                    throw new Exception("Backup file exists.");
52
+        }
52 53
         $this->dbProcessor->backup();
53 54
     }
54 55
 
Please login to merge, or discard this patch.
src/logic/FolderBackupRestorer.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,11 +25,13 @@
 block discarded – undo
25 25
      */
26 26
     public function __construct(string $backupFilePath, string $targetFolder, $io = IOPriority::IDLE)
27 27
     {
28
-        if (!file_exists($backupFilePath))
29
-            throw new Exception("Backup file don`t exist..");
28
+        if (!file_exists($backupFilePath)) {
29
+                    throw new Exception("Backup file don`t exist..");
30
+        }
30 31
 
31
-        if (!file_exists($targetFolder))
32
-            throw new Exception("Target folder don`t exist.");
32
+        if (!file_exists($targetFolder)) {
33
+                    throw new Exception("Target folder don`t exist.");
34
+        }
33 35
 
34 36
         $this->backupFilePath = $backupFilePath;
35 37
         $this->targetFolder = $targetFolder;
Please login to merge, or discard this patch.
src/logic/BackupCreate.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@
 block discarded – undo
99 99
                 $targetPath = Yii::getAlias($this->currentConfig['path']);
100 100
                 Yii::createObject(FolderBackupMaker::class, [$this->model->getFullPath(), $targetPath, $this->currentConfig['io']])->execute();
101 101
             }
102
-        } catch (MysqlDumpException|PostgresDumpException|FolderDumpException $exception) {
102
+        } catch (MysqlDumpException | PostgresDumpException | FolderDumpException $exception) {
103 103
             $this->setBackupFailed();
104 104
             throw new $exception;
105 105
         }
Please login to merge, or discard this patch.
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -61,8 +61,9 @@  discard block
 block discarded – undo
61 61
     protected function loadConfigs()
62 62
     {
63 63
         $this->configs = Yii::$app->getModule('backup')->configs;
64
-        if (!is_array($this->configs) || !sizeof($this->configs))
65
-            throw new ModuleNotConfiguredException('Backup configs is empty');
64
+        if (!is_array($this->configs) || !sizeof($this->configs)) {
65
+                    throw new ModuleNotConfiguredException('Backup configs is empty');
66
+        }
66 67
     }
67 68
 
68 69
     /**
@@ -71,8 +72,9 @@  discard block
 block discarded – undo
71 72
      */
72 73
     protected function setUpActiveConfig()
73 74
     {
74
-        if (!is_array($this->configs[$this->config_id]))
75
-            throw new ConfigurationNotFoundException("Configuration `{$this->config_id}` not found.");
75
+        if (!is_array($this->configs[$this->config_id])) {
76
+                    throw new ConfigurationNotFoundException("Configuration `{$this->config_id}` not found.");
77
+        }
76 78
         $this->currentConfig = $this->configs[$this->config_id];
77 79
     }
78 80
 
@@ -87,8 +89,9 @@  discard block
 block discarded – undo
87 89
         $this->deleteOldFiles();
88 90
         $this->createBackupItem();
89 91
 
90
-        if (empty($this->currentConfig['io']))
91
-            $this->currentConfig['io'] = IOPriority::IDLE;
92
+        if (empty($this->currentConfig['io'])) {
93
+                    $this->currentConfig['io'] = IOPriority::IDLE;
94
+        }
92 95
         try {
93 96
             if ($this->currentConfig['type'] == BackupType::DB) {
94 97
                 $connection = Yii::$app->{$this->currentConfig['connection']};
@@ -114,17 +117,19 @@  discard block
 block discarded – undo
114 117
      */
115 118
     protected function deleteOldFiles()
116 119
     {
117
-        if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit']))
118
-            return false;
120
+        if (!isset($this->currentConfig['limit']) || empty($this->currentConfig['limit'])) {
121
+                    return false;
122
+        }
119 123
         $backups = Backup::find()
120 124
             ->where(['config_id' => $this->config_id])
121 125
             ->orderBy('date DESC')
122 126
             ->offset($this->currentConfig['limit'] - 1)
123 127
             ->all();
124 128
 
125
-        if ($backups)
126
-            foreach ($backups as $backup)
129
+        if ($backups) {
130
+                    foreach ($backups as $backup)
127 131
                 $backup->delete();
132
+        }
128 133
     }
129 134
 
130 135
     /**
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
             $extension = Backup::EXT_TGZ;
153 158
             /** @var Connection $connection */
154 159
             $connection = Yii::$app->{$this->currentConfig['connection']};
155
-            if ($connection->driverName == 'pgsql')
156
-                $extension = Backup::EXT_DUMP;
160
+            if ($connection->driverName == 'pgsql') {
161
+                            $extension = Backup::EXT_DUMP;
162
+            }
157 163
         }
158 164
         $date = date("Y-m-d_H-i-s");
159 165
         $rand = substr(md5(rand(0, 9999)), 0, 3);
Please login to merge, or discard this patch.
src/logic/DatabaseBackupRestorer.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@
 block discarded – undo
32 32
      */
33 33
     public function __construct(string $backupFilePath, Connection $connection)
34 34
     {
35
-        if (file_exists($backupFilePath))
36
-            throw new Exception("Backup file exists.");
35
+        if (file_exists($backupFilePath)) {
36
+                    throw new Exception("Backup file exists.");
37
+        }
37 38
 
38 39
         $currentProcessorClassname = $this->dbProcessors[$connection->driverName];
39 40
         $this->dbProcessor = new $currentProcessorClassname($backupFilePath, $connection);
Please login to merge, or discard this patch.
src/logic/processors/MysqlProcessor.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,8 +25,9 @@  discard block
 block discarded – undo
25 25
         $this->checkBinary($ionicePath);
26 26
         $command = "{$ionicePath} -c{$this->io} {$mysqldumpPath} -h {$this->host} -P {$this->port} -u {$this->username}  -p{$this->password}  {$this->database} | {$gzipPath} -9 -c > {$this->backupFilePath}";
27 27
         (exec($command));
28
-        if (!file_exists($this->backupFilePath) || filesize($this->backupFilePath) < 100)
29
-            throw new MysqlDumpException();
28
+        if (!file_exists($this->backupFilePath) || filesize($this->backupFilePath) < 100) {
29
+                    throw new MysqlDumpException();
30
+        }
30 31
     }
31 32
 
32 33
     public function restore()
@@ -37,7 +38,8 @@  discard block
 block discarded – undo
37 38
         $this->checkBinary($mysqlPath);
38 39
         $command = "{$zcatPath} {$this->backupFilePath} | {$mysqlPath} -h {$this->host} -P {$this->port} -u {$this->username} -p{$this->password} {$this->database}";
39 40
         exec($command, $return);
40
-        if (!empty($return))
41
-            throw new PostgresDumpException();
41
+        if (!empty($return)) {
42
+                    throw new PostgresDumpException();
43
+        }
42 44
     }
43 45
 }
Please login to merge, or discard this patch.
src/logic/processors/DbProcessor.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -58,13 +58,15 @@  discard block
 block discarded – undo
58 58
         $dsn = substr($dsn, strpos($dsn, ':') + 1);
59 59
         $dsnParts = explode(';', $dsn);
60 60
 
61
-        if (empty($dsnParts))
62
-            throw new DsnParseException();
61
+        if (empty($dsnParts)) {
62
+                    throw new DsnParseException();
63
+        }
63 64
 
64 65
         foreach ($dsnParts as $part) {
65 66
             $row = explode('=', $part);
66
-            if (isset($row[0]) && isset($row[1]))
67
-                $this->parsedDsn[$row[0]] = $row[1];
67
+            if (isset($row[0]) && isset($row[1])) {
68
+                            $this->parsedDsn[$row[0]] = $row[1];
69
+            }
68 70
         }
69 71
 
70 72
         $this->host = $this->parsedDsn['host'] ?: null;
@@ -74,8 +76,9 @@  discard block
 block discarded – undo
74 76
 
75 77
     protected function checkBinary(string $binary)
76 78
     {
77
-        if (!file_exists($binary) || !is_executable($binary))
78
-            throw new BinaryNotFoundException($binary);
79
+        if (!file_exists($binary) || !is_executable($binary)) {
80
+                    throw new BinaryNotFoundException($binary);
81
+        }
79 82
     }
80 83
 
81 84
     public function backup()
Please login to merge, or discard this patch.
src/logic/processors/PostgresProcessor.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
         $ionicePath = $this->module->binaries['ionice'];
16 16
         $command = "PGPASSWORD='{$this->password}' {$ionicePath} -c{$this->io} {$binaryPath} -h {$this->host} -p {$this->port} -U {$this->username} -Fc -Z1 {$this->database} -f {$this->backupFilePath}";
17 17
         exec($command, $return);
18
-        if (!empty($return))
19
-            throw new PostgresDumpException();
18
+        if (!empty($return)) {
19
+                    throw new PostgresDumpException();
20
+        }
20 21
     }
21 22
 
22 23
     public function restore()
@@ -24,8 +25,9 @@  discard block
 block discarded – undo
24 25
         $binaryPath = $this->module->binaries['pg_restore'];
25 26
         $command = "PGPASSWORD='{$this->password}' {$binaryPath} -c -Fc -j 4 -h {$this->host} -p {$this->port} -U {$this->username}  -d {$this->database} {$this->backupFilePath}";
26 27
         exec($command, $return);
27
-        if (!empty($return))
28
-            throw new PostgresDumpException();
28
+        if (!empty($return)) {
29
+                    throw new PostgresDumpException();
30
+        }
29 31
     }
30 32
 
31 33
     public function init()
Please login to merge, or discard this patch.