diff --git a/app/Http/Controllers/Account/DeleteController.php b/app/Http/Controllers/Account/DeleteController.php index 41a5cc1f59..09ac8cff5e 100644 --- a/app/Http/Controllers/Account/DeleteController.php +++ b/app/Http/Controllers/Account/DeleteController.php @@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Account; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -38,8 +37,6 @@ use Illuminate\View\View; */ class DeleteController extends Controller { - use UserNavigation; - /** @var AccountRepositoryInterface The account repository */ private $repository; diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index afa92d88eb..cfbc085ce1 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -30,7 +30,6 @@ use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\ModelInformation; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -43,7 +42,7 @@ use Illuminate\View\View; */ class EditController extends Controller { - use ModelInformation, UserNavigation; + use ModelInformation; private AttachmentHelperInterface $attachments; /** @var CurrencyRepositoryInterface The currency repository */ diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 112273fef4..5ccb8543d5 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -36,7 +36,6 @@ use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; -use FireflyIII\Support\Http\Controllers\UserNavigation; use FireflyIII\User; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; @@ -49,8 +48,6 @@ use Log; */ class ReconcileController extends Controller { - use UserNavigation; - /** @var AccountRepositoryInterface The account repository */ private $accountRepos; /** @var CurrencyRepositoryInterface The currency repository */ diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 6d25d3bb49..2b10139176 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -31,7 +31,6 @@ use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -45,7 +44,7 @@ use Illuminate\View\View; */ class ShowController extends Controller { - use UserNavigation, PeriodOverview; + use PeriodOverview; private CurrencyRepositoryInterface $currencyRepos; private AccountRepositoryInterface $repository; diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index e8fb8a4b97..47a5f37fd4 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -39,6 +39,7 @@ use Illuminate\View\View; */ class AttachmentController extends Controller { + /** @var AttachmentRepositoryInterface Attachment repository */ private $repository; diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 4f669d4c7b..9a0f946d97 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -27,7 +27,6 @@ use FireflyIII\Events\RegisteredUser; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Http\Controllers\CreateStuff; -use FireflyIII\Support\Http\Controllers\RequestInformation; use FireflyIII\User; use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\RegistersUsers; @@ -48,7 +47,7 @@ use Log; */ class RegisterController extends Controller { - use RegistersUsers, RequestInformation, CreateStuff; + use RegistersUsers, CreateStuff; /** * Where to redirect users after registration. diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index a146dc199c..b176c3d2c0 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -46,7 +46,7 @@ class ShowController extends Controller { use PeriodOverview, AugumentData; - private JournalRepositoryInterface $journalRepos; + protected JournalRepositoryInterface $journalRepos; private BudgetRepositoryInterface $repository; /** diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php index 5360245aba..9ae41cebb2 100644 --- a/app/Http/Controllers/Category/NoCategoryController.php +++ b/app/Http/Controllers/Category/NoCategoryController.php @@ -43,8 +43,7 @@ class NoCategoryController extends Controller { use PeriodOverview; - /** @var JournalRepositoryInterface Journals and transactions overview */ - private $journalRepos; + protected JournalRepositoryInterface $journalRepos; /** * CategoryController constructor. diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 6d3bbedf34..e581bdcc1c 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -36,15 +36,11 @@ use Route; */ abstract class Controller extends BaseController { - use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation, RequestInformation; + use AuthorizesRequests, DispatchesJobs, ValidatesRequests, RequestInformation, UserNavigation; - /** @var string Format for date and time. */ protected string $dateTimeFormat; - /** @var string Format for "23 Feb, 2016". */ protected string $monthAndDayFormat; - /** @var string Format for "March 2018" */ protected string $monthFormat; - /** @var string Redirect user */ protected string $redirectUri = '/'; /** diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php index f219ade592..1d3b6bdedb 100644 --- a/app/Http/Controllers/HelpController.php +++ b/app/Http/Controllers/HelpController.php @@ -22,7 +22,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; -use FireflyIII\Support\Http\Controllers\RequestInformation; use Illuminate\Http\JsonResponse; /** @@ -30,8 +29,6 @@ use Illuminate\Http\JsonResponse; */ class HelpController extends Controller { - use RequestInformation; - /** * Show help for a route. * diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 5de2c2d2a2..ebaf03c2de 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -36,7 +36,6 @@ use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\CacheProperties; -use FireflyIII\Support\Http\Controllers\RequestInformation; use Illuminate\Http\JsonResponse; use Log; @@ -45,8 +44,6 @@ use Log; */ class BoxController extends Controller { - use RequestInformation; - /** * This box has three types of info to display: * 0) If the user has available amount this period and has overspent: overspent box. diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php index 1f28f3a82a..c9ff62b25b 100644 --- a/app/Http/Controllers/Json/IntroController.php +++ b/app/Http/Controllers/Json/IntroController.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Http\Controllers\GetConfigurationData; use Illuminate\Http\JsonResponse; use Log; @@ -29,7 +30,7 @@ use Log; /** * Class IntroController. */ -class IntroController +class IntroController extends Controller { use GetConfigurationData; diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index 1aabc1a206..5bc1a296f1 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -32,7 +32,6 @@ use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; @@ -45,8 +44,6 @@ use Throwable; */ class ReconcileController extends Controller { - use UserNavigation; - private AccountRepositoryInterface $accountRepos; private CurrencyRepositoryInterface $currencyRepos; private JournalRepositoryInterface $repository; diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index 9cb593ce9b..b6089d1976 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -24,7 +24,6 @@ namespace FireflyIII\Http\Controllers\Popup; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Http\Controllers\RenderPartialViews; -use FireflyIII\Support\Http\Controllers\RequestInformation; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -34,7 +33,7 @@ use Illuminate\Http\Request; */ class ReportController extends Controller { - use RequestInformation, RenderPartialViews; + use RenderPartialViews; /** * Generate popup view. diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index b38955156b..5d09146c0c 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -35,7 +35,6 @@ use FireflyIII\Http\Requests\TokenFormRequest; use FireflyIII\Models\Preference; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Support\Http\Controllers\CreateStuff; -use FireflyIII\Support\Http\Controllers\RequestInformation; use FireflyIII\User; use Google2FA; use Hash; @@ -58,7 +57,7 @@ use PragmaRX\Recovery\Recovery; */ class ProfileController extends Controller { - use RequestInformation, CreateStuff; + use CreateStuff; protected bool $internalAuth; protected bool $internalIdentity; @@ -74,7 +73,7 @@ class ProfileController extends Controller $this->middleware( static function ($request, $next) { - app('view')->share('title', (string) trans('firefly.profile')); + app('view')->share('title', (string)trans('firefly.profile')); app('view')->share('mainTitleIcon', 'fa-user'); return $next($request); @@ -95,9 +94,11 @@ class ProfileController extends Controller public function logoutOtherSessions() { if (!$this->internalAuth) { - session()->flash('info', (string) trans('firefly.external_auth_disabled')); + session()->flash('info', (string)trans('firefly.external_auth_disabled')); + return redirect(route('profile.index')); } + return prefixView('profile.logout-other-sessions'); } @@ -109,7 +110,8 @@ class ProfileController extends Controller public function postLogoutOtherSessions(Request $request) { if (!$this->internalAuth) { - session()->flash('info', (string) trans('firefly.external_auth_disabled')); + session()->flash('info', (string)trans('firefly.external_auth_disabled')); + return redirect(route('profile.index')); } $creds = [ @@ -118,11 +120,11 @@ class ProfileController extends Controller ]; if (Auth::once($creds)) { Auth::logoutOtherDevices($request->get('password')); - session()->flash('info', (string) trans('firefly.other_sessions_logged_out')); + session()->flash('info', (string)trans('firefly.other_sessions_logged_out')); return redirect(route('profile.index')); } - session()->flash('error', (string) trans('auth.failed')); + session()->flash('error', (string)trans('auth.failed')); return redirect(route('profile.index')); @@ -145,7 +147,7 @@ class ProfileController extends Controller $title = auth()->user()->email; $email = auth()->user()->email; - $subTitle = (string) trans('firefly.change_your_email'); + $subTitle = (string)trans('firefly.change_your_email'); $subTitleIcon = 'fa-envelope'; return prefixView('profile.change-email', compact('title', 'subTitle', 'subTitleIcon', 'email')); @@ -167,7 +169,7 @@ class ProfileController extends Controller } $title = auth()->user()->email; - $subTitle = (string) trans('firefly.change_your_password'); + $subTitle = (string)trans('firefly.change_your_password'); $subTitleIcon = 'fa-key'; return prefixView('profile.change-password', compact('title', 'subTitle', 'subTitleIcon')); @@ -260,7 +262,7 @@ class ProfileController extends Controller $repository->unblockUser($user); // return to login. - session()->flash('success', (string) trans('firefly.login_with_new_email')); + session()->flash('success', (string)trans('firefly.login_with_new_email')); return redirect(route('login')); } @@ -280,7 +282,7 @@ class ProfileController extends Controller return redirect(route('profile.index')); } $title = auth()->user()->email; - $subTitle = (string) trans('firefly.delete_account'); + $subTitle = (string)trans('firefly.delete_account'); $subTitleIcon = 'fa-trash'; return prefixView('profile.delete-account', compact('title', 'subTitle', 'subTitleIcon')); @@ -305,8 +307,8 @@ class ProfileController extends Controller $user = auth()->user(); $repository->setMFACode($user, null); - session()->flash('success', (string) trans('firefly.pref_two_factor_auth_disabled')); - session()->flash('info', (string) trans('firefly.pref_two_factor_auth_remove_it')); + session()->flash('success', (string)trans('firefly.pref_two_factor_auth_disabled')); + session()->flash('info', (string)trans('firefly.pref_two_factor_auth_remove_it')); return redirect(route('profile.index')); } @@ -335,7 +337,7 @@ class ProfileController extends Controller // If FF3 already has a secret, just set the two factor auth enabled to 1, // and let the user continue with the existing secret. - session()->flash('info', (string) trans('firefly.2fa_already_enabled')); + session()->flash('info', (string)trans('firefly.2fa_already_enabled')); return redirect(route('profile.index')); } @@ -370,7 +372,9 @@ class ProfileController extends Controller $accessToken = app('preferences')->set('access_token', $token); } - return prefixView('profile.index', compact('subTitle', 'mfaBackupCount', 'userId', 'accessToken', 'enabled2FA', 'isInternalAuth','isInternalIdentity')); + return prefixView( + 'profile.index', compact('subTitle', 'mfaBackupCount', 'userId', 'accessToken', 'enabled2FA', 'isInternalAuth', 'isInternalIdentity') + ); } /** @@ -420,7 +424,7 @@ class ProfileController extends Controller $newEmail = $request->string('email'); $oldEmail = $user->email; if ($newEmail === $user->email) { - session()->flash('error', (string) trans('firefly.email_not_changed')); + session()->flash('error', (string)trans('firefly.email_not_changed')); return redirect(route('profile.change-email'))->withInput(); } @@ -430,7 +434,7 @@ class ProfileController extends Controller Auth::guard()->logout(); $request->session()->invalidate(); - session()->flash('success', (string) trans('firefly.email_changed')); + session()->flash('success', (string)trans('firefly.email_changed')); return redirect(route('index')); } @@ -445,7 +449,7 @@ class ProfileController extends Controller // force user logout. Auth::guard()->logout(); $request->session()->invalidate(); - session()->flash('success', (string) trans('firefly.email_changed')); + session()->flash('success', (string)trans('firefly.email_changed')); return redirect(route('index')); } @@ -480,7 +484,7 @@ class ProfileController extends Controller } $repository->changePassword($user, $request->get('new_password')); - session()->flash('success', (string) trans('firefly.password_changed')); + session()->flash('success', (string)trans('firefly.password_changed')); return redirect(route('profile.index')); } @@ -509,7 +513,7 @@ class ProfileController extends Controller $secret = session()->get('two-factor-secret'); $repository->setMFACode($user, $secret); - session()->flash('success', (string) trans('firefly.saved_preferences')); + session()->flash('success', (string)trans('firefly.saved_preferences')); app('preferences')->mark(); // also save the code so replay attack is prevented. @@ -547,7 +551,7 @@ class ProfileController extends Controller } if (!Hash::check($request->get('password'), auth()->user()->password)) { - session()->flash('error', (string) trans('firefly.invalid_password')); + session()->flash('error', (string)trans('firefly.invalid_password')); return redirect(route('profile.delete-account')); } @@ -579,7 +583,7 @@ class ProfileController extends Controller $user = auth()->user(); $token = $user->generateAccessToken(); app('preferences')->set('access_token', $token); - session()->flash('success', (string) trans('firefly.token_regenerated')); + session()->flash('success', (string)trans('firefly.token_regenerated')); return redirect(route('profile.index')); } @@ -619,7 +623,7 @@ class ProfileController extends Controller /** @var string $match */ $match = null; foreach ($set as $entry) { - $hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $entry->data)); + $hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $entry->data)); if ($hashed === $hash) { $match = $entry->data; break; @@ -634,7 +638,7 @@ class ProfileController extends Controller $repository->unblockUser($user); // return to login. - session()->flash('success', (string) trans('firefly.login_with_old_email')); + session()->flash('success', (string)trans('firefly.login_with_old_email')); return redirect(route('login')); } diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index 4299fce5e3..4872b52db7 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -29,7 +29,6 @@ use FireflyIII\Http\Requests\SelectTransactionsRequest; use FireflyIII\Http\Requests\TestRuleFormRequest; use FireflyIII\Models\Rule; use FireflyIII\Models\RuleTrigger; -use FireflyIII\Support\Http\Controllers\RequestInformation; use FireflyIII\Support\Http\Controllers\RuleManagement; use FireflyIII\TransactionRules\Engine\RuleEngineInterface; use FireflyIII\TransactionRules\TransactionMatcher; @@ -48,7 +47,7 @@ use Throwable; */ class SelectController extends Controller { - use RuleManagement, RequestInformation; + use RuleManagement; /** * RuleController constructor. diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 50a55fc699..4f4242c9db 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -218,7 +218,7 @@ class InstallController extends Controller public function keys(): void { // switch on PHP version. - + $keys = []; // switch on class existence. Log::info(sprintf('PHP version is %s', phpversion())); if (class_exists(LegacyRSA::class)) { @@ -242,7 +242,7 @@ class InstallController extends Controller return; } - file_put_contents($publicKey, Arr::get($keys, 'publickey')); - file_put_contents($privateKey, Arr::get($keys, 'privatekey')); + file_put_contents($publicKey, $keys['publickey']); + file_put_contents($privateKey, $keys['privatekey']); } } diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index d7ddfbd8f6..4c513d5c4b 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -35,7 +35,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Services\Internal\Update\JournalUpdateService; use FireflyIII\Support\Http\Controllers\ModelInformation; -use FireflyIII\Support\Http\Controllers\UserNavigation; use FireflyIII\Transformers\TransactionGroupTransformer; use FireflyIII\Validation\AccountValidator; use Illuminate\Contracts\View\Factory; @@ -52,7 +51,7 @@ use Log; */ class ConvertController extends Controller { - use ModelInformation, UserNavigation; + use ModelInformation; private AccountRepositoryInterface $accountRepository; private JournalRepositoryInterface $repository; diff --git a/app/Http/Controllers/Transaction/DeleteController.php b/app/Http/Controllers/Transaction/DeleteController.php index 0c8ca3785a..348c2bf266 100644 --- a/app/Http/Controllers/Transaction/DeleteController.php +++ b/app/Http/Controllers/Transaction/DeleteController.php @@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Transaction; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionGroup; use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; use Log; @@ -38,8 +37,6 @@ use URL; */ class DeleteController extends Controller { - use UserNavigation; - /** @var TransactionGroupRepositoryInterface */ private $repository; diff --git a/app/Http/Controllers/Transaction/EditController.php b/app/Http/Controllers/Transaction/EditController.php index 4c5657ed80..8b54d047e1 100644 --- a/app/Http/Controllers/Transaction/EditController.php +++ b/app/Http/Controllers/Transaction/EditController.php @@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Transaction; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionGroup; use FireflyIII\Repositories\Account\AccountRepositoryInterface; -use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; @@ -37,8 +36,6 @@ use Illuminate\View\View; */ class EditController extends Controller { - use UserNavigation; - /** * EditController constructor. * diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 2c78ab3d9b..77362eeb6d 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -40,6 +40,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property \Illuminate\Support\Carbon $start_date * @property \Illuminate\Support\Carbon|null $end_date * @property string $amount + * @property string $spent * @property string|null $period * @property int $generated * @property-read \FireflyIII\Models\Budget $budget diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 922caf3382..53c0a39d18 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -41,19 +41,19 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * FireflyIII\Models\TransactionJournal * * @property int $id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property \Illuminate\Support\Carbon|null $deleted_at + * @property \Carbon\Carbon|null $created_at + * @property \Carbon\Carbon|null $updated_at + * @property \Carbon\Carbon|null $deleted_at * @property int $user_id * @property int $transaction_type_id * @property int|null $transaction_group_id * @property int|null $bill_id * @property int|null $transaction_currency_id * @property string $description - * @property \Illuminate\Support\Carbon $date - * @property \Illuminate\Support\Carbon|null $interest_date - * @property \Illuminate\Support\Carbon|null $book_date - * @property \Illuminate\Support\Carbon|null $process_date + * @property \Carbon\Carbon $date + * @property \Carbon\Carbon|null $interest_date + * @property \Carbon\Carbon|null $book_date + * @property \Carbon\Carbon|null $process_date * @property int $order * @property int $tag_count * @property bool $encrypted diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php index 53a79d8e67..09ca4f9833 100644 --- a/app/Services/Internal/Update/AccountUpdateService.php +++ b/app/Services/Internal/Update/AccountUpdateService.php @@ -51,12 +51,11 @@ class AccountUpdateService */ public function __construct() { - // TODO move to configuration. - $this->canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]; + $this->canHaveVirtual = config('firefly.can_have_virtual_amounts'); + $this->validAssetFields = config('firefly.valid_asset_fields'); + $this->validCCFields = config('firefly.valid_cc_fields'); + $this->validFields = config('firefly.valid_account_fields'); $this->accountRepository = app(AccountRepositoryInterface::class); - $this->validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; - $this->validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth']; - $this->validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth']; } /** @@ -100,7 +99,7 @@ class AccountUpdateService $this->updateOpeningBalance($account, $data); // update note: - if (isset($data['notes']) && null !== $data['notes']) { + if (array_key_exists('notes', $data) && null !== $data['notes']) { $this->updateNote($account, (string)$data['notes']); } diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php index 48616fd059..c1a1cc1ffb 100644 --- a/app/Services/Internal/Update/BillUpdateService.php +++ b/app/Services/Internal/Update/BillUpdateService.php @@ -144,20 +144,20 @@ class BillUpdateService */ private function updateBillProperties(Bill $bill, array $data): Bill { - if (isset($data['name']) && '' !== (string)$data['name']) { + if (array_key_exists('name', $data) && '' !== (string)$data['name']) { $bill->name = $data['name']; } - if (isset($data['amount_min']) && '' !== (string)$data['amount_min']) { + if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) { $bill->amount_min = $data['amount_min']; } - if (isset($data['amount_max']) && '' !== (string)$data['amount_max']) { + if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) { $bill->amount_max = $data['amount_max']; } - if (isset($data['date']) && '' !== (string)$data['date']) { + if (array_key_exists('date', $data) && '' !== (string)$data['date']) { $bill->date = $data['date']; } - if (isset($data['repeat_freq']) && '' !== (string)$data['repeat_freq']) { + if (array_key_exists('repeat_freq', $data) && '' !== (string)$data['repeat_freq']) { $bill->repeat_freq = $data['repeat_freq']; } if (array_key_exists('skip', $data)) { diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php index c3e96764f6..d6322a845c 100644 --- a/app/Services/Internal/Update/CategoryUpdateService.php +++ b/app/Services/Internal/Update/CategoryUpdateService.php @@ -154,7 +154,7 @@ class CategoryUpdateService try { $dbNote->delete(); } catch (Exception $e) { - Log::debug($e->getMessage()); + // @ignoreException } } diff --git a/app/Services/Internal/Update/GroupUpdateService.php b/app/Services/Internal/Update/GroupUpdateService.php index 0c7bf27885..3146eea33b 100644 --- a/app/Services/Internal/Update/GroupUpdateService.php +++ b/app/Services/Internal/Update/GroupUpdateService.php @@ -130,15 +130,15 @@ class GroupUpdateService foreach ($transactions as $index => $transaction) { Log::debug(sprintf('Now at #%d of %d', ($index + 1), count($transactions)), $transaction); $journalId = (int)($transaction['transaction_journal_id'] ?? 0); - /** @var TransactionJournal $journal */ + /** @var TransactionJournal|null $journal */ $journal = $transactionGroup->transactionJournals()->find($journalId); if (null === $journal) { Log::debug('This entry has no existing journal: make a new split.'); // force the transaction type on the transaction data. // by plucking it from another journal in the group: - if (!isset($transaction['type'])) { + if (!array_key_exists('type', $transaction)) { Log::debug('No transaction type is indicated.'); - /** @var TransactionJournal $randomJournal */ + /** @var TransactionJournal|null $randomJournal */ $randomJournal = $transactionGroup->transactionJournals()->inRandomOrder()->with(['transactionType'])->first(); if (null !== $randomJournal) { $transaction['type'] = $randomJournal->transactionType->type; @@ -182,7 +182,7 @@ class GroupUpdateService } catch (FireflyException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); - throw new FireflyException(sprintf('Could not create new transaction journal: %s', $e->getMessage())); + throw new FireflyException(sprintf('Could not create new transaction journal: %s', $e->getMessage()), 0, $e); } $collection->each( function (TransactionJournal $journal) use ($transactionGroup) { diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php index 3203bd3796..3a285c2c21 100644 --- a/app/Services/Internal/Update/JournalUpdateService.php +++ b/app/Services/Internal/Update/JournalUpdateService.php @@ -616,7 +616,7 @@ class JournalUpdateService if ($this->hasFields([$field])) { try { $value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]); - } catch (Exception $e) { + } catch (Exception $e) { // @phpstan-ignore-line Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage())); return; diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index b7370de5e2..cc6a3cfc40 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -133,11 +133,10 @@ class RecurrenceUpdateService if (null !== $dbNote && '' === $text) { try { $dbNote->delete(); - } catch (Exception $e) { - Log::debug(sprintf('Could not delete note: %s', $e->getMessage())); + } catch (Exception $e) { // @phpstan-ignore-line + // @ignoreException } } - } /** @@ -252,7 +251,7 @@ class RecurrenceUpdateService $currency = $currencyFactory->find($current['currency_id'] ?? null, $currency['currency_code'] ?? null); } if (null === $currency) { - unset($current['currency_id'], $currency['currency_code']); + unset($current['currency_id'], $current['currency_code']); } if (null !== $currency) { $current['currency_id'] = (int)$currency->id; diff --git a/app/Services/Password/PwndVerifierV2.php b/app/Services/Password/PwndVerifierV2.php index 8566ba7dbf..6ebdae729b 100644 --- a/app/Services/Password/PwndVerifierV2.php +++ b/app/Services/Password/PwndVerifierV2.php @@ -22,9 +22,9 @@ declare(strict_types=1); namespace FireflyIII\Services\Password; -use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Exception\RequestException; use Log; use RuntimeException; @@ -51,7 +51,7 @@ class PwndVerifierV2 implements Verifier $uri = sprintf('https://api.pwnedpasswords.com/range/%s', $prefix); $opt = [ 'headers' => [ - 'User-Agent' => 'Firefly III v' . config('firefly.version'), + 'User-Agent' => sprintf('Firefly III v%s', config('firefly.version')), 'Add-Padding' => 'true', ], 'timeout' => 3.1415]; @@ -62,7 +62,7 @@ class PwndVerifierV2 implements Verifier try { $client = new Client(); $res = $client->request('GET', $uri, $opt); - } catch (GuzzleException | Exception $e) { + } catch (GuzzleException | RequestException $e) { Log::error(sprintf('Could not verify password security: %s', $e->getMessage())); return true; @@ -73,7 +73,7 @@ class PwndVerifierV2 implements Verifier } try { $strpos = stripos($res->getBody()->getContents(), $rest); - } catch (RuntimeException $e) { + } catch (RuntimeException $e) { // @phpstan-ignore-line Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage())); $strpos = false; } diff --git a/app/Services/Webhook/StandardWebhookSender.php b/app/Services/Webhook/StandardWebhookSender.php index 90035f6b31..a877d4a355 100644 --- a/app/Services/Webhook/StandardWebhookSender.php +++ b/app/Services/Webhook/StandardWebhookSender.php @@ -23,12 +23,11 @@ declare(strict_types=1); namespace FireflyIII\Services\Webhook; -use Exception; use FireflyIII\Helpers\Webhook\SignatureGeneratorInterface; use FireflyIII\Models\WebhookAttempt; use FireflyIII\Models\WebhookMessage; use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Exception\RequestException; use JsonException; use Log; @@ -92,7 +91,7 @@ class StandardWebhookSender implements WebhookSenderInterface try { $res = $client->request('POST', $this->message->webhook->url, $options); $this->message->sent = true; - } catch (ClientException | Exception $e) { + } catch (RequestException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); @@ -104,7 +103,7 @@ class StandardWebhookSender implements WebhookSenderInterface $attempt = new WebhookAttempt; $attempt->webhookMessage()->associate($this->message); - $attempt->status_code = $e->getResponse() ? $e->getResponse()->getStatusCode() : 0; + $attempt->status_code = $e->hasResponse() ? $e->getResponse()->getStatusCode() : 0; $attempt->logs = $logs; $attempt->save(); diff --git a/app/Support/Amount.php b/app/Support/Amount.php index d2280d48f0..cf46bd1e12 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -164,7 +164,7 @@ class Amount if (strlen($currencyCode) > 3) { $currencyCode = json_decode($currencyCode, true, 512, JSON_THROW_ON_ERROR) ?? 'EUR'; } - /** @var TransactionCurrency $currency */ + /** @var TransactionCurrency|null $currency */ $currency = TransactionCurrency::where('code', $currencyCode)->first(); if (null === $currency) { // get EUR @@ -185,7 +185,7 @@ class Amount try { $value = Crypt::decrypt($value); // verified } catch (DecryptException $e) { - // ignore decryption error. + // @ignoreException } return $value; diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.php index 9d24ca6f1a..8d925d0038 100644 --- a/app/Support/Authentication/RemoteUserGuard.php +++ b/app/Support/Authentication/RemoteUserGuard.php @@ -47,7 +47,7 @@ class RemoteUserGuard implements Guard * * @return void */ - public function __construct(UserProvider $provider, Application $app) + public function __construct(UserProvider $provider, Application $app) // @phpstan-ignore-line { $this->application = $app; $this->provider = $provider; diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index 423b699a7d..d458b343f5 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -62,7 +62,7 @@ class Date implements BinderInterface 'previousFiscalYearStart' => $fiscalHelper->startOfFiscalYear(Carbon::now())->subYear(), 'previousFiscalYearEnd' => $fiscalHelper->endOfFiscalYear(Carbon::now())->subYear(), ]; - if (isset($magicWords[$value])) { + if (array_key_exists($value, $magicWords)) { $return = $magicWords[$value]; Log::debug(sprintf('User requests "%s", so will return "%s"', $value, $return)); @@ -71,7 +71,7 @@ class Date implements BinderInterface try { $result = new Carbon($value); - } catch (Exception $e) { + } catch (Exception $e) { // @phpstan-ignore-line Log::error(sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage())); throw new NotFoundHttpException; } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 7175468e6c..8301e839f9 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -96,7 +96,7 @@ class CacheProperties $content .= json_encode($property, JSON_THROW_ON_ERROR, 512); } catch (JsonException $e) { // @ignoreException - $content .= md5(time()); + $content .= hash('sha256', (string)time()); } } $this->hash = substr(hash('sha256', $content), 0, 16); diff --git a/app/Support/Chart/Budget/FrontpageChartGenerator.php b/app/Support/Chart/Budget/FrontpageChartGenerator.php index 3ea24b1cb2..941fdfabe0 100644 --- a/app/Support/Chart/Budget/FrontpageChartGenerator.php +++ b/app/Support/Chart/Budget/FrontpageChartGenerator.php @@ -30,6 +30,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\User; use Illuminate\Support\Collection; + /** * Class FrontpageChartGenerator */ @@ -97,12 +98,7 @@ class FrontpageChartGenerator return $this->noBudgetLimits($data, $budget); } - // if limits: - if (0 !== $limits->count()) { - return $this->budgetLimits($data, $budget, $limits); - } - - return $data; + return $this->budgetLimits($data, $budget, $limits); } /** diff --git a/app/Support/Cronjobs/AbstractCronjob.php b/app/Support/Cronjobs/AbstractCronjob.php index d1fc16d0e7..19a5ae44a2 100644 --- a/app/Support/Cronjobs/AbstractCronjob.php +++ b/app/Support/Cronjobs/AbstractCronjob.php @@ -65,7 +65,7 @@ abstract class AbstractCronjob /** * @param Carbon $date */ - public function setDate(Carbon $date): void + final public function setDate(Carbon $date): void { $newDate = clone $date; $this->date = $newDate; @@ -74,7 +74,7 @@ abstract class AbstractCronjob /** * @param bool $force */ - public function setForce(bool $force): void + final public function setForce(bool $force): void { $this->force = $force; } diff --git a/app/Support/Cronjobs/AutoBudgetCronjob.php b/app/Support/Cronjobs/AutoBudgetCronjob.php index 96bf9d5f96..bfd5118f36 100644 --- a/app/Support/Cronjobs/AutoBudgetCronjob.php +++ b/app/Support/Cronjobs/AutoBudgetCronjob.php @@ -43,7 +43,7 @@ class AutoBudgetCronjob extends AbstractCronjob $config = app('fireflyconfig')->get('last_ab_job', 0); $lastTime = (int)$config->data; $diff = time() - $lastTime; - $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), true); + $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime),null, true); if (0 === $lastTime) { Log::info('Auto budget cron-job has never fired before.'); } diff --git a/app/Support/Cronjobs/RecurringCronjob.php b/app/Support/Cronjobs/RecurringCronjob.php index f68f826a0d..4c00551e3d 100644 --- a/app/Support/Cronjobs/RecurringCronjob.php +++ b/app/Support/Cronjobs/RecurringCronjob.php @@ -44,7 +44,7 @@ class RecurringCronjob extends AbstractCronjob $config = app('fireflyconfig')->get('last_rt_job', 0); $lastTime = (int)$config->data; $diff = time() - $lastTime; - $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), true); + $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null,true); if (0 === $lastTime) { Log::info('Recurring transactions cron-job has never fired before.'); diff --git a/app/Support/Cronjobs/TelemetryCronjob.php b/app/Support/Cronjobs/TelemetryCronjob.php index 624f1f523f..88a7850ef5 100644 --- a/app/Support/Cronjobs/TelemetryCronjob.php +++ b/app/Support/Cronjobs/TelemetryCronjob.php @@ -54,7 +54,7 @@ class TelemetryCronjob extends AbstractCronjob $config = app('fireflyconfig')->get('last_tm_job', 0); $lastTime = (int)$config->data; $diff = time() - $lastTime; - $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), true); + $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); if (0 === $lastTime) { Log::info('Telemetry cron-job has never fired before.'); } diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index d5fb36f40a..a5286b9b7a 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -64,7 +64,7 @@ class ExpandedForm } try { $html = prefixView('form.amount-no-currency', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage())); $html = 'Could not render amountNoCurrency.'; } @@ -100,7 +100,7 @@ class ExpandedForm unset($options['placeholder'], $options['autocomplete'], $options['class']); try { $html = prefixView('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render checkbox(): %s', $e->getMessage())); $html = 'Could not render checkbox.'; } @@ -125,7 +125,7 @@ class ExpandedForm unset($options['placeholder']); try { $html = prefixView('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render date(): %s', $e->getMessage())); $html = 'Could not render date.'; } @@ -148,7 +148,7 @@ class ExpandedForm $classes = $this->getHolderClasses($name); try { $html = prefixView('form.file', compact('classes', 'name', 'label', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render file(): %s', $e->getMessage())); $html = 'Could not render file.'; } @@ -174,7 +174,7 @@ class ExpandedForm $options['step'] = '1'; try { $html = prefixView('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render integer(): %s', $e->getMessage())); $html = 'Could not render integer.'; } @@ -199,7 +199,7 @@ class ExpandedForm $value = $this->fillFieldValue($name, $value); try { $html = prefixView('form.location', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render location(): %s', $e->getMessage())); $html = 'Could not render location.'; } @@ -220,12 +220,12 @@ class ExpandedForm $fields = ['title', 'name', 'description']; /** @var Eloquent $entry */ foreach ($set as $entry) { - $entryId = (int)$entry->id; + $entryId = (int)$entry->id; // @phpstan-ignore-line $title = null; foreach ($fields as $field) { - if (isset($entry->$field) && null === $title) { - $title = $entry->$field; + if (property_exists($entry, $field) && null === $title) { + $title = $entry->$field; // @phpstan-ignore-line } } $selectList[$entryId] = $title; @@ -257,7 +257,7 @@ class ExpandedForm } try { $html = prefixView('form.non-selectable-amount', compact('selectedCurrency', 'classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render nonSelectableAmount(): %s', $e->getMessage())); $html = 'Could not render nonSelectableAmount.'; } @@ -283,7 +283,7 @@ class ExpandedForm unset($options['placeholder']); try { $html = prefixView('form.number', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render number(): %s', $e->getMessage())); $html = 'Could not render number.'; } @@ -312,7 +312,7 @@ class ExpandedForm try { $html = prefixView('form.object_group', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render objectGroup(): %s', $e->getMessage())); $html = 'Could not render objectGroup.'; } @@ -331,7 +331,7 @@ class ExpandedForm { try { $html = prefixView('form.options', compact('type', 'name'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render select(): %s', $e->getMessage())); $html = 'Could not render optionsList.'; } @@ -354,7 +354,7 @@ class ExpandedForm $classes = $this->getHolderClasses($name); try { $html = prefixView('form.password', compact('classes', 'name', 'label', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render password(): %s', $e->getMessage())); $html = 'Could not render password.'; } @@ -382,7 +382,7 @@ class ExpandedForm unset($options['placeholder']); try { $html = prefixView('form.percentage', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render percentage(): %s', $e->getMessage())); $html = 'Could not render percentage.'; } @@ -405,7 +405,7 @@ class ExpandedForm $classes = $this->getHolderClasses($name); try { $html = prefixView('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render staticText(): %s', $e->getMessage())); $html = 'Could not render staticText.'; } @@ -429,7 +429,7 @@ class ExpandedForm $value = $this->fillFieldValue($name, $value); try { $html = prefixView('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render text(): %s', $e->getMessage())); $html = 'Could not render text.'; } @@ -459,7 +459,7 @@ class ExpandedForm try { $html = prefixView('form.textarea', compact('classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render textarea(): %s', $e->getMessage())); $html = 'Could not render textarea.'; } diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index 612c10b818..03657a2201 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Export; use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Models\Account; use FireflyIII\Models\Bill; @@ -52,6 +53,7 @@ use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface use FireflyIII\User; use Illuminate\Support\Collection; use League\Csv\CannotInsertRecord; +use League\Csv\Exception; use League\Csv\Writer; /** @@ -93,6 +95,8 @@ class ExportDataGenerator /** * @return array * @throws CannotInsertRecord + * @throws Exception + * @throws FireflyException */ public function export(): array { @@ -168,16 +172,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportBills(): string { @@ -211,17 +226,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string - * @throws CannotInsertRecord + * @throws FireflyException */ private function exportBudgets(): string { @@ -265,17 +290,28 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportCategories(): string { @@ -303,16 +339,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportPiggies(): string { @@ -356,16 +403,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportRecurring(): string { @@ -397,7 +455,7 @@ class ExportDataGenerator $recurrence->transactionType->type, $recurrence->title, $recurrence->description, - $recurrence->first_date ? $recurrence->first_date->format('Y-m-d') : null, + null !== $recurrence->first_date ? $recurrence->first_date->format('Y-m-d') : null, $recurrence->repeat_until ? $recurrence->repeat_until->format('Y-m-d') : null, $recurrence->latest_date ? $recurrence->latest_date->format('Y-m-d') : null, $recurrence->repetitions, @@ -443,16 +501,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportRules(): string { @@ -468,7 +537,7 @@ class ExportDataGenerator $records[] = [ $this->user->id, $rule->id, 'rule', $rule->created_at->toAtomString(), $rule->updated_at->toAtomString(), - $rule->ruleGroup->id, $rule->ruleGroup->name, + $rule->ruleGroup->id, $rule->ruleGroup->title, $rule->title, $rule->description, $rule->order, $rule->active, $rule->stop_processing, $rule->strict, ]; /** @var RuleTrigger $trigger */ @@ -499,16 +568,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportTags(): string { @@ -538,16 +618,27 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** * @return string + * @throws FireflyException */ private function exportTransactions(): string { @@ -647,12 +738,22 @@ class ExportDataGenerator $csv = Writer::createFromString(''); //insert the header - $csv->insertOne($header); + try { + $csv->insertOne($header); + } catch (CannotInsertRecord $e) { + throw new FireflyException(sprintf('Could not add record to set: %s', $e->getMessage()), 0, $e); + } //insert all the records $csv->insertAll($records); - return $csv->getContent(); //returns the CSV document as a string + try { + $string = $csv->toString(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not export to string: %s', $e->getMessage()), 0, $e); + } + + return $string; } /** @@ -662,7 +763,7 @@ class ExportDataGenerator */ private function mergeTags(array $tags): string { - if (empty($tags)) { + if (0 === count($tags)) { return ''; } $smol = []; diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index 6440b655ad..5f923758b9 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -27,7 +27,6 @@ use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Configuration; use Illuminate\Database\QueryException; -use Log; /** * Class FireflyConfig. @@ -48,9 +47,8 @@ class FireflyConfig } try { Configuration::where('name', $name)->delete(); - } catch (Exception $e) { - Log::debug(sprintf('Could not delete config value: %s', $e->getMessage())); - + } catch (Exception $e) { // @phpstan-ignore-line + // @ignoreException } } @@ -65,8 +63,8 @@ class FireflyConfig } /** - * @param string $name - * @param bool|string|int|null $default + * @param string $name + * @param bool|string|int|null $default * * @return Configuration|null * @throws FireflyException @@ -79,13 +77,13 @@ class FireflyConfig } try { - /** @var Configuration $config */ + /** @var Configuration|null $config */ $config = Configuration::where('name', $name)->first(['id', 'name', 'data']); - } catch (QueryException | Exception $e) { + } catch (QueryException | Exception $e) { // @phpstan-ignore-line throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage())); } - if ($config) { + if (null !== $config) { Cache::forever($fullName, $config); return $config; @@ -122,29 +120,26 @@ class FireflyConfig /** * @param string $name - * @param $value + * @param mixed $value * * @return Configuration */ public function put(string $name, $value): Configuration { - return $this->set($name, $value); } /** - * @param string $name - * @param $value - * @param int|string|true $value + * @param string $name + * @param mixed $value * * @return Configuration */ public function set(string $name, $value): Configuration { - /** @var Configuration $config */ try { $config = Configuration::whereName($name)->first(); - } catch (QueryException | Exception $e) { + } catch (QueryException | Exception $e) { // @phpstan-ignore-line $item = new Configuration; $item->name = $name; $item->data = $value; diff --git a/app/Support/Form/AccountForm.php b/app/Support/Form/AccountForm.php index 17c1c59f3a..16b0ae0b40 100644 --- a/app/Support/Form/AccountForm.php +++ b/app/Support/Form/AccountForm.php @@ -43,9 +43,9 @@ class AccountForm /** * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -94,9 +94,9 @@ class AccountForm /** * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -116,11 +116,10 @@ class AccountForm /** * Check list of asset accounts. * - * @param string $name - * @param array $options + * @param string $name + * @param array|null $options * * @return string - * */ public function assetAccountCheckList(string $name, array $options = null): string { @@ -137,7 +136,7 @@ class AccountForm unset($options['class']); try { $html = prefixView('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage())); $html = 'Could not render assetAccountCheckList.'; } @@ -148,9 +147,9 @@ class AccountForm /** * Basic list of asset accounts. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -164,9 +163,9 @@ class AccountForm /** * Same list but all liabilities as well. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php index 5e7e2e888c..e27d167150 100644 --- a/app/Support/Form/CurrencyForm.php +++ b/app/Support/Form/CurrencyForm.php @@ -22,8 +22,8 @@ declare(strict_types=1); namespace FireflyIII\Support\Form; + use Amount as Amt; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Support\Collection; @@ -42,9 +42,9 @@ class CurrencyForm use FormSupport; /** - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -54,13 +54,12 @@ class CurrencyForm } /** - * @param string $name - * @param string $view - * @param mixed $value - * @param array $options + * @param string $name + * @param string $view + * @param mixed $value + * @param array|null $options * * @return string - * */ protected function currencyField(string $name, string $view, $value = null, array $options = null): string { @@ -77,7 +76,7 @@ class CurrencyForm // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) $preFilled = session('preFilled'); $key = 'amount_currency_id_' . $name; - $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id; + $sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id; Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId)); @@ -96,7 +95,7 @@ class CurrencyForm } try { $html = prefixView('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage())); $html = 'Could not render currencyField.'; } @@ -107,12 +106,11 @@ class CurrencyForm /** * TODO describe and cleanup. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string - * @throws FireflyException */ public function balanceAll(string $name, $value = null, array $options = null): string { @@ -122,13 +120,12 @@ class CurrencyForm /** * TODO cleanup and describe better. * - * @param string $name - * @param string $view - * @param mixed $value - * @param array $options + * @param string $name + * @param string $view + * @param mixed $value + * @param array|null $options * * @return string - * */ protected function allCurrencyField(string $name, string $view, $value = null, array $options = null): string { @@ -145,7 +142,7 @@ class CurrencyForm // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) $preFilled = session('preFilled'); $key = 'amount_currency_id_' . $name; - $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id; + $sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id; Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId)); @@ -164,7 +161,7 @@ class CurrencyForm } try { $html = prefixView('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage())); $html = 'Could not render currencyField.'; } @@ -175,9 +172,9 @@ class CurrencyForm /** * TODO cleanup and describe. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -200,9 +197,9 @@ class CurrencyForm /** * TODO cleanup and describe. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ diff --git a/app/Support/Form/FormSupport.php b/app/Support/Form/FormSupport.php index ccad30a682..c6c720cc44 100644 --- a/app/Support/Form/FormSupport.php +++ b/app/Support/Form/FormSupport.php @@ -37,10 +37,10 @@ use Throwable; trait FormSupport { /** - * @param string $name - * @param array $list - * @param mixed $selected - * @param array $options + * @param string $name + * @param array|null $list + * @param mixed $selected + * @param array|null $options * * @return string */ @@ -54,7 +54,7 @@ trait FormSupport unset($options['autocomplete'], $options['placeholder']); try { $html = prefixView('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Could not render select(): %s', $e->getMessage())); $html = 'Could not render select.'; } @@ -63,15 +63,15 @@ trait FormSupport } /** - * @param $name - * @param $options + * @param string $name + * @param array|null $options * * @return string */ protected function label(string $name, array $options = null): string { $options = $options ?? []; - if (isset($options['label'])) { + if (array_key_exists('label', $options)) { return $options['label']; } $name = str_replace('[]', '', $name); @@ -80,9 +80,9 @@ trait FormSupport } /** - * @param $name - * @param $label - * @param array $options + * @param string $name + * @param mixed $label + * @param array|null $options * * @return array */ @@ -99,7 +99,7 @@ trait FormSupport } /** - * @param $name + * @param string $name * * @return string */ @@ -118,8 +118,8 @@ trait FormSupport } /** - * @param string $name - * @param $value + * @param string $name + * @param mixed|null $value * * @return mixed */ @@ -127,14 +127,14 @@ trait FormSupport { if (app('session')->has('preFilled')) { $preFilled = session('preFilled'); - $value = isset($preFilled[$name]) && null === $value ? $preFilled[$name] : $value; + $value = array_key_exists($name, $preFilled) && null === $value ? $preFilled[$name] : $value; } try { if (null !== request()->old($name)) { $value = request()->old($name); } - } catch (RuntimeException $e) { + } catch (RuntimeException $e) { // @phpstan-ignore-line // don't care about session errors. Log::debug(sprintf('Run time: %s', $e->getMessage())); } @@ -163,8 +163,8 @@ trait FormSupport $date = null; try { $date = today(config('app.timezone')); - } catch (Exception $e) { - $e->getMessage(); + } catch (Exception $e) { // @phpstan-ignore-line + // @ignoreException } return $date; diff --git a/app/Support/Form/PiggyBankForm.php b/app/Support/Form/PiggyBankForm.php index 21e11d31bc..068bfbcfca 100644 --- a/app/Support/Form/PiggyBankForm.php +++ b/app/Support/Form/PiggyBankForm.php @@ -37,9 +37,9 @@ class PiggyBankForm /** * TODO cleanup and describe. * - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ diff --git a/app/Support/Form/RuleForm.php b/app/Support/Form/RuleForm.php index d1f0748f7b..f90091c697 100644 --- a/app/Support/Form/RuleForm.php +++ b/app/Support/Form/RuleForm.php @@ -36,9 +36,9 @@ class RuleForm use FormSupport; /** - * @param string $name - * @param mixed $value - * @param array $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -79,7 +79,7 @@ class RuleForm ]; /** @var RuleGroup $group */ foreach ($list as $group) { - if (isset($options['hidden']) && (int)$options['hidden'] !== $group->id) { + if (array_key_exists('hidden', $options) && (int)$options['hidden'] !== $group->id) { $array[$group->id] = $group->title; } } diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.php index e3d1a1adfc..7ee0c9f0fd 100644 --- a/app/Support/Http/Controllers/AugumentData.php +++ b/app/Support/Http/Controllers/AugumentData.php @@ -123,7 +123,7 @@ trait AugumentData foreach ($accountIds as $combinedId) { $parts = explode('-', $combinedId); $accountId = (int)$parts[0]; - if (isset($grouped[$accountId])) { + if (array_key_exists($accountId, $grouped)) { $return[$accountId] = $grouped[$accountId][0]['name']; } } @@ -147,7 +147,7 @@ trait AugumentData $grouped = $budgets->groupBy('id')->toArray(); $return = []; foreach ($budgetIds as $budgetId) { - if (isset($grouped[$budgetId])) { + if (array_key_exists($budgetId, $grouped)) { $return[$budgetId] = $grouped[$budgetId][0]['name']; } } @@ -173,7 +173,7 @@ trait AugumentData foreach ($categoryIds as $combinedId) { $parts = explode('-', $combinedId); $categoryId = (int)$parts[0]; - if (isset($grouped[$categoryId])) { + if (array_key_exists($categoryId, $grouped)) { $return[$categoryId] = $grouped[$categoryId][0]['name']; } } @@ -286,7 +286,7 @@ trait AugumentData $currencyId = (int)$journal['currency_id']; // if not set, set to zero: - if (!isset($sum['per_currency'][$currencyId])) { + if (!array_key_exists($currencyId, $sum['per_currency'])) { $sum['per_currency'][$currencyId] = [ 'sum' => '0', 'currency' => [ diff --git a/app/Support/Http/Controllers/CreateStuff.php b/app/Support/Http/Controllers/CreateStuff.php index cdd2a82947..8c4b7c80fc 100644 --- a/app/Support/Http/Controllers/CreateStuff.php +++ b/app/Support/Http/Controllers/CreateStuff.php @@ -115,7 +115,7 @@ trait CreateStuff } // switch on class existence. - + $keys= []; Log::info(sprintf('PHP version is %s', phpversion())); if (class_exists(LegacyRSA::class)) { // PHP 7 @@ -132,8 +132,8 @@ trait CreateStuff // @codeCoverageIgnoreStart Log::alert('NO OAuth keys were found. They have been created.'); - file_put_contents($publicKey, array_get($keys, 'publickey')); - file_put_contents($privateKey, array_get($keys, 'privatekey')); + file_put_contents($publicKey, $keys['publickey']); + file_put_contents($privateKey, $keys['privatekey']); } /** diff --git a/app/Support/Http/Controllers/ModelInformation.php b/app/Support/Http/Controllers/ModelInformation.php index ca35c4de5c..7f6b16014c 100644 --- a/app/Support/Http/Controllers/ModelInformation.php +++ b/app/Support/Http/Controllers/ModelInformation.php @@ -57,15 +57,12 @@ trait ModelInformation 'count' => 1, ] )->render(); - // @codeCoverageIgnoreStart - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); $result = 'Could not render view. See log files.'; } - // @codeCoverageIgnoreEnd - return [$result]; } @@ -149,13 +146,11 @@ trait ModelInformation 'triggers' => $triggers, ] )->render(); - // @codeCoverageIgnoreStart - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage())); Log::debug($e->getTraceAsString()); $string = ''; - // @codeCoverageIgnoreEnd } if ('' !== $string) { $result[] = $string; @@ -189,9 +184,9 @@ trait ModelInformation $index = 0; // amount, description, category, budget, tags, source, destination, notes, currency type //,type - /** @var Transaction $source */ + /** @var Transaction|null $source */ $source = $journal->transactions()->where('amount', '<', 0)->first(); - /** @var Transaction $destination */ + /** @var Transaction|null $destination */ $destination = $journal->transactions()->where('amount', '>', 0)->first(); if (null === $destination || null === $source) { return $result; @@ -267,13 +262,11 @@ trait ModelInformation 'triggers' => $triggers, ] )->render(); - // @codeCoverageIgnoreStart - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage())); Log::debug($e->getTraceAsString()); $string = ''; - // @codeCoverageIgnoreEnd } if ('' !== $string) { $result[] = $string; diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index cdf90716b7..7be27a72e7 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -29,6 +29,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Category; use FireflyIII\Models\Tag; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; use Log; @@ -63,15 +64,16 @@ use Log; */ trait PeriodOverview { + protected JournalRepositoryInterface $journalRepos; /** * This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range) * and for each period, the amount of money spent and earned. This is a complex operation which is cached for * performance reasons. * - * @param Account $account The account involved - * @param Carbon $date The start date. - * @param Carbon $end The end date. + * @param Account $account + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -220,7 +222,7 @@ trait PeriodOverview foreach ($journals as $journal) { $currencyId = (int)$journal['currency_id']; $foreignCurrencyId = $journal['foreign_currency_id']; - if (!isset($return[$currencyId])) { + if (!array_key_exists($currencyId, $return)) { $return[$currencyId] = [ 'amount' => '0', 'count' => 0, @@ -235,7 +237,7 @@ trait PeriodOverview $return[$currencyId]['count']++; if (null !== $foreignCurrencyId && null !== $journal['foreign_amount']) { - if (!isset($return[$foreignCurrencyId])) { + if (!array_key_exists($foreignCurrencyId, $return)) { $return[$foreignCurrencyId] = [ 'amount' => '0', 'count' => 0, @@ -338,7 +340,7 @@ trait PeriodOverview * This method has been refactored recently. * * @param Carbon $start - * @param Carbon $date + * @param Carbon $end * * @return array */ @@ -469,10 +471,11 @@ trait PeriodOverview * This shows a period overview for a tag. It goes back in time and lists all relevant transactions and sums. * * @param Tag $tag - * - * @param Carbon $date + * @param Carbon $start + * @param Carbon $end * * @return array + * @throws \FireflyIII\Exceptions\FireflyException */ protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags. { @@ -542,9 +545,11 @@ trait PeriodOverview /** * @param string $transactionType - * @param Carbon $endDate + * @param Carbon $start + * @param Carbon $end * * @return array + * @throws \FireflyIII\Exceptions\FireflyException */ protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array { diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php index f726a488ab..181138a22c 100644 --- a/app/Support/Http/Controllers/RenderPartialViews.php +++ b/app/Support/Http/Controllers/RenderPartialViews.php @@ -68,7 +68,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $view = prefixView('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render: %s', $e->getMessage())); $view = 'Firefly III could not render the view. Please see the log files.'; } @@ -91,7 +91,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $result = prefixView('reports.options.budget', compact('budgets'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) {// @phpstan-ignore-line Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); $result = 'Could not render view.'; } @@ -124,7 +124,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $view = prefixView('popup.report.budget-spent-amount', compact('journals', 'budget'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render: %s', $e->getMessage())); $view = 'Firefly III could not render the view. Please see the log files.'; } @@ -153,7 +153,7 @@ trait RenderPartialViews try { $view = prefixView('popup.report.category-entry', compact('journals', 'category'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render: %s', $e->getMessage())); $view = 'Firefly III could not render the view. Please see the log files.'; } @@ -174,7 +174,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $result = prefixView('reports.options.category', compact('categories'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Cannot render reports.options.category: %s', $e->getMessage())); $result = 'Could not render view.'; } @@ -217,7 +217,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $result = prefixView('reports.options.double', compact('set'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); $result = 'Could not render view.'; } @@ -252,7 +252,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $view = prefixView('popup.report.expense-entry', compact('journals', 'account'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render: %s', $e->getMessage())); $view = 'Firefly III could not render the view. Please see the log files.'; } @@ -289,7 +289,7 @@ trait RenderPartialViews ] )->render(); // @codeCoverageIgnoreStart - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); } @@ -340,7 +340,7 @@ trait RenderPartialViews ] )->render(); // @codeCoverageIgnoreStart - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); } @@ -376,7 +376,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $view = prefixView('popup.report.income-entry', compact('journals', 'account'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Could not render: %s', $e->getMessage())); $view = 'Firefly III could not render the view. Please see the log files.'; } @@ -396,7 +396,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $result = prefixView('reports.options.no-options')->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage())); $result = 'Could not render view.'; } @@ -420,7 +420,7 @@ trait RenderPartialViews // @codeCoverageIgnoreStart try { $result = prefixView('reports.options.tag', compact('tags'))->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); $result = 'Could not render view.'; } diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index e9159111f4..12e328d0c2 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -48,7 +48,7 @@ trait RequestInformation * * @return string */ - protected function getDomain(): string // get request info + final protected function getDomain(): string // get request info { $url = url()->to('/'); $parts = parse_url($url); @@ -65,7 +65,7 @@ trait RequestInformation * @return string * */ - protected function getHelpText(string $route, string $language): string // get from internet. + final protected function getHelpText(string $route, string $language): string // get from internet. { $help = app(HelpInterface::class); // get language and default variables. @@ -119,7 +119,7 @@ trait RequestInformation /** * @return string */ - protected function getPageName(): string // get request info + final protected function getPageName(): string // get request info { return str_replace('.', '_', RouteFacade::currentRouteName()); } @@ -129,7 +129,7 @@ trait RequestInformation * * @return string */ - protected function getSpecificPageName(): string // get request info + final protected function getSpecificPageName(): string // get request info { return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType'); } @@ -141,7 +141,7 @@ trait RequestInformation * * @return array */ - protected function getValidTriggerList(TestRuleFormRequest $request): array // process input + final protected function getValidTriggerList(TestRuleFormRequest $request): array // process input { $triggers = []; $data = $request->get('triggers'); @@ -163,7 +163,7 @@ trait RequestInformation * * @return bool */ - protected function hasSeenDemo(): bool // get request info + get preference + final protected function hasSeenDemo(): bool // get request info + get preference { $page = $this->getPageName(); $specificPage = $this->getSpecificPageName(); @@ -194,7 +194,7 @@ trait RequestInformation * @return bool * */ - protected function notInSessionRange(Carbon $date): bool // Validate a preference + final protected function notInSessionRange(Carbon $date): bool // Validate a preference { /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); @@ -219,7 +219,7 @@ trait RequestInformation * * @return array */ - protected function parseAttributes(array $attributes): array // parse input + return result + final protected function parseAttributes(array $attributes): array // parse input + return result { $attributes['location'] = $attributes['location'] ?? ''; $attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', [])); @@ -253,7 +253,7 @@ trait RequestInformation * * @throws ValidationException */ - protected function validatePassword(User $user, string $current, string $new): bool //get request info + final protected function validatePassword(User $user, string $current, string $new): bool //get request info { if (!Hash::check($current, $user->password)) { throw new ValidationException((string)trans('firefly.invalid_current_password')); @@ -274,7 +274,7 @@ trait RequestInformation * @return ValidatorContract * @codeCoverageIgnore */ - protected function validator(array $data): ValidatorContract + final protected function validator(array $data): ValidatorContract { return Validator::make( $data, diff --git a/app/Support/Http/Controllers/RuleManagement.php b/app/Support/Http/Controllers/RuleManagement.php index 2ead11c60f..c9e2d6f4fd 100644 --- a/app/Support/Http/Controllers/RuleManagement.php +++ b/app/Support/Http/Controllers/RuleManagement.php @@ -108,7 +108,7 @@ trait RuleManagement 'count' => $index + 1, ] )->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); } @@ -154,7 +154,7 @@ trait RuleManagement 'triggers' => $triggers, ] )->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); } @@ -197,7 +197,7 @@ trait RuleManagement 'triggers' => $triggers, ] )->render(); - } catch (Throwable $e) { + } catch (Throwable $e) { // @phpstan-ignore-line Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); } diff --git a/app/Support/Http/Controllers/UserNavigation.php b/app/Support/Http/Controllers/UserNavigation.php index 5bf7c550cc..65f888dbef 100644 --- a/app/Support/Http/Controllers/UserNavigation.php +++ b/app/Support/Http/Controllers/UserNavigation.php @@ -53,7 +53,7 @@ trait UserNavigation * * @return string */ - protected function getPreviousUri(string $identifier): string + final protected function getPreviousUri(string $identifier): string { Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier)); $uri = (string)session($identifier); @@ -76,7 +76,7 @@ trait UserNavigation * * @return bool */ - protected function isEditableAccount(Account $account): bool + final protected function isEditableAccount(Account $account): bool { $editable = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $type = $account->accountType->type; @@ -89,9 +89,9 @@ trait UserNavigation * * @return bool */ - protected function isEditableGroup(TransactionGroup $group): bool + final protected function isEditableGroup(TransactionGroup $group): bool { - /** @var TransactionJournal $journal */ + /** @var TransactionJournal|null $journal */ $journal = $group->transactionJournals()->first(); if (null === $journal) { return false; @@ -107,13 +107,13 @@ trait UserNavigation * * @return RedirectResponse|Redirector */ - protected function redirectAccountToAccount(Account $account) + final protected function redirectAccountToAccount(Account $account) { $type = $account->accountType->type; if (AccountType::RECONCILIATION === $type || AccountType::INITIAL_BALANCE === $type) { // reconciliation must be stored somewhere in this account's transactions. - /** @var Transaction $transaction */ + /** @var Transaction|null $transaction */ $transaction = $account->transactions()->first(); if (null === $transaction) { Log::error(sprintf('Account #%d has no transactions. Dont know where it belongs.', $account->id)); @@ -122,7 +122,7 @@ trait UserNavigation return redirect(route('index')); } $journal = $transaction->transactionJournal; - /** @var Transaction $other */ + /** @var Transaction|null $other */ $other = $journal->transactions()->where('id', '!=', $transaction->id)->first(); if (null === $other) { Log::error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id)); @@ -142,9 +142,9 @@ trait UserNavigation * * @return RedirectResponse|Redirector */ - protected function redirectGroupToAccount(TransactionGroup $group) + final protected function redirectGroupToAccount(TransactionGroup $group) { - /** @var TransactionJournal $journal */ + /** @var TransactionJournal|null $journal */ $journal = $group->transactionJournals()->first(); if (null === $journal) { Log::error(sprintf('No journals in group #%d', $group->id)); @@ -170,13 +170,13 @@ trait UserNavigation * * @return string|null */ - protected function rememberPreviousUri(string $identifier): ?string + final protected function rememberPreviousUri(string $identifier): ?string { $return = app('url')->previous(); - /** @var ViewErrorBag $errors */ + /** @var ViewErrorBag|null $errors */ $errors = session()->get('errors'); $forbidden = ['json', 'debug']; - if ((null === $errors || (null !== $errors && 0 === $errors->count())) && !Str::contains($return, $forbidden)) { + if ((null === $errors || (0 === $errors->count())) && !Str::contains($return, $forbidden)) { Log::debug(sprintf('Saving URL %s under key %s', $return, $identifier)); session()->put($identifier, $return); } diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 2f81cbcb4e..0322a5ed49 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -34,8 +34,8 @@ class Navigation { /** * @param \Carbon\Carbon $theDate - * @param $repeatFreq - * @param $skip + * @param string $repeatFreq + * @param int $skip * * @return \Carbon\Carbon */ @@ -71,12 +71,12 @@ class Navigation 'half-year' => 6, ]; - if (!isset($functionMap[$repeatFreq])) { + if (!array_key_exists($repeatFreq, $functionMap)) { Log::error(sprintf('Cannot do addPeriod for $repeat_freq "%s"', $repeatFreq)); return $theDate; } - if (isset($modifierMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $modifierMap)) { $add *= $modifierMap[$repeatFreq]; } $function = $functionMap[$repeatFreq]; @@ -156,12 +156,13 @@ class Navigation $loopCount++; } } + return $periods; } /** * @param \Carbon\Carbon $end - * @param $repeatFreq + * @param string $repeatFreq * * @return \Carbon\Carbon */ @@ -212,14 +213,14 @@ class Navigation return $currentEnd; } - if (!isset($functionMap[$repeatFreq])) { + if (!array_key_exists($repeatFreq, $functionMap)) { Log::error(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq)); return $end; } $function = $functionMap[$repeatFreq]; - if (isset($modifierMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $modifierMap)) { $currentEnd->$function($modifierMap[$repeatFreq]); if (in_array($repeatFreq, $subDay, true)) { $currentEnd->subDay(); @@ -265,7 +266,7 @@ class Navigation $currentEnd = clone $theCurrentEnd; - if (isset($functionMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $functionMap)) { $function = $functionMap[$repeatFreq]; $currentEnd->$function(); } @@ -338,7 +339,7 @@ class Navigation '6M' => (string)trans('config.half_year'), ]; - if (isset($formatMap[$repeatFrequency])) { + if (array_key_exists($repeatFrequency, $formatMap)) { return $date->formatLocalized((string)$formatMap[$repeatFrequency]); } if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) { @@ -472,7 +473,7 @@ class Navigation /** * @param \Carbon\Carbon $theDate - * @param $repeatFreq + * @param string $repeatFreq * * @return \Carbon\Carbon */ @@ -496,7 +497,7 @@ class Navigation 'yearly' => 'startOfYear', '1Y' => 'startOfYear', ]; - if (isset($functionMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $functionMap)) { $function = $functionMap[$repeatFreq]; $date->$function(); @@ -523,7 +524,7 @@ class Navigation /** * @param \Carbon\Carbon $theDate - * @param $repeatFreq + * @param string $repeatFreq * @param int $subtract * * @return \Carbon\Carbon @@ -555,13 +556,13 @@ class Navigation 'half-year' => 6, '6M' => 6, ]; - if (isset($functionMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $functionMap)) { $function = $functionMap[$repeatFreq]; $date->$function($subtract); return $date; } - if (isset($modifierMap[$repeatFreq])) { + if (array_key_exists($repeatFreq, $modifierMap)) { $subtract *= $modifierMap[$repeatFreq]; $date->subMonths($subtract); @@ -577,6 +578,7 @@ class Navigation $tEnd = session('end', Carbon::now()->endOfMonth()); $diffInDays = $tStart->diffInDays($tEnd); $date->subDays($diffInDays * $subtract); + return $date; } @@ -584,7 +586,7 @@ class Navigation } /** - * @param $range + * @param string $range * @param \Carbon\Carbon $start * * @return \Carbon\Carbon @@ -602,7 +604,7 @@ class Navigation ]; $end = clone $start; - if (isset($functionMap[$range])) { + if (array_key_exists($range, $functionMap)) { $function = $functionMap[$range]; $end->$function(); @@ -630,7 +632,7 @@ class Navigation } /** - * @param $range + * @param string $range * @param \Carbon\Carbon $start * * @return \Carbon\Carbon @@ -646,7 +648,7 @@ class Navigation '3M' => 'firstOfQuarter', 'custom' => 'startOfMonth', // this only happens in test situations. ]; - if (isset($functionMap[$range])) { + if (array_key_exists($range, $functionMap)) { $function = $functionMap[$range]; $start->$function(); diff --git a/app/Support/ParseDateString.php b/app/Support/ParseDateString.php index 9d4b3d80fe..ae1f566064 100644 --- a/app/Support/ParseDateString.php +++ b/app/Support/ParseDateString.php @@ -386,7 +386,7 @@ class ParseDateString $direction = 0 === strpos($part, '+') ? 1 : 0; $period = $part[strlen($part) - 1]; $number = (int) substr($part, 1, -1); - if (!isset($functions[$direction][$period])) { + if (!array_key_exists($period, $functions[$direction])) { Log::error(sprintf('No method for direction %d and period "%s".', $direction, $period)); continue; } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index fb808e7c9e..90971f9fca 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -24,6 +24,7 @@ namespace FireflyIII\Support; use Cache; use Exception; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Preference; use FireflyIII\User; use Illuminate\Support\Collection; @@ -49,9 +50,10 @@ class Preferences } /** - * @param $name + * @param string $name * * @return bool + * @throws FireflyException */ public function delete(string $name): bool { @@ -62,8 +64,7 @@ class Preferences try { Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); } catch (Exception $e) { - Log::debug(sprintf('Could not delete preference: %s', $e->getMessage())); - // don't care. + throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); } return true; @@ -87,7 +88,7 @@ class Preferences */ public function get(string $name, $default = null): ?Preference { - /** @var User $user */ + /** @var User|null $user */ $user = auth()->user(); if (null === $user) { $preference = new Preference; @@ -107,7 +108,7 @@ class Preferences */ public function getFresh(string $name, $default = null): ?Preference { - /** @var User $user */ + /** @var User|null $user */ $user = auth()->user(); if (null === $user) { $preference = new Preference; @@ -134,7 +135,7 @@ class Preferences $result[$preference->name] = $preference->data; } foreach ($list as $name) { - if (!isset($result[$name])) { + if (!array_key_exists($name, $result)) { $result[$name] = null; } } @@ -148,6 +149,7 @@ class Preferences * @param null|string|int $default * * @return \FireflyIII\Models\Preference|null + * @throws FireflyException */ public function getForUser(User $user, string $name, $default = null): ?Preference { @@ -156,7 +158,7 @@ class Preferences try { $preference->delete(); } catch (Exception $e) { - Log::debug(sprintf('Could not delete preference #%d: %s', $preference->id, $e->getMessage())); + throw new FireflyException(sprintf('Could not delete preference #%d: %s', $preference->id, $e->getMessage()), 0, $e); } $preference = null; } @@ -252,6 +254,7 @@ class Preferences * @param mixed $value * * @return Preference + * @throws FireflyException */ public function setForUser(User $user, string $name, $value): Preference { @@ -264,7 +267,7 @@ class Preferences try { $pref->delete(); } catch (Exception $e) { - Log::error(sprintf('Could not delete preference: %s', $e->getMessage())); + throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); } return new Preference; @@ -272,20 +275,7 @@ class Preferences if (null === $value) { return new Preference; } - - if (null !== $pref) { - $pref->data = $value; - $pref->save(); - Cache::forever($fullName, $pref); - - return $pref; - } - - $pref = new Preference; - $pref->name = $name; $pref->data = $value; - $pref->user()->associate($user); - $pref->save(); Cache::forever($fullName, $pref); diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php index d7698ac470..c1665b7fed 100644 --- a/app/Support/Request/ConvertsDataTypes.php +++ b/app/Support/Request/ConvertsDataTypes.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Request; use Carbon\Carbon; +use Carbon\Exceptions\InvalidFormatException; use Exception; use Log; @@ -134,7 +135,7 @@ trait ConvertsDataTypes } /** - * @param $array + * @param mixed $array * * @return array|null */ @@ -172,15 +173,9 @@ trait ConvertsDataTypes if ('yes' === $value) { return true; } - if (1 === $value) { - return true; - } if ('1' === $value) { return true; } - if (true === $value) { - return true; - } return false; } @@ -197,8 +192,11 @@ trait ConvertsDataTypes $result = null; try { $result = $this->get($field) ? new Carbon($this->get($field)) : null; - } catch (Exception $e) { - Log::debug(sprintf('Exception when parsing date. Not interesting: %s', $e->getMessage())); + } catch (InvalidFormatException $e) { + // @ignoreException + } + if (null === $result) { + Log::debug(sprintf('Exception when parsing date "%s".', $this->get($field))); } return $result; @@ -217,10 +215,14 @@ trait ConvertsDataTypes if ('' === $string) { return null; } + $carbon = null; try { $carbon = new Carbon($string); - } catch (Exception $e) { - Log::debug(sprintf('Invalid date: %s: %s', $string, $e->getMessage())); + } catch (InvalidFormatException $e) { + // @ignoreException + } + if (null === $carbon) { + Log::debug(sprintf('Invalid date: %s', $string)); return null; } diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 69e3ce241c..b0792b2740 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -245,10 +245,8 @@ class OperatorQuerySearch implements SearchInterface Log::error(sprintf('Cannot handle node %s', $class)); throw new FireflyException(sprintf('Firefly III search cant handle "%s"-nodes', $class)); case Subquery::class: - /** @var Subquery $searchNode */ // loop all notes in subquery: - /** @var Node $subNode */ - foreach ($searchNode->getNodes() as $subNode) { + foreach ($searchNode->getNodes() as $subNode) { // @phpstan-ignore-line $this->handleSearchNode($subNode); // lets hope its not too recursive! } break; diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 0bb1de0400..19fce854c2 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -200,7 +200,7 @@ class Steam ->orderBy('transaction_journals.date', 'ASC') ->whereNull('transaction_journals.deleted_at') ->get( - [ + [ // @phpstan-ignore-line 'transaction_journals.date', 'transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) AS modified'), @@ -256,7 +256,7 @@ class Steam ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->groupBy('transactions.transaction_currency_id'); - $balances = $query->get(['transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) as sum_for_currency')]); + $balances = $query->get(['transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) as sum_for_currency')]); // @phpstan-ignore-line $return = []; /** @var stdClass $entry */ foreach ($balances as $entry) { @@ -343,7 +343,7 @@ class Steam $set = auth()->user()->transactions() ->whereIn('transactions.account_id', $accounts) ->groupBy(['transactions.account_id', 'transaction_journals.user_id']) - ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); + ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); // @phpstan-ignore-line foreach ($set as $entry) { $date = new Carbon($entry->max_date, 'UTC');