mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update find methods to return null
This commit is contained in:
parent
28b00f6507
commit
33db99ffd3
@ -197,7 +197,7 @@ class ExpenseReportController extends Controller
|
|||||||
$collection->push($expenseAccount);
|
$collection->push($expenseAccount);
|
||||||
|
|
||||||
$revenue = $this->accountRepository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
$revenue = $this->accountRepository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
||||||
if (!is_null($revenue->id)) {
|
if (!is_null($revenue)) {
|
||||||
$collection->push($revenue);
|
$collection->push($revenue);
|
||||||
}
|
}
|
||||||
$combined[$expenseAccount->name] = $collection;
|
$combined[$expenseAccount->name] = $collection;
|
||||||
|
@ -313,7 +313,7 @@ class ExpenseController extends Controller
|
|||||||
$collection->push($expenseAccount);
|
$collection->push($expenseAccount);
|
||||||
|
|
||||||
$revenue = $this->accountRepository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
$revenue = $this->accountRepository->findByName($expenseAccount->name, [AccountType::REVENUE]);
|
||||||
if (!is_null($revenue->id)) {
|
if (!is_null($revenue)) {
|
||||||
$collection->push($revenue);
|
$collection->push($revenue);
|
||||||
}
|
}
|
||||||
$combined[$expenseAccount->name] = $collection;
|
$combined[$expenseAccount->name] = $collection;
|
||||||
|
@ -114,7 +114,7 @@ class ImportBill
|
|||||||
Log::debug(sprintf('Finding bill with ID #%d', $this->id['value']));
|
Log::debug(sprintf('Finding bill with ID #%d', $this->id['value']));
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
$bill = $this->repository->find(intval($this->id['value']));
|
$bill = $this->repository->find(intval($this->id['value']));
|
||||||
if (null !== $bill->id) {
|
if (null !== $bill) {
|
||||||
Log::debug(sprintf('Found unmapped bill by ID (#%d): %s', $bill->id, $bill->name));
|
Log::debug(sprintf('Found unmapped bill by ID (#%d): %s', $bill->id, $bill->name));
|
||||||
|
|
||||||
return $bill;
|
return $bill;
|
||||||
@ -199,7 +199,7 @@ class ImportBill
|
|||||||
$search = intval($array['mapped']);
|
$search = intval($array['mapped']);
|
||||||
$bill = $this->repository->find($search);
|
$bill = $this->repository->find($search);
|
||||||
|
|
||||||
if (null === $bill->id) {
|
if (null === $bill) {
|
||||||
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
|
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
|
||||||
|
|
||||||
return new Bill;
|
return new Bill;
|
||||||
|
@ -44,12 +44,13 @@ use Validator;
|
|||||||
*/
|
*/
|
||||||
class AccountRepository implements AccountRepositoryInterface
|
class AccountRepository implements AccountRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
use FindAccountsTrait;
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $validAssetFields = ['accountRole', 'accountNumber', 'currency_id', 'BIC'];
|
private $validAssetFields = ['accountRole', 'accountNumber', 'currency_id', 'BIC'];
|
||||||
|
|
||||||
|
use FindAccountsTrait;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $validCCFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber', 'currency_id', 'BIC'];
|
private $validCCFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber', 'currency_id', 'BIC'];
|
||||||
/** @var array */
|
/** @var array */
|
||||||
@ -91,6 +92,16 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return Account|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $accountId): ?Account
|
||||||
|
{
|
||||||
|
return $this->user->accounts()->find($accountId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return account type by string.
|
* Return account type by string.
|
||||||
*
|
*
|
||||||
@ -336,7 +347,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
|
|
||||||
// account may exist already:
|
// account may exist already:
|
||||||
$existingAccount = $this->findByName($data['name'], [$type]);
|
$existingAccount = $this->findByName($data['name'], [$type]);
|
||||||
if (null !== $existingAccount->id) {
|
if (null !== $existingAccount) {
|
||||||
Log::warning(sprintf('There already is an account named "%s" of type "%s".', $data['name'], $type));
|
Log::warning(sprintf('There already is an account named "%s" of type "%s".', $data['name'], $type));
|
||||||
|
|
||||||
return $existingAccount;
|
return $existingAccount;
|
||||||
|
@ -57,10 +57,18 @@ interface AccountRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param int $accountId
|
* @param int $accountId
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
* @return Account
|
* @return Account
|
||||||
*/
|
*/
|
||||||
public function find(int $accountId): Account;
|
public function find(int $accountId): Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return Account|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $accountId): ?Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $number
|
* @param string $number
|
||||||
* @param array $types
|
* @param array $types
|
||||||
@ -81,9 +89,9 @@ interface AccountRepositoryInterface
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $types
|
* @param array $types
|
||||||
*
|
*
|
||||||
* @return Account
|
* @return Account|null
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name, array $types): Account;
|
public function findByName(string $name, array $types): ?Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return account type by string.
|
* Return account type by string.
|
||||||
|
@ -109,9 +109,9 @@ trait FindAccountsTrait
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $types
|
* @param array $types
|
||||||
*
|
*
|
||||||
* @return Account
|
* @return Account|null
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name, array $types): Account
|
public function findByName(string $name, array $types): ?Account
|
||||||
{
|
{
|
||||||
$query = $this->user->accounts();
|
$query = $this->user->accounts();
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ trait FindAccountsTrait
|
|||||||
}
|
}
|
||||||
Log::debug(sprintf('There is no account with name "%s" or types', $name), $types);
|
Log::debug(sprintf('There is no account with name "%s" or types', $name), $types);
|
||||||
|
|
||||||
return new Account;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,14 +66,12 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return Bill
|
* @return Bill
|
||||||
*/
|
*/
|
||||||
public function find(int $billId): Bill
|
public function find(int $billId): ?Bill
|
||||||
{
|
{
|
||||||
$bill = $this->user->bills()->find($billId);
|
/** @var Bill $res */
|
||||||
if (null === $bill) {
|
$res = $this->user->bills()->find($billId);
|
||||||
$bill = new Bill;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bill;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +81,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return Bill
|
* @return Bill
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name): Bill
|
public function findByName(string $name): ?Bill
|
||||||
{
|
{
|
||||||
$bills = $this->user->bills()->get(['bills.*']);
|
$bills = $this->user->bills()->get(['bills.*']);
|
||||||
|
|
||||||
@ -94,7 +92,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Bill;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,18 +47,18 @@ interface BillRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @param int $billId
|
* @param int $billId
|
||||||
*
|
*
|
||||||
* @return Bill
|
* @return Bill|null
|
||||||
*/
|
*/
|
||||||
public function find(int $billId): Bill;
|
public function find(int $billId): ?Bill;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a bill by name.
|
* Find a bill by name.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return Bill
|
* @return Bill|null
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name): Bill;
|
public function findByName(string $name): ?Bill;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
|
@ -194,9 +194,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget|null
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name): Budget
|
public function findByName(string $name): ?Budget
|
||||||
{
|
{
|
||||||
$budgets = $this->user->budgets()->get(['budgets.*']);
|
$budgets = $this->user->budgets()->get(['budgets.*']);
|
||||||
/** @var Budget $budget */
|
/** @var Budget $budget */
|
||||||
@ -206,7 +206,19 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Budget;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a budget or return NULL
|
||||||
|
*
|
||||||
|
* @param int $budgetId
|
||||||
|
*
|
||||||
|
* @return Budget|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $budgetId): ?Budget
|
||||||
|
{
|
||||||
|
return $this->user->budgets()->find($budgetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,19 +73,29 @@ interface BudgetRepositoryInterface
|
|||||||
* Find a budget.
|
* Find a budget.
|
||||||
*
|
*
|
||||||
* @param int $budgetId
|
* @param int $budgetId
|
||||||
|
* @deprecated
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget
|
||||||
*/
|
*/
|
||||||
public function find(int $budgetId): Budget;
|
public function find(int $budgetId): Budget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a budget or return NULL
|
||||||
|
*
|
||||||
|
* @param int $budgetId
|
||||||
|
*
|
||||||
|
* @return Budget|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $budgetId): ?Budget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a budget.
|
* Find a budget.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget|null
|
||||||
*/
|
*/
|
||||||
public function findByName(string $name): Budget;
|
public function findByName(string $name): ?Budget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the oldest journal or transaction date known to this budget.
|
* This method returns the oldest journal or transaction date known to this budget.
|
||||||
|
@ -110,6 +110,18 @@ class CategoryRepository implements CategoryRepositoryInterface
|
|||||||
return new Category;
|
return new Category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a category or return NULL
|
||||||
|
*
|
||||||
|
* @param int $categoryId
|
||||||
|
*
|
||||||
|
* @return Category|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $categoryId): ?Category
|
||||||
|
{
|
||||||
|
return $this->user->categories()->find($categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
|
@ -53,11 +53,20 @@ interface CategoryRepositoryInterface
|
|||||||
* Find a category.
|
* Find a category.
|
||||||
*
|
*
|
||||||
* @param int $categoryId
|
* @param int $categoryId
|
||||||
*
|
* @deprecated
|
||||||
* @return Category
|
* @return Category
|
||||||
*/
|
*/
|
||||||
public function find(int $categoryId): Category;
|
public function find(int $categoryId): Category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a category or return NULL
|
||||||
|
*
|
||||||
|
* @param int $categoryId
|
||||||
|
*
|
||||||
|
* @return Category|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $categoryId): ?Category;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a category.
|
* Find a category.
|
||||||
*
|
*
|
||||||
|
@ -129,6 +129,18 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find by currency code, return NULL if unfound.
|
||||||
|
*
|
||||||
|
* @param string $currencyCode
|
||||||
|
*
|
||||||
|
* @return TransactionCurrency|null
|
||||||
|
*/
|
||||||
|
public function findByCodeNull(string $currencyCode): ?TransactionCurrency
|
||||||
|
{
|
||||||
|
return TransactionCurrency::where('code', $currencyCode)->first();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find by currency name.
|
* Find by currency name.
|
||||||
*
|
*
|
||||||
@ -163,6 +175,21 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
|||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find by ID, return NULL if not found.
|
||||||
|
*
|
||||||
|
* @param int $currencyId
|
||||||
|
*
|
||||||
|
* @return TransactionCurrency|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $currencyId): ?TransactionCurrency
|
||||||
|
{
|
||||||
|
/** @var TransactionCurrency $res */
|
||||||
|
$res = TransactionCurrency::find($currencyId);
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +60,7 @@ interface CurrencyRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @param int $currencyId
|
* @param int $currencyId
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
* @return TransactionCurrency
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
public function find(int $currencyId): TransactionCurrency;
|
public function find(int $currencyId): TransactionCurrency;
|
||||||
@ -67,12 +68,23 @@ interface CurrencyRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Find by currency code.
|
* Find by currency code.
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @param string $currencyCode
|
* @param string $currencyCode
|
||||||
*
|
*
|
||||||
* @return TransactionCurrency
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
public function findByCode(string $currencyCode): TransactionCurrency;
|
public function findByCode(string $currencyCode): TransactionCurrency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find by currency code, return NULL if unfound.
|
||||||
|
*
|
||||||
|
* @param string $currencyCode
|
||||||
|
*
|
||||||
|
* @return TransactionCurrency|null
|
||||||
|
*/
|
||||||
|
public function findByCodeNull(string $currencyCode): ?TransactionCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find by currency name.
|
* Find by currency name.
|
||||||
*
|
*
|
||||||
@ -91,6 +103,15 @@ interface CurrencyRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function findBySymbol(string $currencySymbol): TransactionCurrency;
|
public function findBySymbol(string $currencySymbol): TransactionCurrency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find by ID, return NULL if not found.
|
||||||
|
*
|
||||||
|
* @param int $currencyId
|
||||||
|
*
|
||||||
|
* @return TransactionCurrency|null
|
||||||
|
*/
|
||||||
|
public function findNull(int $currencyId): ?TransactionCurrency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -117,7 +117,7 @@ class SetDestinationAccount implements ActionInterface
|
|||||||
{
|
{
|
||||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
||||||
|
|
||||||
if (null === $account->id) {
|
if (null === $account) {
|
||||||
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -134,7 +134,7 @@ class SetDestinationAccount implements ActionInterface
|
|||||||
private function findExpenseAccount()
|
private function findExpenseAccount()
|
||||||
{
|
{
|
||||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
|
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
|
||||||
if (null === $account->id) {
|
if (null === $account) {
|
||||||
// create new revenue account with this name:
|
// create new revenue account with this name:
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $this->action->action_value,
|
'name' => $this->action->action_value,
|
||||||
|
@ -116,7 +116,7 @@ class SetSourceAccount implements ActionInterface
|
|||||||
{
|
{
|
||||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
||||||
|
|
||||||
if (null === $account->id) {
|
if (null === $account) {
|
||||||
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -133,7 +133,7 @@ class SetSourceAccount implements ActionInterface
|
|||||||
private function findRevenueAccount()
|
private function findRevenueAccount()
|
||||||
{
|
{
|
||||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
|
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
|
||||||
if (null === $account->id) {
|
if (null === $account) {
|
||||||
// create new revenue account with this name:
|
// create new revenue account with this name:
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $this->action->action_value,
|
'name' => $this->action->action_value,
|
||||||
|
Loading…
Reference in New Issue
Block a user