Various bug fixes and code cleanup.

This commit is contained in:
James Cole 2022-12-31 06:57:05 +01:00
parent 2b9996b844
commit 27a576ae8a
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
27 changed files with 62 additions and 61 deletions

View File

@ -86,9 +86,6 @@ class BackToJournals extends Command
/**
* @return bool
* @throws FireflyException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function isMigrated(): bool
{

View File

@ -62,7 +62,8 @@ class VerifySecurityAlerts extends Command
// check for security advisories.
$version = config('firefly.version');
$disk = Storage::disk('resources');
if (!$disk->has('alerts.json')) {
// Next line is ignored because it's a Laravel Facade.
if (!$disk->has('alerts.json')) { // @phpstan-ignore-line
Log::debug('No alerts.json file present.');
return 0;

View File

@ -111,7 +111,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
private function generateMessage(Webhook $webhook, Model $model): void
{
$class = get_class($model);
Log::debug(sprintf('Now in generateMessage(#%d, %s#%d)', $webhook->id, $class, $model->id));
// Line is ignored because all of Firefly III's Models have an id property.
Log::debug(sprintf('Now in generateMessage(#%d, %s#%d)', $webhook->id, $class, $model->id)); // @phpstan-ignore-line
$uuid = Uuid::uuid4();
$basicMessage = [
@ -127,7 +128,8 @@ class StandardMessageGenerator implements MessageGeneratorInterface
// depends on the model how user_id is set:
switch ($class) {
default:
Log::error(sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id));
// Line is ignored because all of Firefly III's Models have an id property.
Log::error(sprintf('Webhook #%d was given %s#%d to deal with but can\'t extract user ID from it.', $webhook->id, $class, $model->id)); // @phpstan-ignore-line
return;
case TransactionGroup::class:

View File

@ -64,8 +64,6 @@ class UserEventHandler
* This method will bestow upon a user the "owner" role if he is the first user in the system.
*
* @param RegisteredUser $event
*
* @return bool
*/
public function attachUserRole(RegisteredUser $event): void
{
@ -83,8 +81,6 @@ class UserEventHandler
* Fires to see if a user is admin.
*
* @param Login $event
*
* @return bool
*/
public function checkSingleUserIsAdmin(Login $event): void
{
@ -113,7 +109,6 @@ class UserEventHandler
/**
* @param RegisteredUser $event
* @return bool
*/
public function createExchangeRates(RegisteredUser $event): void
{
@ -124,7 +119,6 @@ class UserEventHandler
/**
* @param RegisteredUser $event
*
* @return bool
* @throws FireflyException
*/
public function createGroupMembership(RegisteredUser $event): void
@ -330,7 +324,6 @@ class UserEventHandler
{
Log::debug('Now in storeUserIPAddress');
$user = $event->user;
/** @var array $preference */
if ($user->hasRole('demo')) {
Log::debug('Do not log demo user logins');
@ -338,6 +331,7 @@ class UserEventHandler
}
try {
/** @var array $preference */
$preference = app('preferences')->getForUser($user, 'login_ip_history', [])->data;
} catch (FireflyException $e) {
// don't care.

View File

@ -232,10 +232,10 @@ class AttachmentHelper implements AttachmentHelperInterface
$validation = $this->validateUpload($file, $model);
$attachment = null;
if (false !== $validation) {
$class = get_class($model);
$user = $model->user;
if (PiggyBank::class === $class) {
$user = $model->account->user;
$user = $model->user; // @phpstan-ignore-line
// ignore lines about polymorphic calls.
if ($model instanceof PiggyBank) {
$user = $model->account->user; // @phpstan-ignore-line
}
$attachment = new Attachment(); // create Attachment object.
@ -372,11 +372,12 @@ class AttachmentHelper implements AttachmentHelperInterface
$name = $file->getClientOriginalName();
$class = get_class($model);
$count = 0;
if (PiggyBank::class === $class) {
$count = $model->account->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
// ignore lines about polymorphic calls.
if ($model instanceof PiggyBank) {
$count = $model->account->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); // @phpstan-ignore-line
}
if (PiggyBank::class !== $class) {
$count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
if ($model instanceof PiggyBank) {
$count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); // @phpstan-ignore-line
}
$result = false;
if ($count > 0) {

View File

@ -517,19 +517,22 @@ class GroupCollector implements GroupCollectorInterface
$groupArray = [
'id' => (int)$augumentedJournal->transaction_group_id,
'user_id' => (int)$augumentedJournal->user_id,
'title' => $augumentedJournal->transaction_group_title,
// Field transaction_group_title was added by the query.
'title' => $augumentedJournal->transaction_group_title, // @phpstan-ignore-line
'transaction_type' => $parsedGroup['transaction_type_type'],
'count' => 1,
'sums' => [],
'transactions' => [],
];
$journalId = (int)$augumentedJournal->transaction_journal_id;
// Field transaction_journal_id was added by the query.
$journalId = (int)$augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
$groupArray['transactions'][$journalId] = $parsedGroup;
$groups[$groupId] = $groupArray;
continue;
}
// or parse the rest.
$journalId = (int)$augumentedJournal->transaction_journal_id;
// Field transaction_journal_id was added by the query.
$journalId = (int)$augumentedJournal->transaction_journal_id; // @phpstan-ignore-line
if (array_key_exists($journalId, $groups[$groupId]['transactions'])) {
// append data to existing group + journal (for multiple tags or multiple attachments)
$groups[$groupId]['transactions'][$journalId] = $this->mergeTags($groups[$groupId]['transactions'][$journalId], $augumentedJournal);
@ -770,7 +773,6 @@ class GroupCollector implements GroupCollectorInterface
{
$currentCollection = $collection;
/**
* @var int $i
* @var Closure $function
*/
foreach ($this->postFilters as $function) {
@ -779,7 +781,7 @@ class GroupCollector implements GroupCollectorInterface
// and save it (or not) in the new collection.
// that new collection is the next current collection
/**
* @var int $index
* @var int $ii
* @var array $item
*/
foreach ($currentCollection as $ii => $item) {

View File

@ -93,7 +93,7 @@ class ReconcileController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null)
{
if (!$this->isEditableAccount($account)) {
return $this->redirectAccountToAccount($account);

View File

@ -91,7 +91,7 @@ class ShowController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null)
{
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));

View File

@ -129,7 +129,7 @@ class ResetPasswordController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function showResetForm(Request $request, $token = null) // @phpstan-ignore-line
public function showResetForm(Request $request, $token = null)
{
$loginProvider = config('firefly.login_provider');
if ('eloquent' !== $loginProvider) {

View File

@ -99,7 +99,7 @@ class IndexController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function index(Request $request, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
public function index(Request $request, Carbon $start = null, Carbon $end = null)
{
Log::debug('Start of IndexController::index()');

View File

@ -87,7 +87,7 @@ class ShowController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line
public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)
{
/** @var Carbon $start */
$start = $start ?? session('start');

View File

@ -83,7 +83,7 @@ class NoCategoryController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function show(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line
public function show(Request $request, Carbon $start = null, Carbon $end = null)
{
Log::debug('Start of noCategory()');
/** @var Carbon $start */

View File

@ -85,7 +85,7 @@ class ShowController extends Controller
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null)
{
/** @var Carbon $start */
$start = $start ?? session('start', Carbon::now()->startOfMonth());

View File

@ -205,7 +205,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@ -273,7 +273,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@ -337,7 +337,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);

View File

@ -300,7 +300,7 @@ class CurrencyController extends Controller
/**
* @param Request $request
* @return RedirectResponse|Redirector
* @return JsonResponse
*/
public function enableCurrency(Request $request): JsonResponse
{

View File

@ -180,7 +180,8 @@ class DebugController extends Controller
// get latest log file:
$logger = Log::driver();
$handlers = $logger->getHandlers();
// PHPstan doesn't recognize the method because of its polymorphic nature.
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
$logContent = '';
foreach ($handlers as $handler) {
if ($handler instanceof RotatingFileHandler) {

View File

@ -54,7 +54,7 @@ class FrontpageController extends Controller
// percentage!
$pct = 0;
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$pct = round(($amount / $piggyBank->targetamount) * 100);
$pct = (int)bcmul(bcdiv($amount, $piggyBank->targetamount), '100');
}
$entry = [

View File

@ -44,7 +44,7 @@ class IntroController extends Controller
*
* @return JsonResponse
*/
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse // @phpstan-ignore-line
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse
{
Log::debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage));
$specificPage = $specificPage ?? '';
@ -105,7 +105,7 @@ class IntroController extends Controller
* @return JsonResponse
* @throws FireflyException
*/
public function postEnable(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line
public function postEnable(string $route, string $specialPage = null): JsonResponse
{
$specialPage = $specialPage ?? '';
$route = str_replace('.', '_', $route);
@ -129,7 +129,7 @@ class IntroController extends Controller
* @return JsonResponse
* @throws FireflyException
*/
public function postFinished(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line
public function postFinished(string $route, string $specialPage = null): JsonResponse
{
$specialPage = $specialPage ?? '';
$key = 'shown_demo_'.$route;

View File

@ -85,7 +85,7 @@ class ReconcileController extends Controller
* @throws FireflyException
* @throws JsonException
*/
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse // @phpstan-ignore-line
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse
{
$startBalance = $request->get('startBalance');
$endBalance = $request->get('endBalance');
@ -226,7 +226,7 @@ class ReconcileController extends Controller
* @throws FireflyException
* @throws JsonException
*/
public function transactions(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
public function transactions(Account $account, Carbon $start = null, Carbon $end = null)
{
if (null === $start || null === $end) {
throw new FireflyException('Invalid dates submitted.');

View File

@ -87,7 +87,7 @@ class DeleteController extends Controller
}
$objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = (string)trans('firefly.delete_'.$objectType, ['description' => $group->title ?? $journal->description]);
$previous = app('steam')->getSafePreviousUrl(route('index'));
$previous = app('steam')->getSafePreviousUrl();
// put previous url in session
Log::debug('Will try to remember previous URL');
$this->rememberPreviousUrl('transactions.delete.url');

View File

@ -66,7 +66,7 @@ class DeleteController extends Controller
*/
public function index(Webhook $webhook)
{
$subTitle = (string)trans('firefly.delete_webhook', ['title' => $webhook->name]);
$subTitle = (string)trans('firefly.delete_webhook', ['title' => $webhook->title]);
$this->rememberPreviousUrl('webhooks.delete.url');
return view('webhooks.delete', compact('webhook', 'subTitle'));

View File

@ -122,7 +122,8 @@ class Authenticate
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
// According to PHPstan the method returns void, but we'll see.
return $this->auth->shouldUse($guard); // @phpstan-ignore-line
}
}

View File

@ -41,7 +41,9 @@ class InvitationMail extends Mailable
/**
* OAuthTokenCreatedMail constructor.
*
* @param string $ipAddress
* @param string $invitee
* @param string $admin
* @param string $url
*/
public function __construct(string $invitee, string $admin, string $url)
{

View File

@ -37,29 +37,29 @@
<h3 class="box-title">{{ title }}</h3>
</div>
<div class="box-body no-padding">
<table class="table table-hover">
<table class="table table-hover" aria-label="A table">
<tbody>
<tr>
<th style="width:40%;">Title</th>
<th scope="row" style="width:40%;">Title</th>
<td>{{ title }}</td>
</tr>
<tr>
<th>{{ $t('list.active') }}</th>
<th scope="row">{{ $t('list.active') }}</th>
<td>
<em class="fa fa-check text-success" v-if="active"></em>
<em class="fa fa-times text-danger" v-if="!active"></em>
</td>
</tr>
<tr>
<th>{{ $t('list.trigger') }}</th>
<th scope="row">{{ $t('list.trigger') }}</th>
<td> {{ trigger }}</td>
</tr>
<tr>
<th>{{ $t('list.response') }}</th>
<th scope="row">{{ $t('list.response') }}</th>
<td> {{ response }}</td>
</tr>
<tr>
<th>{{ $t('list.delivery') }}</th>
<th scope="row">{{ $t('list.delivery') }}</th>
<td> {{ delivery }}</td>
</tr>
</tbody>
@ -82,7 +82,7 @@
<h3 class="box-title">{{ $t('firefly.meta_data') }}</h3>
</div>
<div class="box-body no-padding">
<table class="table table-hover">
<table class="table table-hover" aria-label="A table">
<tbody>
<tr>
<th style="width:40%;">{{ $t('list.url') }}</th>

View File

@ -36,7 +36,7 @@
<h3 class="box-title">{{ 'all_users'|_ }}</h3>
</div>
<div class="box-body no-padding">
<table class="table table-responsive table-condensed sortable">
<table class="table table-responsive table-condensed sortable" aria-label="Table">
<thead>
<tr>
<th data-defaultsign="_19" class="hidden-xs" colspan="2">&nbsp;</th>

View File

@ -1,7 +1,7 @@
<table class="table">
<table class="table" aria-label="Table">
{% for logEntry in logEntries %}
<tr>
<td style="width:20%;">
<th style="width:20%;" scope="row">
{# link to object: #}
{% if 'FireflyIII\\Models\\Rule' == logEntry.changer_type %}
<a href="{{ route('rules.edit', [logEntry.changer_id] ) }}">
@ -9,7 +9,7 @@
{{ logEntry.changer_type|replace({"FireflyIII\\Models\\": ""}) }}
#{{ logEntry.changer_id }}
</a>
</td>
</th>
<td style="width:30%;">
{{ trans('firefly.ale_action_'~logEntry.action) }}
</td>

View File

@ -70,11 +70,11 @@
{% endif %}
</strong>
</p>
<table class="table">
<table class="table" aria-label="Table">
<tbody>
{% for occ in rep.occurrences %}
<tr>
<td>{{ occ.date.isoFormat(trans('config.month_and_date_day_js')) }}</td>
<th scope="row">{{ occ.date.isoFormat(trans('config.month_and_date_day_js')) }}</th>
<td>
{% if not occ.fired %}
<form action="{{ route('recurring.trigger', [recurrence.id]) }}" method="post" style="display: inline;">