Fix for level 2

This commit is contained in:
James Cole 2025-01-03 19:07:29 +01:00
parent 3898c0c0ef
commit 6cd60951ba
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
16 changed files with 41 additions and 15 deletions

View File

@ -1,7 +1,6 @@
parameters:
scanFiles:
- ../_ide_helper_models.php
- ../_ide_helper.php
- ../_ide_helper
paths:
- ../app
- ../database
@ -17,6 +16,11 @@ parameters:
- '#Dynamic call to static method#' # all the Laravel ORM things depend on this.
- identifier: varTag.nativeType
- identifier: varTag.type
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#'
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#'
# - '#Control structures using switch should not be used.#' # switch is fine in some cases.
# - '#with no value type specified in iterable type array#' # remove this rule when all other issues are solved.
# - '#has no value type specified in iterable type array#' # remove this rule when all other issues are solved.

View File

@ -45,7 +45,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* Class Controller.
*
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings("PHPMD.NumberOfChildren")
*/
abstract class Controller extends BaseController
{

View File

@ -48,7 +48,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* Class Controller
*
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings("PHPMD.NumberOfChildren")
*/
class Controller extends BaseController
{

View File

@ -39,7 +39,7 @@ class RemovesEmptyGroups extends Command
/**
* Execute the console command.
*
* @throws Exception;
* @throws Exception
*/
public function handle(): int
{

View File

@ -70,7 +70,6 @@ class RepairsAccountBalances extends Command
private function correctBalanceAmounts(): void
{
return;
AccountBalanceCalculator::recalculateAll(true);
AccountBalanceCalculator::recalculateAll(false);
}
}

View File

@ -240,7 +240,7 @@ class UpgradesVariousCurrencyInformation extends Command
private function isMultiCurrency(Account $account): bool
{
$value = $this->accountRepos->getMetaValue($account, 'is_multi_currency', false);
$value = $this->accountRepos->getMetaValue($account, 'is_multi_currency');
if (false === $value || null === $value) {
return false;
}

View File

@ -36,7 +36,7 @@ class AccountBalance
{
$balance = new self();
$balance->id = (string) random_int(1, 1000);
$balance->name = (string) random_int(1, 1000);
// $balance->name = (string) random_int(1, 1000);
$balance->amount = (string) random_int(1, 1000);
$balance->currencyId = '1';

View File

@ -39,7 +39,7 @@ use Route;
* Class Controller.
*
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings("PHPMD.NumberOfChildren")
*/
abstract class Controller extends BaseController
{

View File

@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Webhook;
use FireflyIII\User;
use Illuminate\Http\Request;
/**
@ -140,8 +141,10 @@ class InterestingMessage
$accountId = $request->get('account_id');
$message = $request->get('message');
/** @var User $user */
$user = auth()->user();
/** @var null|Account $account */
$account = auth()->user()->accounts()->withTrashed()->find($accountId);
$account = $user->accounts()->withTrashed()->find($accountId);
if (null === $account) {
return;

View File

@ -192,7 +192,7 @@ class TransactionJournal extends Model
/**
* Checks if tables are joined.
*/
public static function isJoined(Builder $query, string $table): bool
public static function isJoined(EloquentBuilder $query, string $table): bool
{
$joins = $query->getQuery()->joins;
foreach ($joins as $join) {

View File

@ -285,6 +285,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
$currency->save();
// find the budget:
/** @var Budget|null $budget */
$budget = $this->user->budgets()->find((int) $data['budget_id']);
if (null === $budget) {
throw new FireflyException('200004: Budget does not exist.');

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@ -89,7 +90,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
$events = $journal->piggyBankEvents()->get();
$events->each(
static function (PiggyBankEvent $event): void {
$event->piggyBank = $event->piggyBank()->withTrashed()->first();
$event->piggyBank = PiggyBank::withTrashed()->find($event->piggy_bank_id);
}
);

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties;
use FireflyIII\User;
@ -57,7 +58,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
if (null !== $budget) {
return $budget->id;
}
$budget = $journal->transactions()->first()->budgets()->first();
/** @var Transaction|null $transaction */
$transaction = $journal->transactions()->first();
$budget = $transaction?->budgets()->first();
if (null !== $budget) {
return $budget->id;
}
@ -74,7 +77,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
if (null !== $category) {
return $category->id;
}
$category = $journal->transactions()->first()->categories()->first();
/** @var Transaction|null $transaction */
$transaction = $journal->transactions()->first();
$category = $transaction?->categories()->first();
if (null !== $category) {
return $category->id;
}

View File

@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\UserGroups\Currency;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Support\Collection;
@ -33,6 +34,8 @@ interface CurrencyRepositoryInterface
{
public function currencyInUse(TransactionCurrency $currency): bool;
public function getUserGroup(): UserGroup;
/**
* Currency is in use where exactly.
*/

View File

@ -103,4 +103,12 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
return $object;
}
/**
* @return Collection
*/
#[\Override] public function getAll(): Collection
{
return $this->userGroup->currencyExchangeRates()->get();
}
}

View File

@ -33,6 +33,8 @@ interface ExchangeRateRepositoryInterface
{
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection;
public function getAll(): Collection;
public function getSpecificRateOnDate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): ?CurrencyExchangeRate;
public function deleteRate(CurrencyExchangeRate $rate): void;