Refactor phpstan errors.

This commit is contained in:
James Cole
2023-10-29 17:41:14 +01:00
parent 5e32878d01
commit 12675dd950
60 changed files with 297 additions and 386 deletions

View File

@@ -60,7 +60,7 @@ class AccountTasker implements AccountTaskerInterface
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
$return = [
'accounts' => [],
@@ -160,7 +160,7 @@ class AccountTasker implements AccountTaskerInterface
*/
private function groupExpenseByDestination(array $array): array
{
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currencies = [$defaultCurrency->id => $defaultCurrency,];
@@ -257,7 +257,7 @@ class AccountTasker implements AccountTaskerInterface
*/
private function groupIncomeBySource(array $array): array
{
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currencies = [$defaultCurrency->id => $defaultCurrency,];

View File

@@ -294,7 +294,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
}
$currency->enabled = true;
$currency->save();
@@ -371,7 +371,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
}
// catch unexpected null:
if (null === $currency) {
$currency = $budgetLimit->transactionCurrency ?? app('amount')->getDefaultCurrencyByUser($this->user);
$currency = $budgetLimit->transactionCurrency ?? app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
}
$currency->enabled = true;
$currency->save();

View File

@@ -416,7 +416,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$autoBudget = $this->getAutoBudget($budget);
// grab default currency:
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
if (null === $autoBudget) {
// at this point it's a blind assumption auto_budget_type is 1 or 2.
@@ -847,7 +847,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$currency = $repos->findByCode((string)$data['currency_code']);
}
if (null === $currency) {
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
}
$autoBudget = new AutoBudget();

View File

@@ -220,67 +220,6 @@ class OperationsRepository implements OperationsRepositoryInterface
return $repos->getActiveBudgets();
}
/**
* @param Collection $budgets
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user);
$collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
if ($accounts->count() > 0) {
$collector->setAccounts($accounts);
}
// TODO possible candidate for "get extracted groups" method.
$set = $collector->getGroups();
$return = [];
$total = [];
$currencies = [];
/** @var array $group */
foreach ($set as $group) {
/** @var array $transaction */
foreach ($group['transactions'] as $transaction) {
$code = $transaction['currency_code'];
if (!array_key_exists($code, $currencies)) {
$currencies[$code] = [
'id' => $transaction['currency_id'],
'decimal_places' => $transaction['currency_decimal_places'],
'code' => $transaction['currency_code'],
'name' => $transaction['currency_name'],
'symbol' => $transaction['currency_symbol'],
];
}
$total[$code] = array_key_exists($code, $total) ? bcadd($total[$code], $transaction['amount']) : $transaction['amount'];
}
}
/**
* @var string $code
* @var string $spent
*/
foreach ($total as $code => $spent) {
/** @var TransactionCurrency $currency */
$currency = $currencies[$code];
$return[] = [
'currency_id' => (string)$currency['id'],
'currency_code' => $code,
'currency_name' => $currency['name'],
'currency_symbol' => $currency['symbol'],
'currency_decimal_places' => $currency['decimal_places'],
'amount' => app('steam')->bcround($spent, $currency['decimal_places']),
];
}
return $return;
}
/**
* @param Carbon $start
* @param Carbon $end
@@ -289,7 +228,6 @@ class OperationsRepository implements OperationsRepositoryInterface
* @param TransactionCurrency|null $currency
*
* @return array
* @deprecated
*/
public function sumExpenses(
Carbon $start,

View File

@@ -75,29 +75,12 @@ interface OperationsRepositoryInterface
*/
public function setUser(User | Authenticatable | null $user): void;
/**
* Return multi-currency spent information.
*
* @param Collection $budgets
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array;
/**
* TODO this method was marked as deprecated but I'm not sure why.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $budgets
* @param TransactionCurrency|null $currency
*
* @return array
*
*/

View File

@@ -194,7 +194,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
$accountRepos = app(AccountRepositoryInterface::class);
$accountRepos->setUser($this->user);
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
$piggyBankCurrency = $accountRepos->getAccountCurrency($piggyBank->account) ?? $defaultCurrency;
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));

View File

@@ -401,7 +401,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
{
$return = [];
$journals = $group->transactionJournals->pluck('id')->toArray();
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
$currency = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
$data = PiggyBankEvent::whereIn('transaction_journal_id', $journals)
->with('piggyBank', 'piggyBank.account')
->get(['piggy_bank_events.*']);

View File

@@ -299,10 +299,12 @@ class UserRepository implements UserRepositoryInterface
if (null === $user) {
return false;
}
/** @var Role $userRole */
foreach ($user->roles as $userRole) {
if ($userRole->name === $role) {
return true;
if ($user instanceof User) {
/** @var Role $userRole */
foreach ($user->roles as $userRole) {
if ($userRole->name === $role) {
return true;
}
}
}

View File

@@ -220,7 +220,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
return $userGroup;
}
// count the number of members in the group right now:
$membershipCount = $userGroup->groupMemberships()->distinct()->get(['group_memberships.user_id'])->count();
$membershipCount = $userGroup->groupMemberships()->distinct()->count(['group_memberships.user_id']);
// if it's 1:
if (1 === $membershipCount) {

View File

@@ -27,6 +27,7 @@ namespace FireflyIII\Repositories\UserGroups\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -34,6 +35,14 @@ use Illuminate\Support\Collection;
*/
interface AccountRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param int $accountId
*

View File

@@ -27,6 +27,7 @@ namespace FireflyIII\Repositories\UserGroups\Bill;
use Carbon\Carbon;
use FireflyIII\Models\Bill;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -34,6 +35,13 @@ use Illuminate\Support\Collection;
*/
interface BillRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* TODO duplicate of other repos
* Add correct order to bills.

View File

@@ -26,12 +26,19 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Budget;
use Carbon\Carbon;
use FireflyIII\User;
/**
* Interface AvailableBudgetRepositoryInterface
*/
interface AvailableBudgetRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param Carbon $start
* @param Carbon $end

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Budget;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -32,6 +33,12 @@ use Illuminate\Support\Collection;
*/
interface BudgetRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @return Collection
*/

View File

@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Budget;
use Carbon\Carbon;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -33,6 +34,13 @@ use Illuminate\Support\Collection;
*/
interface OperationsRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* This method returns a list of all the withdrawal transaction journals (as arrays) set in that period
* which have the specified budget set to them. It's grouped per currency, with as few details in the array

View File

@@ -262,7 +262,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
if (null === $result) {
app('log')->debug('Grabbing default currency for this user...');
$result = app('amount')->getDefaultCurrencyByUser($this->user);
$result = app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
}
if (null === $result) {

View File

@@ -27,10 +27,17 @@ namespace FireflyIII\Repositories\UserGroups\Currency;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
use Illuminate\Support\Collection;
interface CurrencyRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param TransactionCurrency $currency
*

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Journal;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@@ -30,6 +31,13 @@ use Illuminate\Support\Collection;
*/
interface JournalRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* Search in journal descriptions.
*