Various code cleanup.

This commit is contained in:
James Cole
2018-03-25 09:01:43 +02:00
parent dd9694890a
commit 6660306ac4
46 changed files with 327 additions and 121 deletions

View File

@@ -23,9 +23,12 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
@@ -89,8 +92,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
/**
* TODO use service
*
* @param TransactionCurrency $currency
*
* @return bool
@@ -98,7 +99,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
public function destroy(TransactionCurrency $currency): bool
{
if ($this->user->hasRole('owner')) {
$currency->forceDelete();
/** @var CurrencyDestroyService $service */
$service = app(CurrencyDestroyService::class);
$service->destroy($currency);
}
return true;
@@ -307,30 +310,19 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
/**
* TODO use factory
*
* @param array $data
*
* @return TransactionCurrency
*/
public function store(array $data): TransactionCurrency
{
/** @var TransactionCurrency $currency */
$currency = TransactionCurrency::create(
[
'name' => $data['name'],
'code' => $data['code'],
'symbol' => $data['symbol'],
'decimal_places' => $data['decimal_places'],
]
);
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
return $currency;
return $factory->create($data);
}
/**
* TODO use factory
*
* @param TransactionCurrency $currency
* @param array $data
*
@@ -338,12 +330,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*/
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
$currency->code = $data['code'];
$currency->symbol = $data['symbol'];
$currency->name = $data['name'];
$currency->decimal_places = $data['decimal_places'];
$currency->save();
/** @var CurrencyUpdateService $service */
$service = app(CurrencyUpdateService::class);
return $currency;
return $service->update($currency, $data);
}
}