Code cleanup

This commit is contained in:
James Cole
2018-04-02 14:50:17 +02:00
parent 379b104778
commit fa7ab45a40
100 changed files with 440 additions and 517 deletions

View File

@@ -127,11 +127,10 @@ trait AccountServiceTrait
* @param array $data
*
* @return TransactionJournal|null
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function storeIBJournal(Account $account, array $data): ?TransactionJournal
{
$amount = strval($data['openingBalance']);
$amount = (string)$data['openingBalance'];
Log::debug(sprintf('Submitted amount is %s', $amount));
if (0 === bccomp($amount, '0')) {
@@ -145,7 +144,7 @@ trait AccountServiceTrait
'type' => TransactionType::OPENING_BALANCE,
'user' => $account->user->id,
'transaction_currency_id' => $currencyId,
'description' => strval(trans('firefly.initial_balance_description', ['account' => $account->name])),
'description' => (string)trans('firefly.initial_balance_description', ['account' => $account->name]),
'completed' => true,
'date' => $data['openingBalanceDate'],
'bill_id' => null,
@@ -232,7 +231,6 @@ trait AccountServiceTrait
* @param array $data
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function updateIB(Account $account, array $data): bool
{
@@ -268,9 +266,9 @@ trait AccountServiceTrait
public function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
{
$date = $data['openingBalanceDate'];
$amount = strval($data['openingBalance']);
$amount = (string)$data['openingBalance'];
$negativeAmount = bcmul($amount, '-1');
$currencyId = intval($data['currency_id']);
$currencyId = (int)$data['currency_id'];
Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount));
if (0 === bccomp($amount, '0')) {
@@ -291,13 +289,13 @@ trait AccountServiceTrait
// update transactions:
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if (intval($account->id) === intval($transaction->account_id)) {
if ((int)$account->id === (int)$transaction->account_id) {
Log::debug(sprintf('Will (eq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $amount));
$transaction->amount = $amount;
$transaction->transaction_currency_id = $currencyId;
$transaction->save();
}
if (!(intval($account->id) === intval($transaction->account_id))) {
if (!((int)$account->id === (int)$transaction->account_id)) {
Log::debug(sprintf('Will (neq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $negativeAmount));
$transaction->amount = $negativeAmount;
$transaction->transaction_currency_id = $currencyId;
@@ -383,9 +381,8 @@ trait AccountServiceTrait
*/
public function validIBData(array $data): bool
{
$data['openingBalance'] = strval($data['openingBalance'] ?? '');
if (isset($data['openingBalance']) && null !== $data['openingBalance'] && strlen($data['openingBalance']) > 0
&& isset($data['openingBalanceDate'])) {
$data['openingBalance'] = (string)($data['openingBalance'] ?? '');
if (isset($data['openingBalance'], $data['openingBalanceDate']) && \strlen($data['openingBalance']) > 0) {
Log::debug('Array has valid opening balance data.');
return true;

View File

@@ -72,7 +72,7 @@ trait JournalServiceTrait
$factory->setUser($journal->user);
$bill = $factory->find($data['bill_id'], $data['bill_name']);
if (!is_null($bill)) {
if (null !== $bill) {
$journal->bill_id = $bill->id;
$journal->save();
@@ -110,10 +110,10 @@ trait JournalServiceTrait
*/
protected function storeNote(TransactionJournal $journal, ?string $notes): void
{
$notes = strval($notes);
$notes = (string)$notes;
if (strlen($notes) > 0) {
$note = $journal->notes()->first();
if (is_null($note)) {
if (null === $note) {
$note = new Note;
$note->noteable()->associate($journal);
}
@@ -123,7 +123,7 @@ trait JournalServiceTrait
return;
}
$note = $journal->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$note->delete();
}

View File

@@ -104,12 +104,12 @@ trait TransactionServiceTrait
*/
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): Account
{
$accountId = intval($accountId);
$accountName = strval($accountName);
$accountId = (int)$accountId;
$accountName = (string)$accountName;
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
if (is_null($expectedType)) {
if (null === $expectedType) {
return $repository->findNull($accountId);
}
@@ -215,7 +215,7 @@ trait TransactionServiceTrait
*/
protected function setBudget(Transaction $transaction, ?Budget $budget): void
{
if (is_null($budget)) {
if (null === $budget) {
$transaction->budgets()->sync([]);
return;
@@ -232,7 +232,7 @@ trait TransactionServiceTrait
*/
protected function setCategory(Transaction $transaction, ?Category $category): void
{
if (is_null($category)) {
if (null === $category) {
$transaction->categories()->sync([]);
return;
@@ -259,7 +259,7 @@ trait TransactionServiceTrait
*/
protected function setForeignCurrency(Transaction $transaction, ?TransactionCurrency $currency): void
{
if (is_null($currency)) {
if (null === $currency) {
$transaction->foreign_currency_id = null;
$transaction->save();