diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.php
index b7276a7823..b7e7a14ced 100644
--- a/app/Handlers/Events/VersionCheckEventHandler.php
+++ b/app/Handlers/Events/VersionCheckEventHandler.php
@@ -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;
- }
-
}
diff --git a/app/Helpers/Filter/TransactionViewFilter.php b/app/Helpers/Filter/TransactionViewFilter.php
index 105226c88f..1c8dc2938a 100644
--- a/app/Helpers/Filter/TransactionViewFilter.php
+++ b/app/Helpers/Filter/TransactionViewFilter.php
@@ -43,6 +43,7 @@ class TransactionViewFilter implements FilterInterface
*
* @param Collection $set
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ *
* @return Collection
*/
public function filter(Collection $set): Collection
diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.php
index aaa738effb..5d33e5ca71 100644
--- a/app/Helpers/Report/BudgetReportHelper.php
+++ b/app/Helpers/Report/BudgetReportHelper.php
@@ -147,6 +147,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
/**
* Calculate the expenses for a budget.
+ *
* @param Budget $budget
* @param BudgetLimit $budgetLimit
* @param Collection $accounts
diff --git a/app/Helpers/Report/PopupReportInterface.php b/app/Helpers/Report/PopupReportInterface.php
index 4fa798f1ec..ca38466bca 100644
--- a/app/Helpers/Report/PopupReportInterface.php
+++ b/app/Helpers/Report/PopupReportInterface.php
@@ -55,6 +55,7 @@ interface PopupReportInterface
/**
* Group by budget.
+ *
* @param Budget $budget
* @param array $attributes
*
diff --git a/app/Helpers/Update/UpdateTrait.php b/app/Helpers/Update/UpdateTrait.php
new file mode 100644
index 0000000000..64a02b4a51
--- /dev/null
+++ b/app/Helpers/Update/UpdateTrait.php
@@ -0,0 +1,131 @@
+.
+ */
+
+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;
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php
index d004c440aa..8cbdbc97d2 100644
--- a/app/Http/Controllers/Account/ReconcileController.php
+++ b/app/Http/Controllers/Account/ReconcileController.php
@@ -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];
diff --git a/app/Http/Controllers/Admin/ConfigurationController.php b/app/Http/Controllers/Admin/ConfigurationController.php
index f38c2263a8..2e0bd3aa87 100644
--- a/app/Http/Controllers/Admin/ConfigurationController.php
+++ b/app/Http/Controllers/Admin/ConfigurationController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpUndefinedClassInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Admin;
diff --git a/app/Http/Controllers/Admin/UpdateController.php b/app/Http/Controllers/Admin/UpdateController.php
index 3b4d442bde..9c4adfa4f7 100644
--- a/app/Http/Controllers/Admin/UpdateController.php
+++ b/app/Http/Controllers/Admin/UpdateController.php
@@ -18,27 +18,24 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @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]);
}
}
diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php
index 02be837ae9..1399312fd0 100644
--- a/app/Http/Controllers/Admin/UserController.php
+++ b/app/Http/Controllers/Admin/UserController.php
@@ -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;
}
);
diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php
index bd870e2b45..c9c4d945e0 100644
--- a/app/Http/Controllers/Auth/ForgotPasswordController.php
+++ b/app/Http/Controllers/Auth/ForgotPasswordController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Auth;
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 8b76348ea1..f7015656ed 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @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
}
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 265cd0924d..a7faadb46d 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Auth;
diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php
index fe0040156d..a403866e65 100644
--- a/app/Http/Controllers/Auth/ResetPasswordController.php
+++ b/app/Http/Controllers/Auth/ResetPasswordController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Auth;
diff --git a/app/Http/Controllers/Auth/TwoFactorController.php b/app/Http/Controllers/Auth/TwoFactorController.php
index 1e1d6f6d94..1ad9b126bd 100644
--- a/app/Http/Controllers/Auth/TwoFactorController.php
+++ b/app/Http/Controllers/Auth/TwoFactorController.php
@@ -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);
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index b0ae134570..3d33c9a5f9 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -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'),
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index df6f0d8954..b62589e9b9 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -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();
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index 87af547c89..3f5452b0b5 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -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 */
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 379c4efa8a..1da549de38 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -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;
}
diff --git a/app/Http/Controllers/Chart/PiggyBankController.php b/app/Http/Controllers/Chart/PiggyBankController.php
index bf6d1df692..1060f64f63 100644
--- a/app/Http/Controllers/Chart/PiggyBankController.php
+++ b/app/Http/Controllers/Chart/PiggyBankController.php
@@ -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;
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index d343926732..0ecaf69901 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -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]));
}
}
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
index 1caf4925df..3ec6ee504d 100644
--- a/app/Http/Controllers/DebugController.php
+++ b/app/Http/Controllers/DebugController.php
@@ -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);
diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php
index a4fcf0a520..bb5ec06a04 100644
--- a/app/Http/Controllers/HelpController.php
+++ b/app/Http/Controllers/HelpController.php
@@ -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;
diff --git a/app/Http/Controllers/Import/IndexController.php b/app/Http/Controllers/Import/IndexController.php
index 72c422caad..4853c13e7f 100644
--- a/app/Http/Controllers/Import/IndexController.php
+++ b/app/Http/Controllers/Import/IndexController.php
@@ -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);
diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.php
index 8a9ce1d851..8cae35eb92 100644
--- a/app/Http/Controllers/Import/JobStatusController.php
+++ b/app/Http/Controllers/Import/JobStatusController.php
@@ -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]
);
diff --git a/app/Http/Controllers/Import/PrerequisitesController.php b/app/Http/Controllers/Import/PrerequisitesController.php
index d0e4d5bbd6..0be0e864bb 100644
--- a/app/Http/Controllers/Import/PrerequisitesController.php
+++ b/app/Http/Controllers/Import/PrerequisitesController.php
@@ -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]));
diff --git a/app/Http/Controllers/Json/AutoCompleteController.php b/app/Http/Controllers/Json/AutoCompleteController.php
index 6ff6c92e1d..87a8204244 100644
--- a/app/Http/Controllers/Json/AutoCompleteController.php
+++ b/app/Http/Controllers/Json/AutoCompleteController.php
@@ -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;
}
diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php
index e61c522daf..8c8750cefc 100644
--- a/app/Http/Controllers/Json/BoxController.php
+++ b/app/Http/Controllers/Json/BoxController.php
@@ -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);
}
diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php
index 0f30b1c9d7..f69116d77c 100644
--- a/app/Http/Controllers/Popup/ReportController.php
+++ b/app/Http/Controllers/Popup/ReportController.php
@@ -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;
diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php
index 52d3c79ffc..734c1d301f 100644
--- a/app/Http/Controllers/PreferencesController.php
+++ b/app/Http/Controllers/PreferencesController.php
@@ -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 = [];
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index fc02ea3c55..e7cbbf9f46 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -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);
diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php
index d7f02b5071..e2c75c1e8a 100644
--- a/app/Http/Controllers/Recurring/IndexController.php
+++ b/app/Http/Controllers/Recurring/IndexController.php
@@ -18,7 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
-
+/** @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));
diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.php
index 485b0d6842..4869ac785e 100644
--- a/app/Http/Controllers/Report/ExpenseController.php
+++ b/app/Http/Controllers/Report/ExpenseController.php
@@ -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;
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index 2b4bff068d..b1e5c00242 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -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);
}
}
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php
index 4ec76ebee9..655a4ae34d 100644
--- a/app/Http/Controllers/RuleController.php
+++ b/app/Http/Controllers/RuleController.php
@@ -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',
[
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index 26074416c4..247ef130e3 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @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'));
}
/**
diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php
index aeac8035ea..3c49398d12 100644
--- a/app/Http/Controllers/Transaction/BulkController.php
+++ b/app/Http/Controllers/Transaction/BulkController.php
@@ -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'))]);
}
diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php
index cd08cf2435..ae043d9c19 100644
--- a/app/Http/Controllers/Transaction/MassController.php
+++ b/app/Http/Controllers/Transaction/MassController.php
@@ -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,
diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php
index 17da1e6fb5..d0358b7a8b 100644
--- a/app/Http/Controllers/Transaction/SingleController.php
+++ b/app/Http/Controllers/Transaction/SingleController.php
@@ -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;
}
diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php
index a0b0014576..600ab2005c 100644
--- a/app/Http/Controllers/Transaction/SplitController.php
+++ b/app/Http/Controllers/Transaction/SplitController.php
@@ -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);
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 7ad5d34f99..d1c67291aa 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -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;
}
diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
index 9c2b7f0131..4e8408129c 100644
--- a/app/Http/Middleware/Authenticate.php
+++ b/app/Http/Middleware/Authenticate.php
@@ -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
}
diff --git a/app/Http/Middleware/AuthenticateTwoFactor.php b/app/Http/Middleware/AuthenticateTwoFactor.php
index 61e747bd02..3e5715377e 100644
--- a/app/Http/Middleware/AuthenticateTwoFactor.php
+++ b/app/Http/Middleware/AuthenticateTwoFactor.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @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');
diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php
index 05f06173fb..6ed1ae7c4f 100644
--- a/app/Http/Middleware/EncryptCookies.php
+++ b/app/Http/Middleware/EncryptCookies.php
@@ -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
- = [
- ];
}
diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.php
index 2f8f73a654..11dfbae057 100644
--- a/app/Http/Middleware/Installer.php
+++ b/app/Http/Middleware/Installer.php
@@ -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'));
}
}
diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php
index 539cf378fe..2ac5804051 100644
--- a/app/Http/Middleware/IsAdmin.php
+++ b/app/Http/Middleware/IsAdmin.php
@@ -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'));
}
diff --git a/app/Http/Middleware/IsDemoUser.php b/app/Http/Middleware/IsDemoUser.php
index f89e05cc30..0eb57d29e1 100644
--- a/app/Http/Middleware/IsDemoUser.php
+++ b/app/Http/Middleware/IsDemoUser.php
@@ -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();
diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php
index baf2ec0b08..2a25ad578c 100644
--- a/app/Http/Middleware/Range.php
+++ b/app/Http/Middleware/Range.php
@@ -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.'
);
diff --git a/app/Http/Middleware/Sandstorm.php b/app/Http/Middleware/Sandstorm.php
index ecbc4b6ac5..f992852ce8 100644
--- a/app/Http/Middleware/Sandstorm.php
+++ b/app/Http/Middleware/Sandstorm.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php
index 6dc4ee301b..f14b84141d 100644
--- a/app/Http/Middleware/TrustProxies.php
+++ b/app/Http/Middleware/TrustProxies.php
@@ -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);
}
}
diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php
index f35cb11c61..16a542dff5 100644
--- a/app/Http/Middleware/VerifyCsrfToken.php
+++ b/app/Http/Middleware/VerifyCsrfToken.php
@@ -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
- = [
- ];
}
diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php
index 24e450fbb1..c09499450b 100644
--- a/app/Http/Requests/JournalFormRequest.php
+++ b/app/Http/Requests/JournalFormRequest.php
@@ -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']));
diff --git a/app/Http/Requests/JournalLinkRequest.php b/app/Http/Requests/JournalLinkRequest.php
index ace48c5032..391e0641f8 100644
--- a/app/Http/Requests/JournalLinkRequest.php
+++ b/app/Http/Requests/JournalLinkRequest.php
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see .
*/
+/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Requests;
diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php
index 7bebfacbce..d1ba493c5b 100644
--- a/app/Http/Requests/RecurrenceFormRequest.php
+++ b/app/Http/Requests/RecurrenceFormRequest.php
@@ -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
diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.php
index edd58743ea..933aad993f 100644
--- a/app/Http/Requests/ReportFormRequest.php
+++ b/app/Http/Requests/ReportFormRequest.php
@@ -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
}
}
diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php
index c293b6237e..26952ac3f2 100644
--- a/app/Http/Requests/Request.php
+++ b/app/Http/Requests/Request.php
@@ -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;
}
diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.php
index 9ef8d49a60..7e35f4016a 100644
--- a/app/Http/Requests/RuleFormRequest.php
+++ b/app/Http/Requests/RuleFormRequest.php
@@ -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),
];
}
}
diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.php
index 5e1a4d062f..ec7b6316a3 100644
--- a/app/Http/Requests/SplitJournalFormRequest.php
+++ b/app/Http/Requests/SplitJournalFormRequest.php
@@ -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'));
}
diff --git a/app/Http/Requests/TagFormRequest.php b/app/Http/Requests/TagFormRequest.php
index 85a7acdb0c..7dab913f9a 100644
--- a/app/Http/Requests/TagFormRequest.php
+++ b/app/Http/Requests/TagFormRequest.php
@@ -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');
}
diff --git a/app/User.php b/app/User.php
index 28525e3ab4..9834e58178 100644
--- a/app/User.php
+++ b/app/User.php
@@ -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
{