Remove unused methods.

This commit is contained in:
James Cole 2019-08-12 18:24:33 +02:00
parent 5eadb51b78
commit 499e713683
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 2 additions and 146 deletions

View File

@ -130,29 +130,6 @@ class CategoryRepository implements CategoryRepositoryInterface
return $return;
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user);
if (0 !== $accounts->count()) {
$collector->setAccounts($accounts);
}
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setCategories($categories);
return $collector->getExtractedJournals();
}
/**
* A very cryptic method name that means:
*
@ -660,30 +637,6 @@ class CategoryRepository implements CategoryRepositoryInterface
return $return;
}
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setCategories($categories);
if ($accounts->count() > 0) {
$collector->setAccounts($accounts);
}
return $collector->getExtractedJournals();
}
/**
* A very cryptic method name that means:
*

View File

@ -60,20 +60,6 @@ interface CategoryRepositoryInterface
*/
public function earnedInPeriod(Category $category, Collection $accounts, Carbon $start, Carbon $end): array;
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array;
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* A very cryptic method name that means:
*
@ -218,16 +204,6 @@ interface CategoryRepositoryInterface
*/
public function spentInPeriod(Category $category, Collection $accounts, Carbon $start, Carbon $end): array;
/**
* @param Collection $categories
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array;
/**
* A very cryptic method name that means:
*

View File

@ -68,8 +68,8 @@ class CategoryTransformer extends AbstractTransformer
$start = $this->parameters->get('start');
$end = $this->parameters->get('end');
if (null !== $start && null !== $end) {
$spent = $this->getSpentInformation($category, $start, $end);
$earned = $this->getEarnedInformation($category, $start, $end);
$earned = array_values($this->repository->earnedInPeriod($category, new Collection, $start, $end));
$spent = array_values($this->repository->spentInPeriod($category, new Collection, $start, $end));
}
$data = [
'id' => (int)$category->id,
@ -88,77 +88,4 @@ class CategoryTransformer extends AbstractTransformer
return $data;
}
/**
* @param Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getEarnedInformation(Category $category, Carbon $start, Carbon $end): array
{
$collection = $this->repository->earnedInPeriodCollection(new Collection([$category]), new Collection, $start, $end);
$return = [];
$total = [];
$currencies = [];
/** @var Transaction $transaction */
foreach ($collection as $transaction) {
$code = $transaction->transaction_currency_code;
if (!isset($currencies[$code])) {
$currencies[$code] = $transaction->transactionCurrency;
}
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
}
foreach ($total as $code => $earned) {
/** @var TransactionCurrency $currency */
$currency = $currencies[$code];
$return[] = [
'currency_id' => $currency->id,
'currency_code' => $code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'amount' => round($earned, $currency->decimal_places),
];
}
return $return;
}
/**
* @param Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function getSpentInformation(Category $category, Carbon $start, Carbon $end): array
{
$collection = $this->repository->spentInPeriodCollection(new Collection([$category]), new Collection, $start, $end);
$return = [];
$total = [];
$currencies = [];
/** @var Transaction $transaction */
foreach ($collection as $transaction) {
$code = $transaction->transaction_currency_code;
if (!isset($currencies[$code])) {
$currencies[$code] = $transaction->transactionCurrency;
}
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
}
foreach ($total as $code => $spent) {
/** @var TransactionCurrency $currency */
$currency = $currencies[$code];
$return[] = [
'currency_id' => $currency->id,
'currency_code' => $code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'amount' => round($spent, $currency->decimal_places),
];
}
return $return;
}
}