Clean up code.

This commit is contained in:
James Cole
2023-12-10 06:51:59 +01:00
parent c2b22a2bac
commit 46e130fdfe
195 changed files with 973 additions and 984 deletions

View File

@@ -40,6 +40,50 @@ class AccountRepository implements AccountRepositoryInterface
{
use UserGroupTrait;
/**
* @inheritDoc
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$dbQuery = $this->userGroup
->accounts()
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.active', true)
->where(
static function (EloquentBuilder $q1) use ($number) { // @phpstan-ignore-line
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
);
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
/** @var Account|null */
return $dbQuery->first(['accounts.*']);
}
/**
* @param string $iban
* @param array $types
*
* @return Account|null
*/
public function findByIbanNull(string $iban, array $types): ?Account
{
$query = $this->userGroup->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Account|null */
return $query->where('iban', $iban)->first(['accounts.*']);
}
/**
* @inheritDoc
*/
@@ -66,31 +110,6 @@ class AccountRepository implements AccountRepositoryInterface
return $account;
}
/**
* @inheritDoc
*/
public function findByAccountNumber(string $number, array $types): ?Account
{
$dbQuery = $this->userGroup
->accounts()
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.active', true)
->where(
static function (EloquentBuilder $q1) use ($number) { /** @phpstan-ignore-line */
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
);
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
/** @var Account|null */
return $dbQuery->first(['accounts.*']);
}
/**
* @param Account $account
*
@@ -245,22 +264,4 @@ class AccountRepository implements AccountRepositoryInterface
return $dbQuery->take($limit)->get(['accounts.*']);
}
/**
* @param string $iban
* @param array $types
*
* @return Account|null
*/
public function findByIbanNull(string $iban, array $types): ?Account
{
$query = $this->userGroup->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
/** @var Account|null */
return $query->where('iban', $iban)->first(['accounts.*']);
}
}

View File

@@ -37,19 +37,11 @@ use Illuminate\Support\Collection;
interface AccountRepositoryInterface
{
/**
* @param UserGroup $userGroup
*
* @return void
*/
public function setUserGroup(UserGroup $userGroup): void;
/**
* @param string $iban
* @param array $types
* @param int $accountId
*
* @return Account|null
*/
public function findByIbanNull(string $iban, array $types): ?Account;
public function find(int $accountId): ?Account;
/**
* @param string $number
@@ -60,18 +52,12 @@ interface AccountRepositoryInterface
public function findByAccountNumber(string $number, array $types): ?Account;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param int $accountId
* @param string $iban
* @param array $types
*
* @return Account|null
*/
public function find(int $accountId): ?Account;
public function findByIbanNull(string $iban, array $types): ?Account;
/**
* @param string $name
@@ -129,5 +115,19 @@ interface AccountRepositoryInterface
*/
public function searchAccount(string $query, array $types, int $limit): Collection;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param UserGroup $userGroup
*
* @return void
*/
public function setUserGroup(UserGroup $userGroup): void;
}

View File

@@ -157,7 +157,7 @@ class BillRepository implements BillRepositoryInterface
$currencyId = $bill->transaction_currency_id;
$average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2');
$nativeAverage = $converter->convert($currency, $default, $start, $average);
$return[$currencyId] ??= [
$return[$currencyId] ??= [
'currency_id' => (string)$currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,

View File

@@ -35,13 +35,6 @@ 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.
@@ -84,6 +77,13 @@ interface BillRepositoryInterface
*/
public function nextDateMatch(Bill $bill, Carbon $date): Carbon;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* Collect multi-currency of sum of bills already paid.
*

View File

@@ -54,7 +54,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
$currencyId = $availableBudget->transaction_currency_id;
$return[$currencyId] ??= [
$return[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_code' => $availableBudget->transactionCurrency->code,
'currency_symbol' => $availableBudget->transactionCurrency->symbol,

View File

@@ -33,12 +33,6 @@ use FireflyIII\User;
*/
interface AvailableBudgetRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param Carbon $start
* @param Carbon $end
@@ -47,4 +41,11 @@ interface AvailableBudgetRepositoryInterface
*/
public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
}

View File

@@ -34,6 +34,11 @@ use Illuminate\Support\Collection;
*/
interface BudgetRepositoryInterface
{
/**
* @return Collection
*/
public function getActiveBudgets(): Collection;
/**
* @param User $user
*
@@ -47,8 +52,4 @@ interface BudgetRepositoryInterface
* @return void
*/
public function setUserGroup(UserGroup $userGroup): void;
/**
* @return Collection
*/
public function getActiveBudgets(): Collection;
}

View File

@@ -34,13 +34,6 @@ 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
@@ -54,4 +47,11 @@ interface OperationsRepositoryInterface
* @return array
*/
public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
}

View File

@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Currency;
use FireflyIII\Api\V1\Controllers\Data\Bulk\TransactionController;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
@@ -33,12 +32,6 @@ use Illuminate\Support\Collection;
interface CurrencyRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param TransactionCurrency $currency
*
@@ -162,6 +155,13 @@ interface CurrencyRepositoryInterface
*/
public function searchCurrency(string $search, int $limit): Collection;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* @param array $data
*

View File

@@ -31,13 +31,6 @@ use Illuminate\Support\Collection;
*/
interface JournalRepositoryInterface
{
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
/**
* Search in journal descriptions.
*
@@ -47,4 +40,11 @@ interface JournalRepositoryInterface
* @return Collection
*/
public function searchJournalDescriptions(string $search, int $limit): Collection;
/**
* @param User $user
*
* @return void
*/
public function setUser(User $user): void;
}