Various nestor-related fixes.

This commit is contained in:
James Cole
2025-05-24 05:40:20 +02:00
parent b7ec7625c0
commit c40229e9fa
63 changed files with 222 additions and 156 deletions

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Account;
use FireflyIII\Models\Location;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\AccountFormRequest;
@@ -87,11 +88,11 @@ class EditController extends Controller
$roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes();
$location = $repository->getLocation($account);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$latitude = $location instanceof Location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = $location instanceof Location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = $location instanceof Location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$canEditCurrency = 0 === $account->piggyBanks()->count();
$hasLocation = null !== $location;
$hasLocation = $location instanceof Location;
$locations = [
'location' => [
'latitude' => old('location_latitude') ?? $latitude,

View File

@@ -94,7 +94,7 @@ class ReconcileController extends Controller
// get start and end
if (null === $start && null === $end) {
if (!$start instanceof Carbon && !$end instanceof Carbon) {
/** @var Carbon $start */
$start = clone session('start', app('navigation')->startOfPeriod(new Carbon(), $range));

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Auth;
use function Safe\parse_url;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\User\UserRepositoryInterface;
@@ -101,7 +102,7 @@ class ForgotPasswordController extends Controller
*/
private function validateHost(): void
{
$configuredHost = \Safe\parse_url((string) config('app.url'), PHP_URL_HOST);
$configuredHost = parse_url((string) config('app.url'), PHP_URL_HOST);
if (false === $configuredHost || null === $configuredHost) {
throw new FireflyException('Please set a valid and correct Firefly III URL in the APP_URL environment variable.');
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Auth;
use FireflyIII\User;
use Cookie;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\Security\UnknownUserAttemptedLogin;
@@ -130,11 +131,11 @@ class LoginController extends Controller
app('log')->warning('Login attempt failed.');
$username = (string) $request->get($this->username());
$user = $this->repository->findByEmail($username);
if (null === $user) {
if (!$user instanceof User) {
// send event to owner.
event(new UnknownUserAttemptedLogin($username));
}
if (null !== $user) {
if ($user instanceof User) {
event(new UserAttemptedLogin($user));
}
@@ -198,7 +199,7 @@ class LoginController extends Controller
// also logout current 2FA tokens.
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
\Cookie::forget($cookieName);
Cookie::forget($cookieName);
$this->guard()->logout();
@@ -252,7 +253,7 @@ class LoginController extends Controller
$storeInCookie = config('google2fa.store_in_cookie', false);
if (false !== $storeInCookie) {
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
\Cookie::queue(\Cookie::make($cookieName, 'invalid-'.time()));
Cookie::queue(Cookie::make($cookieName, 'invalid-'.time()));
}
$usernameField = $this->username();

View File

@@ -143,13 +143,13 @@ class BudgetLimitController extends Controller
// first search for existing one and update it if necessary.
$currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id'));
$budget = $this->repository->find((int) $request->get('budget_id'));
if (null === $currency || null === $budget) {
if (!$currency instanceof TransactionCurrency || !$budget instanceof Budget) {
throw new FireflyException('No valid currency or budget.');
}
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
if (null === $start || null === $end) {
if (!$start instanceof Carbon || !$end instanceof Carbon) {
return response()->json([]);
}
@@ -167,7 +167,7 @@ class BudgetLimitController extends Controller
// sanity check on amount:
if (0 === bccomp($amount, '0')) {
if (null !== $limit) {
if ($limit instanceof BudgetLimit) {
$this->blRepository->destroyBudgetLimit($limit);
}
@@ -181,11 +181,11 @@ class BudgetLimitController extends Controller
$amount = bcmul($amount, '-1');
}
if (null !== $limit) {
if ($limit instanceof BudgetLimit) {
$limit->amount = $amount;
$limit->save();
}
if (null === $limit) {
if (!$limit instanceof BudgetLimit) {
$limit = $this->blRepository->store(
[
'budget_id' => $request->get('budget_id'),

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Models\AutoBudget;
use FireflyIII\Enums\AutoBudgetType;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -95,7 +96,7 @@ class EditController extends Controller
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->defaultCurrency->id,
];
if (null !== $autoBudget) {
if ($autoBudget instanceof AutoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
if (is_array($amount)) {
$amount = '0';

View File

@@ -316,7 +316,7 @@ class IndexController extends Controller
foreach ($budgetIds as $index => $budgetId) {
$budgetId = (int) $budgetId;
$budget = $repository->find($budgetId);
if (null !== $budget) {
if ($budget instanceof Budget) {
app('log')->debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));
$repository->setBudgetOrder($budget, $index + 1);
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Budget;
use FireflyIII\Models\TransactionJournal;
use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -90,7 +91,7 @@ class ShowController extends Controller
// get first journal ever to set off the budget period overview.
$first = $this->journalRepos->firstNull();
$firstDate = null !== $first ? $first->date : $start;
$firstDate = $first instanceof TransactionJournal ? $first->date : $start;
$periods = $this->getNoBudgetPeriodOverview($firstDate, $end);
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
@@ -115,7 +116,7 @@ class ShowController extends Controller
{
$subTitle = (string) trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$start = $first instanceof TransactionJournal ? $first->date : new Carbon();
$end = today(config('app.timezone'));
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Models\TransactionJournal;
use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -119,7 +120,7 @@ class NoCategoryController extends Controller
app('log')->debug('Start of noCategory()');
$subTitle = (string) trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$start = $first instanceof TransactionJournal ? $first->date : new Carbon();
$end = today(config('app.timezone'));
app('log')->debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
use function Safe\json_encode;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
@@ -468,14 +469,14 @@ class AccountController extends Controller
Log::debug('Balances exist at:');
foreach ($range as $key => $value) {
$newRange[] = ['date' => $key, 'info' => $value];
Log::debug(sprintf('%d - %s (%s)', count($newRange) - 1, $key, \Safe\json_encode($value)));
Log::debug(sprintf('%d - %s (%s)', count($newRange) - 1, $key, json_encode($value)));
}
$carbon = Carbon::createFromFormat('Y-m-d', $newRange[0]['date'])->endOfDay();
Log::debug(sprintf('Start of loop, $carbon is %s', $carbon->format('Y-m-d H:i:s')));
while ($end->gte($current)) {
$momentBalance = $previous;
// $theDate = $current->format('Y-m-d');
Log::debug(sprintf('Now at %s, with momentBalance %s', $current->format('Y-m-d H:i:s'), \Safe\json_encode($momentBalance)));
Log::debug(sprintf('Now at %s, with momentBalance %s', $current->format('Y-m-d H:i:s'), json_encode($momentBalance)));
// loop over the array with balances, find one that is earlier or on the same day.
while ($carbon->lte($current) && array_key_exists($expectedIndex, $newRange)) {
@@ -490,7 +491,7 @@ class AccountController extends Controller
$carbon = Carbon::createFromFormat('Y-m-d', $newRange[$expectedIndex]['date'])->endOfDay();
}
}
Log::debug(sprintf('momentBalance is now %s', \Safe\json_encode($momentBalance)));
Log::debug(sprintf('momentBalance is now %s', json_encode($momentBalance)));
$return = $this->updateChartKeys($return, $momentBalance);
$previous = $momentBalance;

View File

@@ -202,7 +202,7 @@ class BudgetController extends Controller
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$budgetLimitId = $budgetLimit instanceof BudgetLimit ? $budgetLimit->id : 0;
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($this->convertToNative);
@@ -211,7 +211,7 @@ class BudgetController extends Controller
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
if ($budgetLimit instanceof BudgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setNormalCurrency($budgetLimit->transactionCurrency);
@@ -285,7 +285,7 @@ class BudgetController extends Controller
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$budgetLimitId = $budgetLimit instanceof BudgetLimit ? $budgetLimit->id : 0;
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($this->convertToNative);
@@ -293,7 +293,7 @@ class BudgetController extends Controller
$cache->addProperty('chart.budget.expense-category');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
if ($budgetLimit instanceof BudgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setNormalCurrency($budgetLimit->transactionCurrency);
@@ -367,7 +367,7 @@ class BudgetController extends Controller
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id;
$budgetLimitId = $budgetLimit instanceof BudgetLimit ? $budgetLimit->id : 0;
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
@@ -375,7 +375,7 @@ class BudgetController extends Controller
$cache->addProperty('chart.budget.expense-expense');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
if ($budgetLimit instanceof BudgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->setNormalCurrency($budgetLimit->transactionCurrency);
@@ -529,7 +529,7 @@ class BudgetController extends Controller
// get budget limit in this period for this currency.
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
if (null !== $limit) {
if ($limit instanceof BudgetLimit) {
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
}

View File

@@ -159,7 +159,7 @@ class CategoryController extends Controller
$income = [];
$expenses = [];
$categoryId = 0;
if (null === $category) {
if (!$category instanceof Category) {
/** @var NoCategoryRepositoryInterface $noCatRepository */
$noCatRepository = app(NoCategoryRepositoryInterface::class);
@@ -168,7 +168,7 @@ class CategoryController extends Controller
$income = $noCatRepository->listIncome($start, $end, $accounts);
}
if (null !== $category) {
if ($category instanceof Category) {
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$categoryId = $category->id;

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use function Safe\realpath;
use function Safe\ini_get;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Amount;
use FireflyIII\Support\Facades\Steam;
@@ -83,15 +85,15 @@ abstract class Controller extends BaseController
if ('true' === request()->get('force_default_layout') && 'v2' === config('view.layout')) {
//config('view.layout','v1');
Config::set('view.layout', 'v1');
View::getFinder()->setPaths([\Safe\realpath(base_path('resources/views'))]); // @phpstan-ignore-line
View::getFinder()->setPaths([realpath(base_path('resources/views'))]); // @phpstan-ignore-line
}
View::share('authGuard', $authGuard);
View::share('logoutUrl', $logoutUrl);
// upload size
$maxFileSize = Steam::phpBytes((string) \Safe\ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes((string) \Safe\ini_get('post_max_size'));
$maxFileSize = Steam::phpBytes((string) ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes((string) ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
View::share('uploadSize', $uploadSize);

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use function Safe\file_get_contents;
use function Safe\ini_get;
use Carbon\Carbon;
use Exception;
use FireflyIII\Enums\AccountTypeEnum;
@@ -108,7 +110,7 @@ class DebugController extends Controller
try {
Artisan::call('twig:clean');
} catch (\Exception $e) { // intentional generic exception
} catch (Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e);
}
@@ -139,7 +141,7 @@ class DebugController extends Controller
if ($handler instanceof RotatingFileHandler) {
$logFile = $handler->getUrl();
if (null !== $logFile && file_exists($logFile)) {
$logContent = \Safe\file_get_contents($logFile);
$logContent = file_get_contents($logFile);
}
}
}
@@ -164,8 +166,8 @@ class DebugController extends Controller
private function getSystemInformation(): array
{
$maxFileSize = Steam::phpBytes((string) \Safe\ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes((string) \Safe\ini_get('post_max_size'));
$maxFileSize = Steam::phpBytes((string) ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes((string) ini_get('post_max_size'));
$drivers = DB::availableDrivers();
$currentDriver = DB::getDriverName();
@@ -177,8 +179,8 @@ class DebugController extends Controller
'interface' => \PHP_SAPI,
'bits' => \PHP_INT_SIZE * 8,
'bcscale' => bcscale(),
'display_errors' => \Safe\ini_get('display_errors'),
'error_reporting' => $this->errorReporting((int) \Safe\ini_get('error_reporting')),
'display_errors' => ini_get('display_errors'),
'error_reporting' => $this->errorReporting((int) ini_get('error_reporting')),
'upload_size' => min($maxFileSize, $maxPostSize),
'all_drivers' => $drivers,
'current_driver' => $currentDriver,
@@ -197,19 +199,19 @@ class DebugController extends Controller
try {
if (file_exists('/var/www/counter-main.txt')) {
$return['build'] = trim((string) \Safe\file_get_contents('/var/www/counter-main.txt'));
$return['build'] = trim((string) file_get_contents('/var/www/counter-main.txt'));
app('log')->debug(sprintf('build is now "%s"', $return['build']));
}
} catch (\Exception $e) {
} catch (Exception $e) {
app('log')->debug('Could not check build counter, but thats ok.');
app('log')->warning($e->getMessage());
}
try {
if (file_exists('/var/www/build-date-main.txt')) {
$return['build_date'] = trim((string) \Safe\file_get_contents('/var/www/build-date-main.txt'));
$return['build_date'] = trim((string) file_get_contents('/var/www/build-date-main.txt'));
}
} catch (\Exception $e) {
} catch (Exception $e) {
app('log')->debug('Could not check build date, but thats ok.');
app('log')->warning($e->getMessage());
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Export;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Middleware\IsDemoUser;
@@ -84,7 +85,7 @@ class IndexController extends Controller
$firstDate = today(config('app.timezone'));
$firstDate->subYear();
$journal = $this->journalRepository->firstNull();
if (null !== $journal) {
if ($journal instanceof TransactionJournal) {
Log::debug('First journal is NULL, using today() - 1 year.');
$firstDate = clone $journal->date;
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Exception;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Enums\AccountTypeEnum;
@@ -57,7 +58,7 @@ class HomeController extends Controller
/**
* Change index date range.
*
* @throws \Exception
* @throws Exception
*/
public function dateRange(Request $request): JsonResponse
{

View File

@@ -96,7 +96,7 @@ class JavascriptController extends Controller
{
$account = $repository->find((int) $request->get('account'));
$currency = $this->defaultCurrency;
if (null !== $account) {
if ($account instanceof Account) {
$currency = $repository->getAccountCurrency($account) ?? $this->defaultCurrency;
}
$locale = app('steam')->getLocale();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use FireflyIII\Models\AvailableBudget;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
@@ -72,7 +73,7 @@ class BudgetController extends Controller
$available = '0';
$percentage = '0';
if (null !== $availableBudget) {
if ($availableBudget instanceof AvailableBudget) {
$available = $availableBudget->amount;
if (0 !== bccomp($available, '0')) {
$percentage = bcmul(bcdiv($budgeted, $available), '100');

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Throwable;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank;
@@ -89,7 +90,7 @@ class FrontpageController extends Controller
if (0 !== count($info)) {
try {
$html = view('json.piggy-banks', compact('info', 'convertToNative', 'native'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$html = 'Could not render view.';

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -77,7 +78,7 @@ class ReconcileController extends Controller
$amount = '0';
$clearedAmount = '0';
if (null === $start && null === $end) {
if (!$start instanceof Carbon && !$end instanceof Carbon) {
throw new FireflyException('Invalid dates submitted.');
}
if ($end->lt($start)) {
@@ -130,7 +131,7 @@ class ReconcileController extends Controller
try {
$view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('View error: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$view = sprintf('Could not render accounts.reconcile.overview: %s', $e->getMessage());
@@ -183,7 +184,7 @@ class ReconcileController extends Controller
*/
public function transactions(Account $account, ?Carbon $start = null, ?Carbon $end = null)
{
if (null === $start || null === $end) {
if (!$start instanceof Carbon || !$end instanceof Carbon) {
throw new FireflyException('Invalid dates submitted.');
}
if ($end->lt($start)) {
@@ -228,7 +229,7 @@ class ReconcileController extends Controller
'accounts.reconcile.transactions',
compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
)->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$html = sprintf('Could not render accounts.reconcile.transactions: %s', $e->getMessage());

View File

@@ -82,12 +82,12 @@ class RecurrenceController extends Controller
$skip = $skip < 0 || $skip > 31 ? 0 : $skip;
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
if (null === $endDate) {
if (!$endDate instanceof Carbon) {
// safety catch:
$endDate = now()->addYear();
}
if (null === $start || null === $end || null === $firstDate) {
if (!$start instanceof Carbon || !$end instanceof Carbon || !$firstDate instanceof Carbon) {
return response()->json();
}
@@ -161,7 +161,7 @@ class RecurrenceController extends Controller
} catch (InvalidFormatException) {
$date = Carbon::today(config('app.timezone'));
}
if (null === $date) {
if (!$date instanceof Carbon) {
return response()->json();
}
$date->startOfDay();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Throwable;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
@@ -50,7 +51,7 @@ class RuleController extends Controller
try {
$view = view('rules.partials.action', compact('actions', 'count'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$view = 'Could not render view.';
@@ -80,7 +81,7 @@ class RuleController extends Controller
try {
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$view = 'Could not render view.';

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\NewUserFormRequest;
@@ -101,7 +102,7 @@ class NewUserController extends Controller
$currency = $currencyRepository->find((int) $request->input('amount_currency_id_bank_balance'));
// if is null, set to EUR:
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$currency = $currencyRepository->findByCode('EUR');
}
$currencyRepository->enable($currency);

View File

@@ -23,6 +23,10 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use JsonException;
use function Safe\json_decode;
use function Safe\file_get_contents;
use function Safe\strtotime;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency;
use FireflyIII\Events\Test\UserTestNotificationChannel;
@@ -149,8 +153,8 @@ class PreferencesController extends Controller
// list of locales also has "equal" which makes it equal to whatever the language is.
try {
$locales = \Safe\json_decode((string) \Safe\file_get_contents(resource_path(sprintf('locales/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
$locales = json_decode((string) file_get_contents(resource_path(sprintf('locales/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
app('log')->error($e->getMessage());
$locales = [];
}
@@ -271,7 +275,7 @@ class PreferencesController extends Controller
// custom fiscal year
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
$string = \Safe\strtotime((string) $request->get('fiscalYearStart'));
$string = strtotime((string) $request->get('fiscalYearStart'));
if (false !== $string) {
$fiscalYearStart = date('m-d', $string);
Preferences::set('customFiscalYear', $customFiscalYear);

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Profile;
use Cookie;
use Google2FA;
use FireflyIII\Events\Security\DisabledMFA;
use FireflyIII\Events\Security\EnabledMFA;
use FireflyIII\Events\Security\MFANewBackupCodes;
@@ -181,7 +183,7 @@ class MfaController extends Controller
// also logout current 2FA tokens.
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
\Cookie::forget($cookieName);
Cookie::forget($cookieName);
// send user notification.
Log::channel('audit')->info(sprintf('User "%s" has disabled MFA', $user->email));
@@ -214,8 +216,8 @@ class MfaController extends Controller
}
$domain = $this->getDomain();
$secret = \Google2FA::generateSecretKey();
$image = \Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret);
$secret = Google2FA::generateSecretKey();
$image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret);
app('preferences')->set('temp-mfa-secret', $secret);
@@ -271,7 +273,7 @@ class MfaController extends Controller
// make sure MFA is logged out.
if ('testing' !== config('app.env')) {
\Google2FA::logout();
Google2FA::logout();
}
// drop all info from session:

View File

@@ -23,6 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Auth;
use Hash;
use Exception;
use FireflyIII\Events\UserChangedEmail;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Exceptions\ValidationException;
@@ -201,9 +204,9 @@ class ProfileController extends Controller
return redirect(route('profile.change-email'))->withInput();
}
$existing = $repository->findByEmail($newEmail);
if (null !== $existing) {
if ($existing instanceof User) {
// force user logout.
\Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function)
Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function)
$request->session()->invalidate();
session()->flash('success', (string) trans('firefly.email_changed'));
@@ -217,7 +220,7 @@ class ProfileController extends Controller
event(new UserChangedEmail($user, $newEmail, $oldEmail));
// force user logout.
\Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function)
Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function)
$request->session()->invalidate();
session()->flash('success', (string) trans('firefly.email_changed'));
@@ -310,7 +313,7 @@ class ProfileController extends Controller
return redirect(route('profile.index'));
}
if (!\Hash::check($request->get('password'), auth()->user()->password)) {
if (!Hash::check($request->get('password'), auth()->user()->password)) {
session()->flash('error', (string) trans('firefly.invalid_password'));
return redirect(route('profile.delete-account'));
@@ -343,8 +346,8 @@ class ProfileController extends Controller
'email' => auth()->user()->email,
'password' => $request->get('password'),
];
if (\Auth::once($creds)) {
\Auth::logoutOtherDevices($request->get('password'));
if (Auth::once($creds)) {
Auth::logoutOtherDevices($request->get('password'));
session()->flash('info', (string) trans('firefly.other_sessions_logged_out'));
return redirect(route('profile.index'));
@@ -359,7 +362,7 @@ class ProfileController extends Controller
*
* @return Redirector|RedirectResponse
*
* @throws \Exception
* @throws Exception
*/
public function regenerate(Request $request)
{

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -58,7 +59,7 @@ class AccountController extends Controller
try {
$result = view('reports.partials.accounts', compact('accountReport'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -140,7 +141,7 @@ class BalanceController extends Controller
try {
$result = view('reports.partials.balance', compact('report'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\ReportHelperInterface;
@@ -58,7 +59,7 @@ class BillController extends Controller
try {
$result = view('reports.partials.bills', compact('report'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -176,7 +177,7 @@ class BudgetController extends Controller
try {
$result = view('reports.budget.partials.avg-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
app('log')->error($e->getTraceAsString());
@@ -326,7 +327,7 @@ class BudgetController extends Controller
try {
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
@@ -377,7 +378,7 @@ class BudgetController extends Controller
try {
$result = view('reports.budget.partials.top-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -295,7 +296,7 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.avg-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -345,7 +346,7 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.avg-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -527,7 +528,7 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
@@ -599,7 +600,7 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
@@ -639,7 +640,7 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.categories', compact('report'))->render();
$cache->store($result);
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
@@ -687,7 +688,7 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.top-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -735,7 +736,7 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.top-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -102,7 +103,7 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.avg-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -152,7 +153,7 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.avg-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -429,7 +430,7 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.top-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -477,7 +478,7 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.top-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -78,7 +79,7 @@ class OperationsController extends Controller
try {
$result = view('reports.partials.income-expenses', compact('report', 'type'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
@@ -112,7 +113,7 @@ class OperationsController extends Controller
try {
$result = view('reports.partials.income-expenses', compact('report', 'type'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
@@ -167,7 +168,7 @@ class OperationsController extends Controller
try {
$result = view('reports.partials.operations', compact('sums'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.operations: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -292,7 +293,7 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.avg-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -342,7 +343,7 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.avg-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -490,7 +491,7 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.top-expenses', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
@@ -538,7 +539,7 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.top-income', compact('result'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use FireflyIII\Models\Rule;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RuleFormRequest;
@@ -128,7 +129,7 @@ class CreateController extends Controller
// title depends on whether or not there is a rule group:
$subTitle = (string) trans('firefly.make_new_rule_no_group');
if (null !== $ruleGroup) {
if ($ruleGroup instanceof RuleGroup) {
$subTitle = (string) trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
}
@@ -252,7 +253,7 @@ class CreateController extends Controller
{
$ruleId = (int) $request->get('id');
$rule = $this->ruleRepos->find($ruleId);
if (null !== $rule) {
if ($rule instanceof Rule) {
$this->ruleRepos->duplicate($rule);
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use Throwable;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RuleFormRequest;
@@ -177,7 +178,7 @@ class EditController extends Controller
'triggers' => $triggers,
]
)->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
$message = sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage());
app('log')->debug($message);
app('log')->error($e->getTraceAsString());

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Rule;
use Throwable;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -174,7 +175,7 @@ class SelectController extends Controller
try {
$view = view('list.journals-array-tiny', ['groups' => $collection])->render();
} catch (\Throwable $exception) {
} catch (Throwable $exception) {
app('log')->error(sprintf('Could not render view in testTriggers(): %s', $exception->getMessage()));
app('log')->error($exception->getTraceAsString());
$view = sprintf('Could not render list.journals-tiny: %s', $exception->getMessage());
@@ -216,7 +217,7 @@ class SelectController extends Controller
try {
$view = view('list.journals-array-tiny', ['groups' => $collection])->render();
} catch (\Throwable $exception) {
} catch (Throwable $exception) {
$message = sprintf('Could not render view in testTriggersByRule(): %s', $exception->getMessage());
app('log')->error($message);
app('log')->error($exception->getTraceAsString());

View File

@@ -91,7 +91,7 @@ class EditController extends Controller
{
$groupId = (int) $request->get('id');
$ruleGroup = $this->repository->find($groupId);
if (null !== $ruleGroup) {
if ($ruleGroup instanceof RuleGroup) {
$direction = $request->get('direction');
if ('down' === $direction) {
$maxOrder = $this->repository->maxOrder();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\RuleGroup;
use Exception;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\SelectTransactionsRequest;
@@ -64,7 +65,7 @@ class ExecutionController extends Controller
/**
* Execute the given rulegroup on a set of existing transactions.
*
* @throws \Exception
* @throws Exception
*/
public function execute(SelectTransactionsRequest $request, RuleGroup $ruleGroup): RedirectResponse
{

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Throwable;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Support\Search\SearchInterface;
@@ -118,7 +119,7 @@ class SearchController extends Controller
try {
$html = view('search.search', compact('groups', 'hasPages', 'searchTime'))->render();
} catch (\Throwable $e) {
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render search.search: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$html = 'Could not render view.';

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\System;
use Artisan;
use function Safe\file_put_contents;
use Cache;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@@ -140,14 +142,14 @@ class InstallController extends Controller
$this->keys();
}
if ('generate-keys' !== $command) {
\Artisan::call($command, $args);
app('log')->debug(\Artisan::output());
Artisan::call($command, $args);
app('log')->debug(Artisan::output());
}
} catch (\Exception $e) { // intentional generic exception
} catch (Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e);
}
// clear cache as well.
\Cache::clear();
Cache::clear();
app('preferences')->mark();
return true;
@@ -169,7 +171,7 @@ class InstallController extends Controller
return;
}
\Safe\file_put_contents($publicKey, (string) $key->getPublicKey());
\Safe\file_put_contents($privateKey, $key->toString('PKCS1'));
file_put_contents($publicKey, (string) $key->getPublicKey());
file_put_contents($privateKey, $key->toString('PKCS1'));
}
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Models\Location;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
@@ -124,10 +125,10 @@ class TagController extends Controller
$subTitleIcon = 'fa-tag';
$location = $this->repository->getLocation($tag);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$latitude = $location instanceof Location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = $location instanceof Location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = $location instanceof Location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = $location instanceof Location;
$locations = [
'location' => [
'latitude' => old('location_latitude') ?? $latitude,
@@ -155,8 +156,8 @@ class TagController extends Controller
{
// start with oldest tag
$first = session('first', today()) ?? today();
$oldestTagDate = null === $repository->oldestTag() ? clone $first : $repository->oldestTag()->date;
$newestTagDate = null === $repository->newestTag() ? today() : $repository->newestTag()->date;
$oldestTagDate = $repository->oldestTag() instanceof Tag ? $repository->oldestTag()->date : clone $first;
$newestTagDate = $repository->newestTag() instanceof Tag ? $repository->newestTag()->date : today();
$oldestTagDate->startOfYear();
$newestTagDate->endOfYear();
$tags = [];
@@ -184,7 +185,7 @@ class TagController extends Controller
foreach ($tags as $tagId) {
$tagId = (int) $tagId;
$tag = $this->repository->find($tagId);
if (null !== $tag) {
if ($tag instanceof Tag) {
$this->repository->destroy($tag);
++$count;
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Models\TransactionCurrency;
use Exception;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
@@ -81,7 +82,7 @@ class ConvertController extends Controller
*
* @return Factory|Redirector|RedirectResponse|View
*
* @throws \Exception
* @throws Exception
*/
public function index(TransactionType $destinationType, TransactionGroup $group)
{
@@ -213,7 +214,7 @@ class ConvertController extends Controller
}
/**
* @throws \Exception
* @throws Exception
*/
private function getLiabilities(): array
{
@@ -237,7 +238,7 @@ class ConvertController extends Controller
}
/**
* @throws \Exception
* @throws Exception
*/
private function getAssetAccounts(): array
{
@@ -342,7 +343,7 @@ class ConvertController extends Controller
$sourceCurrency = $this->accountRepository->getAccountCurrency($source);
$dest = $this->accountRepository->find((int) $destinationId);
$destCurrency = $this->accountRepository->getAccountCurrency($dest);
if (null !== $sourceCurrency && null !== $destCurrency && $sourceCurrency->code !== $destCurrency->code) {
if ($sourceCurrency instanceof TransactionCurrency && $destCurrency instanceof TransactionCurrency && $sourceCurrency->code !== $destCurrency->code) {
$update['currency_id'] = $sourceCurrency->id;
$update['foreign_currency_id'] = $destCurrency->id;
$update['foreign_amount'] = '1'; // not the best solution but at this point the amount is hard to get.

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Models\TransactionGroup;
use function Safe\parse_url;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -65,7 +67,7 @@ class CreateController extends Controller
$groupId = (int) $request->get('id');
if (0 !== $groupId) {
$group = $this->repository->find($groupId);
if (null !== $group) {
if ($group instanceof TransactionGroup) {
/** @var GroupCloneService $service */
$service = app(GroupCloneService::class);
$newGroup = $service->cloneGroup($group);
@@ -116,7 +118,7 @@ class CreateController extends Controller
$accountToTypes = config('firefly.account_to_transaction');
$defaultCurrency = $this->defaultCurrency;
$previousUrl = $this->rememberPreviousUrl('transactions.create.url');
$parts = \Safe\parse_url($previousUrl);
$parts = parse_url((string) $previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUrl = str_replace($search, '', $previousUrl);
if (!is_array($optionalFields)) {

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use function Safe\parse_url;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
@@ -85,7 +86,7 @@ class EditController extends Controller
$defaultCurrency = $this->defaultCurrency;
$cash = $repository->getCashAccount();
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
$parts = \Safe\parse_url($previousUrl);
$parts = parse_url((string) $previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUrl = str_replace($search, '', $previousUrl);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Models\TransactionJournal;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -81,14 +82,14 @@ class IndexController extends Controller
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
if (null === $start) {
if (!$start instanceof Carbon) {
$start = session('start');
$end = session('end');
}
if (null === $end) {
// get last transaction ever?
$last = $this->repository->getLast();
$end = null !== $last ? $last->date : session('end');
$end = $last instanceof TransactionJournal ? $last->date : session('end');
}
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
@@ -97,7 +98,7 @@ class IndexController extends Controller
$subTitle = (string) trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$firstJournal = $this->repository->firstNull();
$startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date;
$startPeriod = $firstJournal instanceof TransactionJournal ? $firstJournal->date : new Carbon();
$endPeriod = clone $end;
$periods = $this->getTransactionPeriodOverview($objectType, $startPeriod, $endPeriod);
@@ -132,9 +133,9 @@ class IndexController extends Controller
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$path = route('transactions.index.all', [$objectType]);
$first = $this->repository->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$start = $first instanceof TransactionJournal ? $first->date : new Carbon();
$last = $this->repository->getLast();
$end = null !== $last ? $last->date : today(config('app.timezone'));
$end = $last instanceof TransactionJournal ? $last->date : today(config('app.timezone'));
$subTitle = (string) trans('firefly.all_'.$objectType);
/** @var GroupCollectorInterface $collector */

View File

@@ -113,7 +113,7 @@ class LinkController extends Controller
app('log')->debug('We are here (store)');
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
if (null === $other) {
if (!$other instanceof TransactionJournal) {
session()->flash('error', (string) trans('firefly.invalid_link_selection'));
return redirect(route('transactions.show', [$journal->transaction_group_id]));

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use InvalidArgumentException;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
@@ -191,7 +192,7 @@ class MassController extends Controller
private function updateJournal(int $journalId, MassEditJournalRequest $request): void
{
$journal = $this->repository->find($journalId);
if (null === $journal) {
if (!$journal instanceof TransactionJournal) {
throw new FireflyException(sprintf('Trying to edit non-existent or deleted journal #%d', $journalId));
}
$service = app(JournalUpdateService::class);
@@ -231,7 +232,7 @@ class MassController extends Controller
try {
$carbon = Carbon::parse($value[$journalId]);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
Log::warning(sprintf('Could not parse "%s" but dont mind', $value[$journalId]));
Log::warning($e->getMessage());

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\TransactionCurrency;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\CurrencyFormRequest;
@@ -122,7 +123,7 @@ class CreateController extends Controller
}
$redirect = redirect($this->getPreviousUrl('currencies.create.url'));
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$request->session()->flash('success', (string) trans('firefly.created_currency', ['name' => $currency->name]));
Log::channel('audit')->info('Created (POST) currency.', $data);
if (1 === (int) $request->get('create_another')) {