Replace magic facades

This commit is contained in:
James Cole
2025-05-24 17:15:46 +02:00
parent e333dedeec
commit b830bd2732
14 changed files with 38 additions and 23 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Rules\UniqueIban; use FireflyIII\Rules\UniqueIban;
use FireflyIII\Services\Internal\Update\AccountUpdateService; use FireflyIII\Services\Internal\Update\AccountUpdateService;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Validator;
/** /**
* Class TransactionFactory * Class TransactionFactory
@@ -152,7 +153,7 @@ class TransactionFactory
return; return;
} }
// validate info: // validate info:
$validator = \Validator::make(['iban' => $this->accountInformation['iban']], [ $validator = Validator::make(['iban' => $this->accountInformation['iban']], [
'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)], 'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)],
]); ]);
if ($validator->fails()) { if ($validator->fails()) {

View File

@@ -54,6 +54,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Auth\Events\Login; use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Mail; use Mail;
@@ -266,7 +267,7 @@ class UserEventHandler
$url = route('profile.confirm-email-change', [$token->data]); $url = route('profile.confirm-email-change', [$token->data]);
try { try {
\Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url)); Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url));
} catch (\Exception $e) { } catch (\Exception $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());
@@ -291,7 +292,7 @@ class UserEventHandler
$url = route('profile.undo-email-change', [$token->data, $hashed]); $url = route('profile.undo-email-change', [$token->data, $hashed]);
try { try {
\Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url)); Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url));
} catch (\Exception $e) { } catch (\Exception $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());
@@ -355,7 +356,7 @@ class UserEventHandler
$url = route('invite', [$event->invitee->invite_code]); $url = route('invite', [$event->invitee->invite_code]);
try { try {
\Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url)); Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url));
} catch (\Exception $e) { } catch (\Exception $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());

View File

@@ -28,6 +28,7 @@ use Illuminate\Mail\Message;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Symfony\Component\Mailer\Exception\TransportException; use Symfony\Component\Mailer\Exception\TransportException;
/** /**
@@ -70,7 +71,7 @@ class MailError extends Job implements ShouldQueue
if ($this->attempts() < 3 && '' !== $email) { if ($this->attempts() < 3 && '' !== $email) {
try { try {
\Mail::send( Mail::send(
['emails.error-html', 'emails.error-text'], ['emails.error-html', 'emails.error-text'],
$args, $args,
static function (Message $message) use ($email): void { static function (Message $message) use ($email): void {

View File

@@ -59,7 +59,7 @@ class AppServiceProvider extends ServiceProvider
// blade extension // blade extension
Blade::directive('activeXRoutePartial', function (string $route) { Blade::directive('activeXRoutePartial', function (string $route) {
$name = \Route::getCurrentRoute()->getName() ?? ''; $name = Route::getCurrentRoute()->getName() ?? '';
if (str_contains($name, $route)) { if (str_contains($name, $route)) {
return 'menu-open'; return 'menu-open';
} }

View File

@@ -39,6 +39,7 @@ use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService; use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
use Illuminate\Support\Facades\Validator;
/** /**
* Trait AccountServiceTrait * Trait AccountServiceTrait
@@ -54,7 +55,7 @@ trait AccountServiceTrait
} }
$data = ['iban' => $iban]; $data = ['iban' => $iban];
$rules = ['iban' => 'required|iban']; $rules = ['iban' => 'required|iban'];
$validator = \Validator::make($data, $rules); $validator = Validator::make($data, $rules);
if ($validator->fails()) { if ($validator->fails()) {
app('log')->info(sprintf('Detected invalid IBAN ("%s"). Return NULL instead.', $iban)); app('log')->info(sprintf('Detected invalid IBAN ("%s"). Return NULL instead.', $iban));

View File

@@ -28,6 +28,7 @@ use FireflyIII\Models\Configuration;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Contracts\Encryption\EncryptException; use Illuminate\Contracts\Encryption\EncryptException;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/** /**
@@ -38,8 +39,8 @@ class FireflyConfig
public function delete(string $name): void public function delete(string $name): void
{ {
$fullName = 'ff-config-'.$name; $fullName = 'ff-config-'.$name;
if (\Cache::has($fullName)) { if (Cache::has($fullName)) {
\Cache::forget($fullName); Cache::forget($fullName);
} }
Configuration::where('name', $name)->forceDelete(); Configuration::where('name', $name)->forceDelete();
} }
@@ -80,8 +81,8 @@ class FireflyConfig
public function get(string $name, mixed $default = null): ?Configuration public function get(string $name, mixed $default = null): ?Configuration
{ {
$fullName = 'ff-config-'.$name; $fullName = 'ff-config-'.$name;
if (\Cache::has($fullName)) { if (Cache::has($fullName)) {
return \Cache::get($fullName); return Cache::get($fullName);
} }
try { try {
@@ -92,7 +93,7 @@ class FireflyConfig
} }
if (null !== $config) { if (null !== $config) {
\Cache::forever($fullName, $config); Cache::forever($fullName, $config);
return $config; return $config;
} }
@@ -122,13 +123,13 @@ class FireflyConfig
$item->name = $name; $item->name = $name;
$item->data = $value; $item->data = $value;
$item->save(); $item->save();
\Cache::forget('ff-config-'.$name); Cache::forget('ff3-config-'.$name);
return $item; return $item;
} }
$config->data = $value; $config->data = $value;
$config->save(); $config->save();
\Cache::forget('ff-config-'.$name); Cache::forget('ff3-config-'.$name);
return $config; return $config;
} }

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Support\System;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Laravel\Passport\Console\KeysCommand; use Laravel\Passport\Console\KeysCommand;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
@@ -88,8 +89,8 @@ class OAuthKeys
public static function generateKeys(): void public static function generateKeys(): void
{ {
\Artisan::registerCommand(new KeysCommand()); Artisan::registerCommand(new KeysCommand());
\Artisan::call('firefly-iii:laravel-passport-keys'); Artisan::call('firefly-iii:laravel-passport-keys');
} }
public static function storeKeysInDB(): void public static function storeKeysInDB(): void

View File

@@ -247,7 +247,7 @@ class General extends AbstractExtension
static function (): string { static function (): string {
$args = func_get_args(); $args = func_get_args();
$route = $args[0]; // name of the route. $route = $args[0]; // name of the route.
$name = \Route::getCurrentRoute()->getName() ?? ''; $name = Route::getCurrentRoute()->getName() ?? '';
if (str_contains($name, $route)) { if (str_contains($name, $route)) {
return 'active'; return 'active';
} }
@@ -271,7 +271,7 @@ class General extends AbstractExtension
if ($objectType === $activeObjectType if ($objectType === $activeObjectType
&& false !== stripos( && false !== stripos(
(string) \Route::getCurrentRoute()->getName(), (string) Route::getCurrentRoute()->getName(),
(string) $route (string) $route
)) { )) {
return 'active'; return 'active';
@@ -294,7 +294,7 @@ class General extends AbstractExtension
static function (): string { static function (): string {
$args = func_get_args(); $args = func_get_args();
$route = $args[0]; // name of the route. $route = $args[0]; // name of the route.
$name = \Route::getCurrentRoute()->getName() ?? ''; $name = Route::getCurrentRoute()->getName() ?? '';
if (str_contains($name, $route)) { if (str_contains($name, $route)) {
return 'menu-open'; return 'menu-open';
} }

View File

@@ -61,6 +61,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Laravel\Passport\HasApiTokens; use Laravel\Passport\HasApiTokens;
use NotificationChannels\Pushover\PushoverReceiver; use NotificationChannels\Pushover\PushoverReceiver;
@@ -464,7 +465,7 @@ class User extends Authenticatable
*/ */
public function sendPasswordResetNotification($token): void public function sendPasswordResetNotification($token): void
{ {
$ipAddress = \Request::ip(); $ipAddress = Request::ip();
event(new RequestedNewPassword($this, $token, $ipAddress)); event(new RequestedNewPassword($this, $token, $ipAddress));
} }

View File

@@ -44,6 +44,7 @@ use Illuminate\Validation\Validator;
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
use PragmaRX\Google2FALaravel\Facade;
/** /**
* Class FireflyValidator. * Class FireflyValidator.
@@ -79,7 +80,7 @@ class FireflyValidator extends Validator
} }
$secret = (string) $secret; $secret = (string) $secret;
return (bool) \Google2FA::verifyKey($secret, $value); return (bool) Facade::verifyKey($secret, $value);
} }
/** /**
@@ -131,7 +132,7 @@ class FireflyValidator extends Validator
} }
$secret = (string) $user->mfa_secret; $secret = (string) $user->mfa_secret;
return (bool) \Google2FA::verifyKey($secret, $value); return (bool) Facade::verifyKey($secret, $value);
} }
/** /**

View File

@@ -22,6 +22,8 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Support\Facades\Route;
// Cron job API routes: // Cron job API routes:
use FireflyIII\Http\Middleware\AcceptHeaders; use FireflyIII\Http\Middleware\AcceptHeaders;

View File

@@ -22,6 +22,8 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Support\Facades\Route;
/* /*
* *
* ____ ____ ___ .______ ______ __ __ .___________. _______ _______. * ____ ____ ___ .______ ______ __ __ .___________. _______ _______.

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Support\Facades\Broadcast;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Broadcast Channels | Broadcast Channels

View File

@@ -19,9 +19,11 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Support\Facades\Route;
if (!defined('DATEFORMAT')) { if (!defined('DATEFORMAT')) {
define('DATEFORMAT', '(19|20)[0-9]{2}-?[0-9]{2}-?[0-9]{2}'); define('DATEFORMAT', '(19|20)[0-9]{2}-?[0-9]{2}-?[0-9]{2}');
} }