From f90bfe8814ef316c0aa9b83327d330272ab68c3a Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 19 May 2020 02:59:08 +0000 Subject: [PATCH] Apply fixes from StyleCI [ci skip] [skip ci] --- app/Helpers/BackupEncryption.php | 25 ++++++------- app/Helpers/BackupPassword.php | 35 ++++++++++--------- .../Controllers/Staff/BackupController.php | 20 +++++------ app/Listeners/PasswordProtectBackup.php | 7 ++-- config/backup.php | 4 +-- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/app/Helpers/BackupEncryption.php b/app/Helpers/BackupEncryption.php index 94a974e571..146f9d3494 100644 --- a/app/Helpers/BackupEncryption.php +++ b/app/Helpers/BackupEncryption.php @@ -16,28 +16,28 @@ class BackupEncryption { /** - * Default encryption contants + * Default encryption contants. * * @var string */ const ENCRYPTION_DEFAULT = 'default'; /** - * AES-128 encryption contants + * AES-128 encryption contants. * * @var string */ const ENCRYPTION_WINZIP_AES_128 = 'aes_128'; /** - * AES-192 encryption contants + * AES-192 encryption contants. * * @var string */ const ENCRYPTION_WINZIP_AES_192 = 'aes_192'; /** - * AES-256 encryption contants + * AES-256 encryption contants. * * @var string */ @@ -45,37 +45,38 @@ class BackupEncryption /** * ZipArchive encryption constants; stores as simple string for PHP < 7.2 - * backwards compatability + * backwards compatability. * * @var array */ private $zipArchiveOptions = [ - self::ENCRYPTION_DEFAULT => '257', + self::ENCRYPTION_DEFAULT => '257', self::ENCRYPTION_WINZIP_AES_128 => '257', self::ENCRYPTION_WINZIP_AES_192 => '258', self::ENCRYPTION_WINZIP_AES_256 => '259', ]; /** - * ZipFile encryption constants + * ZipFile encryption constants. * * @var array */ private $zipFileOptions = [ - self::ENCRYPTION_DEFAULT => \PhpZip\Constants\ZipEncryptionMethod::PKWARE, + self::ENCRYPTION_DEFAULT => \PhpZip\Constants\ZipEncryptionMethod::PKWARE, self::ENCRYPTION_WINZIP_AES_128 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_128, self::ENCRYPTION_WINZIP_AES_192 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_192, self::ENCRYPTION_WINZIP_AES_256 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_256, ]; /** - * Retrive appropriate encryption constant + * Retrive appropriate encryption constant. * * @param string $type * @param string $engine * - * @return mixed * @throws \Exception + * + * @return mixed */ public function getEncryptionConstant($type, $engine) { @@ -83,8 +84,8 @@ public function getEncryptionConstant($type, $engine) return $this->zipArchiveOptions[$type]; } elseif ($engine == 'ZipFile' && isset($this->zipFileOptions[$type])) { return $this->zipFileOptions[$type]; - } else { - throw new \Exception("Encryption key not set or invalid value", 1); } + + throw new \Exception('Encryption key not set or invalid value', 1); } } diff --git a/app/Helpers/BackupPassword.php b/app/Helpers/BackupPassword.php index ee200ade19..562c2781fc 100644 --- a/app/Helpers/BackupPassword.php +++ b/app/Helpers/BackupPassword.php @@ -15,37 +15,37 @@ use Illuminate\Support\Collection; use PhpZip\ZipFile; -use \ZipArchive; +use ZipArchive; class BackupPassword { /** - * Path to .zip-file + * Path to .zip-file. * * @var string */ public $path; /** - * The chosen password + * The chosen password. * * @var string */ protected $password; /** - * Read the .zip, apply password and encryption, then rewrite the file + * Read the .zip, apply password and encryption, then rewrite the file. * * @param \App\Helpers\BackupEncryption $encryption - * @param string $path the path to the .zip-file + * @param string $path the path to the .zip-file * * @throws \PhpZip\Exception\ZipException */ - function __construct(BackupEncryption $encryption, string $path) + public function __construct(BackupEncryption $encryption, string $path) { $this->password = config('backup.security.password'); - if (!$this->password) { + if (! $this->password) { return $this->path = $path; } @@ -65,23 +65,23 @@ function __construct(BackupEncryption $encryption, string $path) } /** - * Use native PHP ZipArchive + * Use native PHP ZipArchive. * * @param \App\Helpers\BackupEncryption $encryption + * @param string $path * - * @param string $path - * - * @return void * @throws \Exception + * + * @return void */ - protected function makeZipArchive(BackupEncryption $encryption, string $path) : void + protected function makeZipArchive(BackupEncryption $encryption, string $path): void { $encryptionConstant = $encryption->getEncryptionConstant( config('backup.security.encryption'), 'ZipArchive' ); - $zipArchive = new ZipArchive; + $zipArchive = new ZipArchive(); $zipArchive->open($path, ZipArchive::OVERWRITE); $zipArchive->addFile($path, 'backup.zip'); @@ -95,14 +95,15 @@ protected function makeZipArchive(BackupEncryption $encryption, string $path) : } /** - * Use PhpZip\ZipFile-package to create the zip + * Use PhpZip\ZipFile-package to create the zip. * * @param \App\Helpers\BackupEncryption $encryption * - * @return void * @throws \PhpZip\Exception\ZipException + * + * @return void */ - protected function makeZipFile(BackupEncryption $encryption, string $path) : void + protected function makeZipFile(BackupEncryption $encryption, string $path): void { $encryptionConstant = $encryption->getEncryptionConstant( config('backup.security.encryption'), @@ -117,4 +118,4 @@ protected function makeZipFile(BackupEncryption $encryption, string $path) : voi $this->path = $path; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Staff/BackupController.php b/app/Http/Controllers/Staff/BackupController.php index 87f6c538ec..36aaef1780 100644 --- a/app/Http/Controllers/Staff/BackupController.php +++ b/app/Http/Controllers/Staff/BackupController.php @@ -16,8 +16,8 @@ use Exception; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use League\Flysystem\Adapter\Local; @@ -92,11 +92,11 @@ public function create(Request $request) $output = Artisan::output(); if (strpos($output, 'Backup failed because')) { preg_match('Backup failed because(.*?)$/ms', $output, $match); - $message = "BackupManager process failed because "; - $message .= isset($match[1]) ? $match[1] : ''; + $message = 'BackupManager process failed because '; + $message .= $match[1] ?? ''; Log::error($message.PHP_EOL.$output); } else { - Log::info("BackupManager process has started"); + Log::info('BackupManager process has started'); } } catch (Exception $e) { Log::error($e); @@ -128,11 +128,11 @@ public function files(Request $request) $output = Artisan::output(); if (strpos($output, 'Backup failed because')) { preg_match('Backup failed because(.*?)$/ms', $output, $match); - $message = "BackupManager process failed because "; - $message .= isset($match[1]) ? $match[1] : ''; + $message = 'BackupManager process failed because '; + $message .= $match[1] ?? ''; Log::error($message.PHP_EOL.$output); } else { - Log::info("BackupManager process has started"); + Log::info('BackupManager process has started'); } } catch (Exception $e) { Log::error($e); @@ -164,11 +164,11 @@ public function database(Request $request) $output = Artisan::output(); if (strpos($output, 'Backup failed because')) { preg_match('Backup failed because(.*?)$/ms', $output, $match); - $message = "BackupManager process failed because "; - $message .= isset($match[1]) ? $match[1] : ''; + $message = 'BackupManager process failed because '; + $message .= $match[1] ?? ''; Log::error($message.PHP_EOL.$output); } else { - Log::info("BackupManager process has started"); + Log::info('BackupManager process has started'); } } catch (Exception $e) { Log::error($e); diff --git a/app/Listeners/PasswordProtectBackup.php b/app/Listeners/PasswordProtectBackup.php index 011e49b38b..7783c66381 100644 --- a/app/Listeners/PasswordProtectBackup.php +++ b/app/Listeners/PasswordProtectBackup.php @@ -33,11 +33,12 @@ public function __construct() * * @param \Spatie\Backup\Events\BackupZipWasCreated $event * - * @return string * @throws \PhpZip\Exception\ZipException + * + * @return string */ - public function handle(BackupZipWasCreated $event) : string + public function handle(BackupZipWasCreated $event): string { - return (new BackupPassword(new \App\Helpers\BackupEncryption, $event->pathToZip))->path; + return (new BackupPassword(new \App\Helpers\BackupEncryption(), $event->pathToZip))->path; } } diff --git a/config/backup.php b/config/backup.php index c78a33a229..aa30a6c095 100644 --- a/config/backup.php +++ b/config/backup.php @@ -232,8 +232,8 @@ ], 'security' => [ - 'password' => env('APP_KEY'), - 'encryption' => \App\Helpers\BackupEncryption::ENCRYPTION_DEFAULT + 'password' => env('APP_KEY'), + 'encryption' => \App\Helpers\BackupEncryption::ENCRYPTION_DEFAULT, // Available encryption methods: // \App\Helpers\BackupEncryption::ENCRYPTION_DEFAULT (PHP < 7.2: PKWARE/ZipCrypto, PHP >= 7.2: AES 128)