First full implementation of new storage routine.

This commit is contained in:
James Cole
2019-03-17 17:05:16 +01:00
parent 6bd2b4f288
commit 200a4b18a8
19 changed files with 958 additions and 674 deletions

View File

@@ -218,6 +218,55 @@ class BudgetRepository implements BudgetRepositoryInterface
}
}
/**
* @param Budget|null $budget
* @param int|null $budgetId
* @param string|null $budgetName
*
* @return Budget|null
*/
public function findBudget(?Budget $budget, ?int $budgetId, ?string $budgetName): ?Budget
{
Log::debug('Now in findBudget()');
$result = null;
if (null !== $budget) {
Log::debug(sprintf('Parameters contain budget #%d, will return this.', $budget->id));
$result = $budget;
}
if (null === $result) {
Log::debug(sprintf('Searching for budget with ID #%d...', $budgetId));
$result = $this->findNull((int)$budgetId);
}
if (null === $result) {
Log::debug(sprintf('Searching for budget with name %s...', $budgetName));
$result = $this->findByName((string)$budgetName);
}
if (null !== $result) {
Log::debug(sprintf('Found budget #%d: %s', $result->id, $result->name));
}
Log::debug(sprintf('Found result is null? %s', var_export(null === $result, true)));
return $result;
}
/**
* Find budget by name.
*
* @param string|null $name
*
* @return Budget|null
*/
public function findByName(?string $name): ?Budget
{
if (null === $name) {
return null;
}
$query = sprintf('%%%s%%', $name);
return $this->user->budgets()->where('name', 'LIKE', $query)->first();
}
/**
* Find a budget or return NULL
*
@@ -399,6 +448,8 @@ class BudgetRepository implements BudgetRepositoryInterface
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Returns all available budget objects.
*
@@ -439,8 +490,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return bcdiv($total, (string)$days);
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Budget $budget
* @param Carbon $start
@@ -568,6 +617,8 @@ class BudgetRepository implements BudgetRepositoryInterface
return $set;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* Get all budgets with these ID's.
*
@@ -647,8 +698,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return $this->user->budgets()->where('name', 'LIKE', $query)->get();
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param TransactionCurrency $currency
* @param Carbon $start
@@ -853,6 +902,8 @@ class BudgetRepository implements BudgetRepositoryInterface
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param array $data
*
@@ -915,8 +966,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return $limit;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Budget $budget
* @param array $data

View File

@@ -35,6 +35,7 @@ use Illuminate\Support\Collection;
*/
interface BudgetRepositoryInterface
{
/**
* A method that returns the amount of money budgeted per day for this budget,
* on average.
@@ -80,6 +81,24 @@ interface BudgetRepositoryInterface
*/
public function destroyBudgetLimit(BudgetLimit $budgetLimit): void;
/**
* @param Budget|null $budget
* @param int|null $budgetId
* @param string|null $budgetName
*
* @return Budget|null
*/
public function findBudget(?Budget $budget, ?int $budgetId, ?string $budgetName): ?Budget;
/**
* Find budget by name.
*
* @param string|null $name
*
* @return Budget|null
*/
public function findByName(?string $name): ?Budget;
/**
* @param int|null $budgetId
*