mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
💚 Update rules for PHPMD
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Shikiryu\Backup\Backup;
|
||||
|
||||
use Exception;
|
||||
use ZipArchive;
|
||||
|
||||
abstract class BackupAbstract
|
||||
{
|
||||
/**
|
||||
@@ -163,18 +166,18 @@ abstract class BackupAbstract
|
||||
* Enabled via options
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setOptionZip()
|
||||
{
|
||||
$zip = new \ZipArchive();
|
||||
$zip = new ZipArchive();
|
||||
// Zip name
|
||||
$zip_name = !empty($this->options['name']) ? $this->options['name'] : time();
|
||||
$zip_name = sprintf('%s.zip', $zip_name);
|
||||
if (touch(TEMP_DIR . $zip_name) === false) {
|
||||
throw new \Exception('Backup::Zip::Permission denied.');
|
||||
throw new Exception('Backup::Zip::Permission denied.');
|
||||
}
|
||||
if ($zip->open(TEMP_DIR . $zip_name, \ZipArchive::OVERWRITE) === true) {
|
||||
if ($zip->open(TEMP_DIR . $zip_name, ZipArchive::OVERWRITE) === true) {
|
||||
foreach ($this->files_to_backup as $file => $name) {
|
||||
$zip->addFile($file, $name); // Adding files into zip
|
||||
}
|
||||
@@ -184,7 +187,7 @@ abstract class BackupAbstract
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
throw new \Exception('Backup::Zip::Can\'t zip the given backup.');
|
||||
throw new Exception('Backup::Zip::Can\'t zip the given backup.');
|
||||
}
|
||||
|
||||
$this->files_to_backup = [TEMP_DIR . $zip_name => $zip_name];
|
||||
@@ -260,14 +263,14 @@ abstract class BackupAbstract
|
||||
*
|
||||
* @param mixed $name option's name
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*
|
||||
* @SuppressWarnings("unused")
|
||||
*/
|
||||
protected function setOptionName($name)
|
||||
{
|
||||
if (empty($this->options['zip'])) {
|
||||
throw new \Exception('name option is for zip only.');
|
||||
throw new Exception('name option is for zip only.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace Shikiryu\Backup\Backup;
|
||||
|
||||
use PDO;
|
||||
|
||||
class Mysql extends BackupAbstract
|
||||
{
|
||||
use IsLocalTrait;
|
||||
|
||||
/**
|
||||
* @var $pdo \PDO
|
||||
* @var $pdo PDO
|
||||
*/
|
||||
private $pdo;
|
||||
|
||||
@@ -106,7 +108,7 @@ class Mysql extends BackupAbstract
|
||||
*/
|
||||
protected function preBuild()
|
||||
{
|
||||
$this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->login, $this->pwd);
|
||||
$this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->login, $this->pwd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Shikiryu\Backup\Backup;
|
||||
|
||||
use Exception;
|
||||
use phpseclib\Crypt\RSA;
|
||||
use phpseclib\Net\SFTP as LibSFTP;
|
||||
use phpseclib\Net\SSH2;
|
||||
@@ -28,7 +29,7 @@ class SFTP extends BackupAbstract
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (!isset($config['files'])) {
|
||||
throw new \Exception('Files needs a "files" configuration.');
|
||||
throw new Exception('Files needs a "files" configuration.');
|
||||
}
|
||||
$filesToBackup = $config['files'];
|
||||
if (!empty($filesToBackup) && is_array($filesToBackup)) {
|
||||
@@ -65,7 +66,7 @@ class SFTP extends BackupAbstract
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
@@ -79,7 +80,7 @@ class SFTP extends BackupAbstract
|
||||
$this->password->loadKey(file_get_contents($this->key));
|
||||
}
|
||||
if (!$this->connection->login($this->login, $this->password)) {
|
||||
throw new \Exception(sprintf('I can\'t connect to the SFTP %s', $this->host));
|
||||
throw new Exception(sprintf('I can\'t connect to the SFTP %s', $this->host));
|
||||
}
|
||||
|
||||
$this->connection->enableQuietMode();
|
||||
@@ -103,7 +104,7 @@ class SFTP extends BackupAbstract
|
||||
try {
|
||||
$tmp_backup = new Files(['files' => $tmp_files]);
|
||||
unset($tmp_files);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user