diff --git a/app/Console/Commands/Integrity/ValidatesEnvironmentVariables.php b/app/Console/Commands/Integrity/ValidatesEnvironmentVariables.php index aceaa211be..197bf95a5f 100644 --- a/app/Console/Commands/Integrity/ValidatesEnvironmentVariables.php +++ b/app/Console/Commands/Integrity/ValidatesEnvironmentVariables.php @@ -42,32 +42,41 @@ class ValidatesEnvironmentVariables extends Command * * @var string */ - protected $signature = 'integrity:validates-environment-variables'; + protected $signature = 'integrity:validates-environment-variables'; /** * Execute the console command. */ public function handle(): int { - $this->validateLanguage(); - $this->validateGuard(); - $this->validateStaticToken(); + $result = $this->validateLanguage(); + if (false === $result) { + return Command::FAILURE; + } + $result = $this->validateGuard(); + if (false === $result) { + return Command::FAILURE; + } + $result = $this->validateStaticToken(); + if (false === $result) { + return Command::FAILURE; + } return Command::SUCCESS; } - private function validateLanguage(): void + private function validateLanguage(): bool { - $language = config('firefly.default_language'); - $locale = config('firefly.default_locale'); - $options = array_keys(config('firefly.languages')); + $language = config('firefly.default_language'); + $locale = config('firefly.default_locale'); + $options = array_keys(config('firefly.languages')); if (!in_array($language, $options, true)) { $this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language)); $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options))); - exit(1); + return false; } $options[] = 'equal'; if (!in_array($locale, $options, true)) { @@ -75,30 +84,31 @@ class ValidatesEnvironmentVariables extends Command $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options))); - exit(1); + return false; } + return true; } - private function validateGuard(): void + private function validateGuard(): bool { $guard = config('auth.defaults.guard'); if ('web' !== $guard && 'remote_user_guard' !== $guard) { $this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard)); $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Valid guards are: web, remote_user_guard'); - - exit(1); + return false; } + return true; } - private function validateStaticToken(): void + private function validateStaticToken(): bool { - $token = (string) config('firefly.static_cron_token'); + $token = (string)config('firefly.static_cron_token'); if ('' !== $token && 32 !== strlen($token)) { $this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); - - exit(1); + return false; } + return true; } } diff --git a/app/Console/Commands/System/ScansAttachments.php b/app/Console/Commands/System/ScansAttachments.php index 6597025bcd..dc889776ff 100644 --- a/app/Console/Commands/System/ScansAttachments.php +++ b/app/Console/Commands/System/ScansAttachments.php @@ -29,12 +29,15 @@ use FireflyIII\Models\Attachment; use Illuminate\Console\Command; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Facades\Crypt; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; - -use function Safe\tempnam; +use Safe\Exceptions\FileinfoException; +use Safe\Exceptions\FilesystemException; +use Safe\Exceptions\StringsException; use function Safe\file_put_contents; use function Safe\md5_file; use function Safe\mime_content_type; +use function Safe\tempnam; class ScansAttachments extends Command { @@ -42,10 +45,13 @@ class ScansAttachments extends Command protected $description = 'Rescan all attachments and re-set the correct MD5 hash and mime.'; - protected $signature = 'firefly-iii:scan-attachments'; + protected $signature = 'firefly-iii:scan-attachments'; /** * Execute the console command. + * @throws FilesystemException + * @throws StringsException + * @throws FileinfoException */ public function handle(): int { @@ -57,7 +63,7 @@ class ScansAttachments extends Command $fileName = $attachment->fileName(); $encryptedContent = $disk->get($fileName); if (null === $encryptedContent) { - app('log')->error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName)); + Log::error(sprintf('No content for attachment #%d under filename "%s"', $attachment->id, $fileName)); continue; } @@ -65,18 +71,13 @@ class ScansAttachments extends Command try { $decryptedContent = Crypt::decrypt($encryptedContent); // verified } catch (DecryptException $e) { - app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage())); + Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage())); $decryptedContent = $encryptedContent; } - $tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII'); - if (false === $tempFileName) { - app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id)); - - exit(1); - } + $tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII'); file_put_contents($tempFileName, $decryptedContent); - $attachment->md5 = (string) md5_file($tempFileName); - $attachment->mime = (string) mime_content_type($tempFileName); + $attachment->md5 = (string)md5_file($tempFileName); + $attachment->mime = (string)mime_content_type($tempFileName); $attachment->save(); $this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id)); } diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 0e05e5d7c0..b402554570 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -835,11 +835,9 @@ class GroupCollector implements GroupCollectorInterface if (count($product['transactions']) > 1) { return $product['title']; } - return 'zzz'; } - - exit('here we are 2'); + return 'zzz'; }); } diff --git a/app/Support/Request/GetFilterInstructions.php b/app/Support/Request/GetFilterInstructions.php index a8c19dccc4..cd8c68b568 100644 --- a/app/Support/Request/GetFilterInstructions.php +++ b/app/Support/Request/GetFilterInstructions.php @@ -24,10 +24,15 @@ declare(strict_types=1); namespace FireflyIII\Support\Request; +use FireflyIII\Exceptions\FireflyException; + trait GetFilterInstructions { private const string INVALID_FILTER = '%INVALID_JAMES_%'; + /** + * @throws FireflyException + */ final public function getFilterInstructions(string $key): array { $config = config(sprintf('firefly.filters.allowed.%s', $key)); @@ -48,7 +53,7 @@ trait GetFilterInstructions switch ($filterType) { default: - exit(sprintf('Do not support filter type "%s"', $filterType)); + throw new FireflyException(sprintf('Do not support filter type "%s"', $filterType)); case 'boolean': $filterValue = $this->booleanInstruction($filterValue);