mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various code optimalisations.
This commit is contained in:
parent
10492e3b2f
commit
2f2f907ffe
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Events\RequestedVersionCheckStatus;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Update\UpdateTrait;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Services\Github\Object\Release;
|
||||
use FireflyIII\Services\Github\Request\UpdateRequest;
|
||||
@ -39,6 +40,7 @@ use Log;
|
||||
*/
|
||||
class VersionCheckEventHandler
|
||||
{
|
||||
use UpdateTrait;
|
||||
|
||||
/**
|
||||
* Checks with GitHub to see if there is a new version.
|
||||
@ -72,7 +74,7 @@ class VersionCheckEventHandler
|
||||
if ($diff < 604800) {
|
||||
Log::debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));
|
||||
|
||||
return;
|
||||
//return;
|
||||
|
||||
}
|
||||
// last check time was more than a week ago.
|
||||
@ -81,86 +83,17 @@ class VersionCheckEventHandler
|
||||
// have actual permission?
|
||||
if ($permission->data === -1) {
|
||||
// never asked before.
|
||||
session()->flash('info', (string)trans('firefly.check_for_updates_permission', ['link' => route('admin.update-check')]));
|
||||
|
||||
return;
|
||||
//session()->flash('info', (string)trans('firefly.check_for_updates_permission', ['link' => route('admin.update-check')]));
|
||||
//return;
|
||||
}
|
||||
|
||||
$current = config('firefly.version');
|
||||
$latestRelease = $this->getLatestRelease();
|
||||
$versionCheck = $this->versionCheck($latestRelease);
|
||||
$string = '';
|
||||
if ($versionCheck === -2) {
|
||||
$string = (string)trans('firefly.update_check_error');
|
||||
}
|
||||
if ($versionCheck === -1 && null !== $latestRelease) {
|
||||
// there is a new FF version!
|
||||
// has it been released for at least three days?
|
||||
$today = new Carbon;
|
||||
if ($today->diffInDays($latestRelease->getUpdated(), true) > 3) {
|
||||
$monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$string = (string)trans(
|
||||
'firefly.update_new_version_alert',
|
||||
[
|
||||
'your_version' => $current,
|
||||
'new_version' => $latestRelease->getTitle(),
|
||||
'date' => $latestRelease->getUpdated()->formatLocalized($monthAndDayFormat),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
if (0 !== $versionCheck && '' !== $string) {
|
||||
$resultString = $this->parseResult($latestRelease, $versionCheck);
|
||||
if (0 !== $versionCheck && '' !== $resultString) {
|
||||
// flash info
|
||||
session()->flash('info', $string);
|
||||
session()->flash('info', $resultString);
|
||||
}
|
||||
FireflyConfig::set('last_update_check', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object for the latest release from GitHub.
|
||||
*
|
||||
* @return Release|null
|
||||
*/
|
||||
private function getLatestRelease(): ?Release
|
||||
{
|
||||
$return = null;
|
||||
/** @var UpdateRequest $request */
|
||||
$request = app(UpdateRequest::class);
|
||||
try {
|
||||
$request->call();
|
||||
} catch (FireflyException $e) {
|
||||
Log::error(sprintf('Could not check for updates: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
// get releases from array.
|
||||
$releases = $request->getReleases();
|
||||
if (\count($releases) > 0) {
|
||||
// first entry should be the latest entry:
|
||||
/** @var Release $first */
|
||||
$first = reset($releases);
|
||||
$return = $first;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare version and store result.
|
||||
*
|
||||
* @param Release|null $release
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function versionCheck(Release $release = null): int
|
||||
{
|
||||
if (null === $release) {
|
||||
return -2;
|
||||
}
|
||||
$current = (string)config('firefly.version');
|
||||
$check = version_compare($current, $release->getTitle());
|
||||
Log::debug(sprintf('Comparing %s with %s, result is %s', $current, $release->getTitle(), $check));
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ class TransactionViewFilter implements FilterInterface
|
||||
*
|
||||
* @param Collection $set
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function filter(Collection $set): Collection
|
||||
|
@ -147,6 +147,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
|
||||
/**
|
||||
* Calculate the expenses for a budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param Collection $accounts
|
||||
|
@ -55,6 +55,7 @@ interface PopupReportInterface
|
||||
|
||||
/**
|
||||
* Group by budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param array $attributes
|
||||
*
|
||||
|
131
app/Helpers/Update/UpdateTrait.php
Normal file
131
app/Helpers/Update/UpdateTrait.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* UpdateTrait.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Update;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Github\Object\Release;
|
||||
use FireflyIII\Services\Github\Request\UpdateRequest;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Trait UpdateTrait
|
||||
*
|
||||
* @package FireflyIII\Helpers\Update
|
||||
*/
|
||||
trait UpdateTrait
|
||||
{
|
||||
/**
|
||||
* Get object for the latest release from GitHub.
|
||||
*
|
||||
* @return Release|null
|
||||
*/
|
||||
public function getLatestRelease(): ?Release
|
||||
{
|
||||
$return = null;
|
||||
/** @var UpdateRequest $request */
|
||||
$request = app(UpdateRequest::class);
|
||||
try {
|
||||
$request->call();
|
||||
} catch (FireflyException $e) {
|
||||
Log::error(sprintf('Could not check for updates: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
// get releases from array.
|
||||
$releases = $request->getReleases();
|
||||
if (\count($releases) > 0) {
|
||||
// first entry should be the latest entry:
|
||||
/** @var Release $first */
|
||||
$first = reset($releases);
|
||||
$return = $first;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the version check result in a human readable sentence.
|
||||
*
|
||||
* @param Release|null $release
|
||||
* @param int $versionCheck
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function parseResult(Release $release = null, int $versionCheck): string
|
||||
{
|
||||
$current = (string)config('firefly.version');
|
||||
$return = '';
|
||||
if ($versionCheck === -2) {
|
||||
$return = (string)trans('firefly.update_check_error');
|
||||
}
|
||||
if ($versionCheck === -1 && null !== $release) {
|
||||
// there is a new FF version!
|
||||
// has it been released for at least three days?
|
||||
$today = new Carbon;
|
||||
$releaseDate = $release->getUpdated();
|
||||
if ($today->diffInDays($releaseDate, true) > 3) {
|
||||
$monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$return = (string)trans(
|
||||
'firefly.update_new_version_alert',
|
||||
[
|
||||
'your_version' => $current,
|
||||
'new_version' => $release->getTitle(),
|
||||
'date' => $release->getUpdated()->formatLocalized($monthAndDayFormat),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 === $versionCheck) {
|
||||
// you are running the current version!
|
||||
$return = (string)trans('firefly.update_current_version_alert', ['version' => $current]);
|
||||
}
|
||||
if (1 === $versionCheck && null !== $release) {
|
||||
// you are running a newer version!
|
||||
$return = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $release->getTitle()]);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare version and store result.
|
||||
*
|
||||
* @param Release|null $release
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function versionCheck(Release $release = null): int
|
||||
{
|
||||
if (null === $release) {
|
||||
return -2;
|
||||
}
|
||||
$current = (string)config('firefly.version');
|
||||
$latest = $release->getTitle();
|
||||
$check = version_compare($current, $latest);
|
||||
Log::debug(sprintf('Comparing %s with %s, result is %s', $current, $latest, $check));
|
||||
|
||||
return $check;
|
||||
}
|
||||
}
|
@ -254,6 +254,7 @@ class ReconcileController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function submit(ReconciliationStoreRequest $request, JournalRepositoryInterface $repository, Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
@ -275,7 +276,7 @@ class ReconcileController extends Controller
|
||||
$difference = $data['difference'];
|
||||
$source = $reconciliation;
|
||||
$destination = $account;
|
||||
if (bccomp($difference, '0') === 1) {
|
||||
if (1 === bccomp($difference, '0')) {
|
||||
// amount is positive. Add it to reconciliation?
|
||||
$source = $account;
|
||||
$destination = $reconciliation;
|
||||
@ -401,7 +402,7 @@ class ReconcileController extends Controller
|
||||
// amount pos neg influences the accounts:
|
||||
$source = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||
$destination = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||
if (bccomp($submitted['amount'], '0') === 1) {
|
||||
if (1 === bccomp($submitted['amount'], '0')) {
|
||||
// amount is positive, switch accounts:
|
||||
[$source, $destination] = [$destination, $source];
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
@ -18,27 +18,24 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Update\UpdateTrait;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use FireflyIII\Services\Github\Object\Release;
|
||||
use FireflyIII\Services\Github\Request\UpdateRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class HomeController.
|
||||
*/
|
||||
class UpdateController extends Controller
|
||||
{
|
||||
|
||||
use UpdateTrait;
|
||||
|
||||
/**
|
||||
* ConfigurationController constructor.
|
||||
@ -70,9 +67,9 @@ class UpdateController extends Controller
|
||||
$permission = app('fireflyconfig')->get('permission_update_check', -1);
|
||||
$selected = $permission->data;
|
||||
$options = [
|
||||
'-1' => trans('firefly.updates_ask_me_later'),
|
||||
'0' => trans('firefly.updates_do_not_check'),
|
||||
'1' => trans('firefly.updates_enable_check'),
|
||||
-1 => trans('firefly.updates_ask_me_later'),
|
||||
0 => trans('firefly.updates_do_not_check'),
|
||||
1 => trans('firefly.updates_enable_check'),
|
||||
];
|
||||
|
||||
return view('admin.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options'));
|
||||
@ -98,55 +95,16 @@ class UpdateController extends Controller
|
||||
*/
|
||||
public function updateCheck()
|
||||
{
|
||||
$current = config('firefly.version');
|
||||
/** @var UpdateRequest $request */
|
||||
$request = app(UpdateRequest::class);
|
||||
$check = -2;
|
||||
$first = new Release(['id' => '0', 'title' => '0', 'updated' => '2017-01-01', 'content' => '']);
|
||||
$string = '';
|
||||
try {
|
||||
$request->call();
|
||||
$releases = $request->getReleases();
|
||||
// first entry should be the latest entry:
|
||||
/** @var Release $first */
|
||||
$first = reset($releases);
|
||||
$check = version_compare($current, $first->getTitle());
|
||||
FireflyConfig::set('last_update_check', time());
|
||||
} catch (FireflyException $e) {
|
||||
Log::error(sprintf('Could not check for updates: %s', $e->getMessage()));
|
||||
}
|
||||
if ($check === -2) {
|
||||
$string = (string)trans('firefly.update_check_error');
|
||||
}
|
||||
$latestRelease = $this->getLatestRelease();
|
||||
$versionCheck = $this->versionCheck($latestRelease);
|
||||
$resultString = $this->parseResult($latestRelease, $versionCheck);
|
||||
|
||||
if ($check === -1) {
|
||||
// there is a new FF version!
|
||||
// has it been released for more than three days?
|
||||
$today = new Carbon;
|
||||
if ($today->diffInDays($first->getUpdated(), true) > 3) {
|
||||
$string = (string)trans(
|
||||
'firefly.update_new_version_alert',
|
||||
[
|
||||
'your_version' => $current,
|
||||
'new_version' => $first->getTitle(),
|
||||
'date' => $first->getUpdated()->formatLocalized($this->monthAndDayFormat),
|
||||
]
|
||||
);
|
||||
}
|
||||
if ($today->diffInDays($first->getUpdated(), true) <= 3) {
|
||||
// tell user their running the current version.
|
||||
$string = (string)trans('firefly.update_current_version_alert', ['version' => $current]);
|
||||
}
|
||||
}
|
||||
if ($check === 0) {
|
||||
// you are running the current version!
|
||||
$string = (string)trans('firefly.update_current_version_alert', ['version' => $current]);
|
||||
}
|
||||
if ($check === 1) {
|
||||
// you are running a newer version!
|
||||
$string = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $first->getTitle()]);
|
||||
if (0 !== $versionCheck && '' !== $resultString) {
|
||||
// flash info
|
||||
session()->flash('info', $resultString);
|
||||
}
|
||||
FireflyConfig::set('last_update_check', time());
|
||||
|
||||
return response()->json(['result' => $string]);
|
||||
return response()->json(['result' => $resultString]);
|
||||
}
|
||||
}
|
||||
|
@ -120,13 +120,13 @@ class UserController extends Controller
|
||||
|
||||
// add meta stuff.
|
||||
$users->each(
|
||||
function (User $user) {
|
||||
function (User $user) use ($repository) {
|
||||
$list = ['twoFactorAuthEnabled', 'twoFactorAuthSecret'];
|
||||
$preferences = Preferences::getArrayForUser($user, $list);
|
||||
$user->isAdmin = $user->hasRole('owner');
|
||||
$user->isAdmin = $repository->hasRole($user, 'owner');
|
||||
$is2faEnabled = 1 === $preferences['twoFactorAuthEnabled'];
|
||||
$has2faSecret = null !== $preferences['twoFactorAuthSecret'];
|
||||
$user->has2FA = ($is2faEnabled && $has2faSecret) ? true : false;
|
||||
$user->has2FA = ($is2faEnabled && $has2faSecret);
|
||||
$user->prefs = $preferences;
|
||||
}
|
||||
);
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
@ -123,7 +124,7 @@ class LoginController extends Controller
|
||||
public function showLoginForm(Request $request)
|
||||
{
|
||||
$count = DB::table('users')->count();
|
||||
if ($count === 0) {
|
||||
if (0 === $count) {
|
||||
return redirect(route('register')); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
@ -59,7 +59,7 @@ class TwoFactorController extends Controller
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
if (0 === \strlen((string)$secret)) {
|
||||
if ('' === (string)$secret) {
|
||||
throw new FireflyException('Your two factor authentication secret is empty, which it cannot be at this point. Please check the log files.');
|
||||
}
|
||||
$request->session()->flash('two-factor-secret', $secret);
|
||||
|
@ -326,7 +326,7 @@ class BillController extends Controller
|
||||
|
||||
// find first rule group, or create one:
|
||||
$count = $this->ruleGroupRepos->count();
|
||||
if ($count === 0) {
|
||||
if (0 === $count) {
|
||||
$data = [
|
||||
'title' => (string)trans('firefly.rulegroup_for_bills_title'),
|
||||
'description' => (string)trans('firefly.rulegroup_for_bills_description'),
|
||||
|
@ -105,8 +105,8 @@ class BudgetController extends Controller
|
||||
$days = $start->diffInDays($end);
|
||||
$daysInMonth = $start->diffInDays($end);
|
||||
}
|
||||
$days = $days === 0 ? 1 : $days;
|
||||
$daysInMonth = $daysInMonth === 0 ? 1 : $daysInMonth;
|
||||
$days = 0 === $days ? 1 : $days;
|
||||
$daysInMonth = 0 === $daysInMonth ? 1 : $daysInMonth;
|
||||
|
||||
// calculate left in budget:
|
||||
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
|
||||
@ -258,7 +258,7 @@ class BudgetController extends Controller
|
||||
$end = app('navigation')->endOfPeriod($start, $range);
|
||||
} catch (Exception $e) {
|
||||
// start and end are already defined.
|
||||
Log::debug('start and end are already defined.');
|
||||
Log::debug(sprintf('start and end are already defined: %s', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,8 +273,8 @@ class BudgetController extends Controller
|
||||
$days = $start->diffInDays($end);
|
||||
$daysInMonth = $start->diffInDays($end);
|
||||
}
|
||||
$days = $days === 0 ? 1 : $days;
|
||||
$daysInMonth = $daysInMonth === 0 ? 1 : $daysInMonth;
|
||||
$days = 0 === $days ? 1 : $days;
|
||||
$daysInMonth = 0 === $daysInMonth ? 1 : $daysInMonth;
|
||||
|
||||
|
||||
$next = clone $end;
|
||||
@ -489,7 +489,7 @@ class BudgetController extends Controller
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->string('end'));
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$amount = $request->get('amount');
|
||||
$page = $request->integer('page') === 0 ? 1 : $request->integer('page');
|
||||
$page = 0 === $request->integer('page') ? 1 : $request->integer('page');
|
||||
$this->repository->cleanupBudgets();
|
||||
$this->repository->setAvailableBudget($defaultCurrency, $start, $end, $amount);
|
||||
Preferences::mark();
|
||||
|
@ -268,7 +268,7 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
// prep for current period
|
||||
if (0 === \strlen($moment)) {
|
||||
if ('' === $moment) {
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range));
|
||||
/** @var Carbon $end */
|
||||
|
@ -107,7 +107,7 @@ class BudgetController extends Controller
|
||||
|
||||
while ($end >= $current) {
|
||||
$currentEnd = app('navigation')->endOfPeriod($current, $step);
|
||||
if ($step === '1Y') {
|
||||
if ('1Y' === $step) {
|
||||
$currentEnd->subDay(); // @codeCoverageIgnore
|
||||
}
|
||||
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $current, $currentEnd);
|
||||
@ -544,7 +544,7 @@ class BudgetController extends Controller
|
||||
$return[$name] = $row;
|
||||
}
|
||||
}
|
||||
unset($rows, $row);
|
||||
unset($rows);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -105,13 +105,13 @@ class PiggyBankController extends Controller
|
||||
$chartData[$label] = $currentSum;
|
||||
$oldest = app('navigation')->addPeriod($oldest, $step, 0);
|
||||
}
|
||||
/** @var Collection $filtered */
|
||||
/** @var Collection $finalFiltered */
|
||||
$finalFiltered = $set->filter(
|
||||
function (PiggyBankEvent $event) use ($today) {
|
||||
return $event->date->lte($today);
|
||||
}
|
||||
);
|
||||
$finalSum = $filtered->sum('amount');
|
||||
$finalSum = $finalFiltered->sum('amount');
|
||||
$finalLabel = $today->formatLocalized((string)trans('config.month_and_day'));
|
||||
$chartData[$finalLabel] = $finalSum;
|
||||
|
||||
|
@ -157,7 +157,7 @@ class Controller extends BaseController
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$account = $transaction->account;
|
||||
if (\in_array($account->accountType->type, $valid)) {
|
||||
if (in_array($account->accountType->type, $valid, true)) {
|
||||
return redirect(route('accounts.show', [$account->id]));
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class DebugController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
// don't care
|
||||
Log::debug('Called twig:clean.');
|
||||
Log::debug(sprintf('Called twig:clean: %s', $e->getMessage()));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
Log::debug('Call view:clear...');
|
||||
@ -202,7 +202,7 @@ class DebugController extends Controller
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($found === false) {
|
||||
if (false === $found) {
|
||||
$return .= 'touch ' . $route->getName() . '.md;';
|
||||
}
|
||||
}
|
||||
@ -258,7 +258,7 @@ class DebugController extends Controller
|
||||
{
|
||||
$packages = [];
|
||||
$file = \dirname(__DIR__, 3) . '/vendor/composer/installed.json';
|
||||
if (!($file === false) && file_exists($file)) {
|
||||
if (!(false === $file) && file_exists($file)) {
|
||||
// file exists!
|
||||
$content = file_get_contents($file);
|
||||
$json = json_decode($content, true);
|
||||
|
@ -90,10 +90,10 @@ class HelpController extends Controller
|
||||
}
|
||||
|
||||
// get help content from Github:
|
||||
$content = $this->help->getFromGithub($route, $language);
|
||||
$content = $this->help->getFromGitHub($route, $language);
|
||||
|
||||
// content will have 0 length when Github failed. Try en_US when it does:
|
||||
if (0 === \strlen($content)) {
|
||||
if ('' === $content) {
|
||||
$language = 'en_US';
|
||||
|
||||
// also check cache first:
|
||||
@ -104,11 +104,11 @@ class HelpController extends Controller
|
||||
return $content;
|
||||
}
|
||||
|
||||
$content = $this->help->getFromGithub($route, $language);
|
||||
$content = $this->help->getFromGitHub($route, $language);
|
||||
}
|
||||
|
||||
// help still empty?
|
||||
if (0 !== \strlen($content)) {
|
||||
if ('' !== $content) {
|
||||
$this->help->putInCache($route, $language, $content);
|
||||
|
||||
return $content;
|
||||
|
@ -89,10 +89,10 @@ class IndexController extends Controller
|
||||
$hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider));
|
||||
$hasConfig = (bool)config(sprintf('import.has_job_config.%s', $importProvider));
|
||||
// if job provider has no prerequisites:
|
||||
if ($hasPreReq === false) {
|
||||
if (false === $hasPreReq) {
|
||||
Log::debug('Provider has no prerequisites. Continue.');
|
||||
// if job provider also has no configuration:
|
||||
if ($hasConfig === false) {
|
||||
if (false === $hasConfig) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug('Provider needs no configuration for job. Job is ready to start.');
|
||||
$this->repository->updateStatus($importJob, 'ready_to_run');
|
||||
@ -130,7 +130,7 @@ class IndexController extends Controller
|
||||
|
||||
// update job to say "has_prereq".
|
||||
$this->repository->setStatus($importJob, 'has_prereq');
|
||||
if ($hasConfig === false) {
|
||||
if (false === $hasConfig) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug('Provider has no configuration. Job is ready to start.');
|
||||
$this->repository->updateStatus($importJob, 'ready_to_run');
|
||||
@ -208,16 +208,16 @@ class IndexController extends Controller
|
||||
$enabled = (bool)config(sprintf('import.enabled.%s', $providerName));
|
||||
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $providerName));
|
||||
$allowedForUser = (bool)config(sprintf('import.allowed_for_user.%s', $providerName));
|
||||
if ($enabled === false) {
|
||||
if (false === $enabled) {
|
||||
//Log::debug('Provider is not enabled. NEXT!');
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isDemoUser === true && $allowedForDemo === false) {
|
||||
if (true === $isDemoUser && false === $allowedForDemo) {
|
||||
//Log::debug('User is demo and this provider is not allowed for demo user. NEXT!');
|
||||
continue;
|
||||
}
|
||||
if ($isDemoUser === false && $allowedForUser === false && $isDebug === false) {
|
||||
if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) {
|
||||
//Log::debug('User is not demo and this provider is not allowed for such users. NEXT!');
|
||||
continue; // @codeCoverageIgnore
|
||||
}
|
||||
@ -227,7 +227,7 @@ class IndexController extends Controller
|
||||
];
|
||||
$class = (string)config(sprintf('import.prerequisites.%s', $providerName));
|
||||
$result = false;
|
||||
if ($class !== '' && class_exists($class)) {
|
||||
if ('' !== $class && class_exists($class)) {
|
||||
//Log::debug('Will not check prerequisites.');
|
||||
/** @var PrerequisitesInterface $object */
|
||||
$object = app($class);
|
||||
|
@ -90,7 +90,7 @@ class JobStatusController extends Controller
|
||||
'download_config_text' => '',
|
||||
];
|
||||
|
||||
if ($importJob->provider === 'file') {
|
||||
if ('file' === $importJob->provider) {
|
||||
$json['download_config'] = true;
|
||||
$json['download_config_text']
|
||||
= trans('import.should_download_config', ['route' => route('import.job.download', [$importJob->key])]) . ' '
|
||||
@ -101,10 +101,10 @@ class JobStatusController extends Controller
|
||||
if (null !== $importJob->tag_id) {
|
||||
$count = $importJob->tag->transactionJournals->count();
|
||||
}
|
||||
if ($count === 0) {
|
||||
if (0 === $count) {
|
||||
$json['report_txt'] = trans('import.result_no_transactions');
|
||||
}
|
||||
if ($count === 1 && null !== $importJob->tag_id) {
|
||||
if (1 === $count && null !== $importJob->tag_id) {
|
||||
$json['report_txt'] = trans(
|
||||
'import.result_one_transaction', ['route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag]
|
||||
);
|
||||
|
@ -73,7 +73,7 @@ class PrerequisitesController extends Controller
|
||||
{
|
||||
// catch impossible status:
|
||||
$allowed = ['new'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed)) {
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
|
||||
Log::error(sprintf('Job has state "%s" but this Prerequisites::index() only accepts %s', $importJob->status, json_encode($allowed)));
|
||||
session()->flash('error', trans('import.bad_job_status', ['status' => $importJob->status]));
|
||||
|
||||
|
@ -146,7 +146,7 @@ class AutoCompleteController extends Controller
|
||||
$set = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
||||
$filtered = $set->filter(
|
||||
function (Account $account) {
|
||||
if ($account->active === true) {
|
||||
if (true === $account->active) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ class AutoCompleteController extends Controller
|
||||
$set = $repository->getAccountsByType([AccountType::REVENUE]);
|
||||
$filtered = $set->filter(
|
||||
function (Account $account) {
|
||||
if ($account->active === true) {
|
||||
if (true === $account->active) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ class BoxController extends Controller
|
||||
$incomes[$currencyId] = Amount::formatAnything($currency, $incomes[$currencyId] ?? '0', false);
|
||||
$expenses[$currencyId] = Amount::formatAnything($currency, $expenses[$currencyId] ?? '0', false);
|
||||
}
|
||||
if (\count($sums) === 0) {
|
||||
if (0 === \count($sums)) {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$sums[$currency->id] = Amount::formatAnything($currency, '0', false);
|
||||
$incomes[$currency->id] = Amount::formatAnything($currency, '0', false);
|
||||
@ -248,7 +248,7 @@ class BoxController extends Controller
|
||||
$accountCurrency = null;
|
||||
$balance = $balances[$account->id] ?? '0';
|
||||
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||
if ($currencyId !== 0) {
|
||||
if (0 !== $currencyId) {
|
||||
$accountCurrency = $currencyRepos->findNull($currencyId);
|
||||
}
|
||||
if (null === $accountCurrency) {
|
||||
@ -259,7 +259,7 @@ class BoxController extends Controller
|
||||
// to better reflect that this is not money that is actually "yours".
|
||||
$role = (string)$repository->getMetaValue($account, 'accountRole');
|
||||
$virtualBalance = (string)$account->virtual_balance;
|
||||
if ($role === 'ccAsset' && $virtualBalance !== '' && (float)$virtualBalance > 0) {
|
||||
if ('ccAsset' === $role && '' !== $virtualBalance && (float)$virtualBalance > 0) {
|
||||
$balance = bcsub($balance, $virtualBalance);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ class ReportController extends Controller
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function general(Request $request)
|
||||
{
|
||||
@ -229,13 +230,13 @@ class ReportController extends Controller
|
||||
try {
|
||||
$attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new FireflyException('Could not parse start date "' . e($attributes['startDate']) . '".');
|
||||
throw new FireflyException(sprintf('Could not parse start date "%s": %s', $attributes['startDate'], $e->getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
$attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate']);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new FireflyException('Could not parse start date "' . e($attributes['endDate']) . '".');
|
||||
throw new FireflyException(sprintf('Could not parse end date "%s": %s', $attributes['endDate'], $e->getMessage()));
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
@ -24,7 +24,6 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Preferences;
|
||||
use View;
|
||||
@ -85,12 +84,11 @@ class PreferencesController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param UserRepositoryInterface $repository
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function postIndex(Request $request, UserRepositoryInterface $repository)
|
||||
public function postIndex(Request $request)
|
||||
{
|
||||
// front page accounts
|
||||
$frontPageAccounts = [];
|
||||
|
@ -210,14 +210,14 @@ class ProfileController extends Controller
|
||||
|
||||
$this->createOAuthKeys();
|
||||
|
||||
if ($count === 0) {
|
||||
if (0 === $count) {
|
||||
/** @var ClientRepository $repository */
|
||||
$repository = app(ClientRepository::class);
|
||||
$repository->createPersonalAccessClient(null, config('app.name') . ' Personal Access Client', 'http://localhost');
|
||||
}
|
||||
$subTitle = auth()->user()->email;
|
||||
$userId = auth()->user()->id;
|
||||
$enabled2FA = (int)Preferences::get('twoFactorAuthEnabled', 0)->data === 1;
|
||||
$enabled2FA = 1 === (int)Preferences::get('twoFactorAuthEnabled', 0)->data;
|
||||
|
||||
// get access token or create one.
|
||||
$accessToken = Preferences::get('access_token', null);
|
||||
|
@ -18,7 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Recurring;
|
||||
@ -64,13 +64,14 @@ class IndexController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
*/
|
||||
function events(Request $request): JsonResponse
|
||||
public function events(Request $request): JsonResponse
|
||||
{
|
||||
$return = [];
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
@ -187,8 +188,8 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function show(Request $request, Recurrence $recurrence)
|
||||
{
|
||||
$transformer = new RecurrenceTransformer(new ParameterBag);
|
||||
$array = $transformer->transform($recurrence);
|
||||
$transformer = new RecurrenceTransformer(new ParameterBag);
|
||||
$array = $transformer->transform($recurrence);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$transactions = $this->recurring->getTransactions($recurrence, $page, $pageSize);
|
||||
@ -202,7 +203,7 @@ class IndexController extends Controller
|
||||
|
||||
$subTitle = trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);
|
||||
|
||||
return view('recurring.show', compact('recurrence', 'subTitle', 'array','transactions'));
|
||||
return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'transactions'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +217,7 @@ class IndexController extends Controller
|
||||
$date = Carbon::createFromFormat('Y-m-d', $request->get('date'));
|
||||
$preSelected = (string)$request->get('pre_select');
|
||||
$result = [];
|
||||
if ($date > $today || (string)$request->get('past') === 'true') {
|
||||
if ($date > $today || 'true' === (string)$request->get('past')) {
|
||||
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
|
||||
$monthly = sprintf('monthly,%s', $date->day);
|
||||
$dayOfWeek = trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
|
@ -98,7 +98,6 @@ class ExpenseController extends Controller
|
||||
}
|
||||
$together[$categoryId]['grand_total'] = bcadd($spentInfo['grand_total'], $together[$categoryId]['grand_total']);
|
||||
}
|
||||
unset($spentInfo);
|
||||
$result = view('reports.partials.exp-budgets', compact('together'))->render();
|
||||
$cache->store($result);
|
||||
|
||||
@ -146,7 +145,6 @@ class ExpenseController extends Controller
|
||||
}
|
||||
$together[$categoryId]['grand_total'] = bcadd($spentInfo['grand_total'], $together[$categoryId]['grand_total']);
|
||||
}
|
||||
unset($spentInfo);
|
||||
foreach ($earned as $categoryId => $earnedInfo) {
|
||||
if (!isset($together[$categoryId])) {
|
||||
$together[$categoryId]['earned'] = $earnedInfo;
|
||||
|
@ -276,7 +276,7 @@ class ReportController extends Controller
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function options(string $reportType)
|
||||
{
|
||||
@ -426,7 +426,7 @@ class ReportController extends Controller
|
||||
$set = new Collection;
|
||||
$names = $revenue->pluck('name')->toArray();
|
||||
foreach ($expense as $exp) {
|
||||
if (\in_array($exp->name, $names)) {
|
||||
if (in_array($exp->name, $names, true)) {
|
||||
$set->push($exp);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class RuleController extends Controller
|
||||
$oldActions = [];
|
||||
$returnToBill = false;
|
||||
|
||||
if ($request->get('return') === 'true') {
|
||||
if ('true' === $request->get('return')) {
|
||||
$returnToBill = true;
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ class RuleController extends Controller
|
||||
Preferences::mark();
|
||||
|
||||
// redirect to show bill.
|
||||
if ($request->get('return_to_bill') === 'true' && (int)$request->get('bill_id') > 0) {
|
||||
if ('true' === $request->get('return_to_bill') && (int)$request->get('bill_id') > 0) {
|
||||
return redirect(route('bills.show', [(int)$request->get('bill_id')])); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
@ -792,6 +792,7 @@ class RuleController extends Controller
|
||||
private function getTriggersForBill(Bill $bill): array
|
||||
{
|
||||
$triggers = [];
|
||||
/** @noinspection BadExceptionsProcessingInspection */
|
||||
try {
|
||||
$triggers[] = view(
|
||||
'rules.partials.trigger',
|
||||
@ -822,6 +823,7 @@ class RuleController extends Controller
|
||||
'count' => 3,
|
||||
]
|
||||
)->render();
|
||||
|
||||
$triggers[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
@ -226,7 +227,7 @@ class TagController extends Controller
|
||||
|
||||
$sums = $repository->sumsOfTag($tag, $start, $end);
|
||||
|
||||
return view('tags.show', compact('apiKey', 'tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end', 'moment'));
|
||||
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end', 'moment'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,9 +95,9 @@ class BulkController extends Controller
|
||||
{
|
||||
$journalIds = $request->get('journals');
|
||||
$journalIds = \is_array($journalIds) ? $journalIds : [];
|
||||
$ignoreCategory = (int)$request->get('ignore_category') === 1;
|
||||
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
|
||||
$ignoreTags = (int)$request->get('ignore_tags') === 1;
|
||||
$ignoreCategory = 1 === (int)$request->get('ignore_category');
|
||||
$ignoreBudget = 1 === (int)$request->get('ignore_budget');
|
||||
$ignoreTags = 1 === (int)$request->get('ignore_tags');
|
||||
$count = 0;
|
||||
|
||||
foreach ($journalIds as $journalId) {
|
||||
@ -110,20 +110,20 @@ class BulkController extends Controller
|
||||
Log::debug(sprintf('Found journal #%d', $journal->id));
|
||||
|
||||
// update category if not told to ignore
|
||||
if ($ignoreCategory === false) {
|
||||
if (false === $ignoreCategory) {
|
||||
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
||||
|
||||
$this->repository->updateCategory($journal, $request->string('category'));
|
||||
}
|
||||
|
||||
// update budget if not told to ignore (and is withdrawal)
|
||||
if ($ignoreBudget === false) {
|
||||
if (false === $ignoreBudget) {
|
||||
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
||||
$this->repository->updateBudget($journal, $request->integer('budget_id'));
|
||||
}
|
||||
|
||||
// update tags:
|
||||
if ($ignoreTags === false) {
|
||||
if (false === $ignoreTags) {
|
||||
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
||||
$this->repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
|
||||
}
|
||||
|
@ -153,12 +153,12 @@ class MassController extends Controller
|
||||
// transform to array
|
||||
$transactions = $collection->map(
|
||||
function (Transaction $transaction) use ($transformer) {
|
||||
$transaction = $transformer->transform($transaction);
|
||||
$transformed = $transformer->transform($transaction);
|
||||
// make sure amount is positive:
|
||||
$transaction['amount'] = app('steam')->positive((string)$transaction['amount']);
|
||||
$transaction['foreign_amount'] = app('steam')->positive((string)$transaction['foreign_amount']);
|
||||
$transformed['amount'] = app('steam')->positive((string)$transformed['amount']);
|
||||
$transformed['foreign_amount'] = app('steam')->positive((string)$transformed['foreign_amount']);
|
||||
|
||||
return $transaction;
|
||||
return $transformed;
|
||||
}
|
||||
);
|
||||
|
||||
@ -177,7 +177,7 @@ class MassController extends Controller
|
||||
$count = 0;
|
||||
if (\is_array($journalIds)) {
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journal = $repository->find((int)$journalId);
|
||||
$journal = $repository->findNull((int)$journalId);
|
||||
if (null !== $journal) {
|
||||
// get optional fields:
|
||||
$what = strtolower($this->repository->getTransactionType($journal));
|
||||
@ -206,7 +206,7 @@ class MassController extends Controller
|
||||
|
||||
'category_id' => null,
|
||||
'category_name' => $category,
|
||||
'budget_id' => (int)$budgetId,
|
||||
'budget_id' => $budgetId,
|
||||
'budget_name' => null,
|
||||
'source_id' => (int)$sourceAccountId,
|
||||
'source_name' => $sourceAccountName,
|
||||
|
@ -113,13 +113,13 @@ class SingleController extends Controller
|
||||
'budget_id' => $budgetId,
|
||||
'category' => $categoryName,
|
||||
'tags' => $tags,
|
||||
'interest_date' => $journal->getMeta('interest_date'),
|
||||
'book_date' => $journal->getMeta('book_date'),
|
||||
'process_date' => $journal->getMeta('process_date'),
|
||||
'due_date' => $journal->getMeta('due_date'),
|
||||
'payment_date' => $journal->getMeta('payment_date'),
|
||||
'invoice_date' => $journal->getMeta('invoice_date'),
|
||||
'internal_reference' => $journal->getMeta('internal_reference'),
|
||||
'interest_date' => $this->repository->getMetaField($journal, 'interest_date'),
|
||||
'book_date' => $this->repository->getMetaField($journal, 'book_date'),
|
||||
'process_date' => $this->repository->getMetaField($journal, 'process_date'),
|
||||
'due_date' => $this->repository->getMetaField($journal, 'due_date'),
|
||||
'payment_date' => $this->repository->getMetaField($journal, 'payment_date'),
|
||||
'invoice_date' => $this->repository->getMetaField($journal, 'invoice_date'),
|
||||
'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),
|
||||
'notes' => '',
|
||||
];
|
||||
|
||||
@ -143,7 +143,7 @@ class SingleController extends Controller
|
||||
public function create(Request $request, string $what = TransactionType::DEPOSIT)
|
||||
{
|
||||
$what = strtolower($what);
|
||||
$what = $request->old('what') ?? $what;
|
||||
$what = (string)($request->old('what') ?? $what);
|
||||
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
|
||||
$subTitle = trans('form.add_new_' . $what);
|
||||
@ -152,13 +152,13 @@ class SingleController extends Controller
|
||||
$source = (int)$request->get('source');
|
||||
|
||||
// grab old currency ID from old data:
|
||||
$currencyID = (int)$request->old('amount_currency_id_amount');
|
||||
$currencyID = (int)$request->old('amount_currency_id_amount');
|
||||
$preFilled['amount_currency_id_amount'] = $currencyID;
|
||||
|
||||
if (($what === 'withdrawal' || $what === 'transfer') && $source > 0) {
|
||||
if (('withdrawal' === $what || 'transfer' === $what) && $source > 0) {
|
||||
$preFilled['source_id'] = $source;
|
||||
}
|
||||
if ($what === 'deposit' && $source > 0) {
|
||||
if ('deposit' === $what && $source > 0) {
|
||||
$preFilled['destination_id'] = $source;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,6 @@ use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@ -49,9 +48,6 @@ use View;
|
||||
*/
|
||||
class SplitController extends Controller
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $accounts;
|
||||
|
||||
/** @var AttachmentHelperInterface */
|
||||
private $attachments;
|
||||
|
||||
@ -73,7 +69,6 @@ class SplitController extends Controller
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->accounts = app(AccountRepositoryInterface::class);
|
||||
$this->budgets = app(BudgetRepositoryInterface::class);
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
$this->currencies = app(CurrencyRepositoryInterface::class);
|
||||
|
@ -85,7 +85,6 @@ class TransactionController extends Controller
|
||||
$types = config('firefly.transactionTypesByWhat.' . $what);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$path = route('transactions.index', [$what]);
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
@ -183,8 +182,8 @@ class TransactionController extends Controller
|
||||
$order = 0;
|
||||
$ids = array_unique($ids);
|
||||
foreach ($ids as $id) {
|
||||
$journal = $this->repository->find((int)$id);
|
||||
if ($journal && $journal->date->isSameDay($date)) {
|
||||
$journal = $this->repository->findNull((int)$id);
|
||||
if (null !== $journal && $journal->date->isSameDay($date)) {
|
||||
$this->repository->setOrder($journal, $order);
|
||||
++$order;
|
||||
}
|
||||
|
@ -105,7 +105,12 @@ class Authenticate
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException('It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands?');
|
||||
throw new FireflyException(
|
||||
sprintf(
|
||||
'It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands? Error: %s',
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
@ -65,6 +66,7 @@ class AuthenticateTwoFactor
|
||||
return response()->redirectTo(route('login'));
|
||||
}
|
||||
|
||||
|
||||
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
|
||||
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
|
||||
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
||||
|
@ -30,12 +30,4 @@ use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
*/
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
];
|
||||
}
|
||||
|
@ -48,12 +48,12 @@ class Installer
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (env('APP_ENV') === 'testing') {
|
||||
if ('testing' === env('APP_ENV')) {
|
||||
return $next($request);
|
||||
}
|
||||
$url = $request->url();
|
||||
$strpos = stripos($url, '/install');
|
||||
if (!($strpos === false)) {
|
||||
if (!(false === $strpos)) {
|
||||
Log::debug(sprintf('URL is %s, will NOT run installer middleware', $url));
|
||||
|
||||
return $next($request);
|
||||
@ -102,7 +102,7 @@ class Installer
|
||||
*/
|
||||
protected function isAccessDenied(string $message): bool
|
||||
{
|
||||
return !(stripos($message, 'Access denied') === false);
|
||||
return !(false === stripos($message, 'Access denied'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,6 +112,6 @@ class Installer
|
||||
*/
|
||||
protected function noTablesExist(string $message): bool
|
||||
{
|
||||
return !(stripos($message, 'Base table or view not found') === false);
|
||||
return !(false === stripos($message, 'Base table or view not found'));
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@ -52,7 +53,9 @@ class IsAdmin
|
||||
}
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
if (!$user->hasRole('owner')) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if (!$repository->hasRole($user, 'owner')) {
|
||||
return response()->redirectTo(route('home'));
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use FireflyIII\Exceptions\IsDemoUserException;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -48,7 +49,9 @@ class IsDemoUser
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($user->hasRole('demo')) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if ($repository->hasRole($user, 'demo')) {
|
||||
$request->session()->flash('info', (string)trans('firefly.not_available_demo_user'));
|
||||
$current = $request->url();
|
||||
$previous = $request->session()->previousUrl();
|
||||
|
@ -107,7 +107,7 @@ class Range
|
||||
*/
|
||||
private function loseItAll(Request $request)
|
||||
{
|
||||
if (getenv('DB_CONNECTION') === 'sqlite' && getenv('IS_DOCKER') === true) {
|
||||
if ('sqlite' === getenv('DB_CONNECTION') && true === getenv('IS_DOCKER')) {
|
||||
$request->session()->flash(
|
||||
'error', 'You seem to be using SQLite in a Docker container. Don\'t do this. If the container restarts all your data will be gone.'
|
||||
);
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
@ -51,11 +51,11 @@ class TrustProxies extends Middleware
|
||||
{
|
||||
$trustedProxies = env('TRUSTED_PROXIES', null);
|
||||
if (false !== $trustedProxies && null !== $trustedProxies && \strlen($trustedProxies) > 0) {
|
||||
if ($trustedProxies === '*' || $trustedProxies === '**') {
|
||||
$this->proxies = (string)$trustedProxies;
|
||||
if ('*' === $trustedProxies || '**' === $trustedProxies) {
|
||||
$this->proxies = $trustedProxies;
|
||||
|
||||
}
|
||||
if ($trustedProxies !== '*' && $trustedProxies !== '**') {
|
||||
if ('*' !== $trustedProxies && '**' !== $trustedProxies) {
|
||||
$this->proxies = explode(',', $trustedProxies);
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,4 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
*/
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except
|
||||
= [
|
||||
];
|
||||
}
|
||||
|
@ -239,15 +239,15 @@ class JournalFormRequest extends Request
|
||||
$data = $validator->getData();
|
||||
$type = $data['what'] ?? 'invalid';
|
||||
Log::debug(sprintf('Type is %s', $type));
|
||||
if ($type === 'withdrawal') {
|
||||
if ('withdrawal' === $type) {
|
||||
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency));
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
&& 0 !== $selectedCurrency
|
||||
&& 0 !== $accountCurrency
|
||||
) {
|
||||
Log::debug('ADD validation error on native_amount');
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
@ -257,13 +257,13 @@ class JournalFormRequest extends Request
|
||||
}
|
||||
|
||||
// same thing for deposits:
|
||||
if ($type === 'deposit') {
|
||||
if ('deposit' === $type) {
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
&& 0 !== $selectedCurrency
|
||||
&& 0 !== $accountCurrency
|
||||
) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
|
||||
@ -272,7 +272,7 @@ class JournalFormRequest extends Request
|
||||
}
|
||||
|
||||
// and for transfers
|
||||
if ($type === 'transfer') {
|
||||
if ('transfer' === $type) {
|
||||
|
||||
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
@ -282,15 +282,15 @@ class JournalFormRequest extends Request
|
||||
Log::debug(sprintf('Source currency is %d, destination currency is %d', $sourceCurrency, $destinationCurrency));
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
&& 0 !== $sourceCurrency
|
||||
&& 0 !== $destinationCurrency
|
||||
) {
|
||||
$validator->errors()->add('source_amount', trans('validation.numeric_source'));
|
||||
}
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
&& 0 !== $sourceCurrency
|
||||
&& 0 !== $destinationCurrency
|
||||
) {
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric_destination'));
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric', ['attribute' => 'destination_amount']));
|
||||
|
@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
@ -174,16 +174,16 @@ class RecurrenceFormRequest extends Request
|
||||
}
|
||||
|
||||
// if ends after X repetitions, set another rule
|
||||
if ($this->string('repetition_end') === 'times') {
|
||||
if ('times' === $this->string('repetition_end')) {
|
||||
$rules['repetitions'] = 'required|numeric|between:0,254';
|
||||
}
|
||||
// if foreign amount, currency must be different.
|
||||
if ($this->float('foreign_amount') !== 0.0) {
|
||||
if (0.0 !== $this->float('foreign_amount')) {
|
||||
$rules['foreign_currency_id'] = 'exists:transaction_currencies,id|different:transaction_currency_id';
|
||||
}
|
||||
|
||||
// if ends at date X, set another rule.
|
||||
if ($this->string('repetition_end') === 'until_date') {
|
||||
if ('until_date' === $this->string('repetition_end')) {
|
||||
$rules['repeat_until'] = 'required|date|after:' . $tomorrow->format('Y-m-d');
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ class RecurrenceFormRequest extends Request
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ($value === 'daily') {
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
//monthly,17
|
||||
|
@ -125,8 +125,9 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon($parts[1]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date range.', $range));
|
||||
throw new FireflyException(sprintf('"%s" is not a valid date range.', $range));
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
@ -172,8 +173,9 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon($parts[0]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date range.', $range));
|
||||
throw new FireflyException(sprintf('"%s" is not a valid date range.', $range));
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ class Request extends FormRequest
|
||||
*/
|
||||
public function boolean(string $field): bool
|
||||
{
|
||||
if ((string)$this->input($field) === 'true') {
|
||||
if ('true' === (string)$this->input($field)) {
|
||||
return true;
|
||||
}
|
||||
if ((string)$this->input($field) === 'false') {
|
||||
if ('false' === (string)$this->input($field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class RuleFormRequest extends Request
|
||||
$data['rule-triggers'][] = [
|
||||
'name' => $value,
|
||||
'value' => $triggerValues[$index] ?? '',
|
||||
'stop-processing' => (int)($triggerStop[$index] ?? 0) === 1,
|
||||
'stop-processing' => 1 === (int)($triggerStop[$index] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ class RuleFormRequest extends Request
|
||||
$data['rule-actions'][] = [
|
||||
'name' => $value,
|
||||
'value' => $actionValues[$index] ?? '',
|
||||
'stop-processing' => (int)($actionStop[$index] ?? 0) === 1,
|
||||
'stop-processing' => 1 === (int)($actionStop[$index] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class SplitJournalFormRequest extends Request
|
||||
$transactions = $data['transactions'] ?? [];
|
||||
/** @var array $array */
|
||||
foreach ($transactions as $array) {
|
||||
if ($array['destination_id'] !== null && $array['source_id'] !== null && $array['destination_id'] === $array['source_id']) {
|
||||
if (null !== $array['destination_id'] && null !== $array['source_id'] && $array['destination_id'] === $array['source_id']) {
|
||||
$validator->errors()->add('journal_source_id', trans('validation.source_equals_destination'));
|
||||
$validator->errors()->add('journal_destination_id', trans('validation.source_equals_destination'));
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ class TagFormRequest extends Request
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$idRule = '';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag';
|
||||
if (null !== $repository->find((int)$this->get('id'))->id) {
|
||||
if (null !== $repository->findNull((int)$this->get('id'))) {
|
||||
$idRule = 'belongsToUser:tags';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,' . $this->get('id');
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $email
|
||||
* @property bool $isAdmin used in admin user controller.
|
||||
* @property bool $has2FA used in admin user controller.
|
||||
* @property array $prefs used in admin user controller.
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user