chore: code cleanup.

This commit is contained in:
James Cole
2023-05-29 13:56:55 +02:00
parent 7f7644c92f
commit 1b52147a05
295 changed files with 12418 additions and 12324 deletions

View File

@@ -36,8 +36,8 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection;
use JsonException;
use Illuminate\Support\Facades\Log;
use JsonException;
use Storage;
/**
@@ -58,6 +58,29 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
$this->user->piggyBanks()->delete();
}
/**
* @param int $piggyBankId
*
* @return PiggyBank|null
*/
public function find(int $piggyBankId): ?PiggyBank
{
// phpstan doesn't get the Model.
return $this->user->piggyBanks()->find($piggyBankId); // @phpstan-ignore-line
}
/**
* Find by name or return NULL.
*
* @param string $name
*
* @return PiggyBank|null
*/
public function findByName(string $name): ?PiggyBank
{
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
}
/**
* @param int|null $piggyBankId
* @param string|null $piggyBankName
@@ -89,29 +112,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return null;
}
/**
* @param int $piggyBankId
*
* @return PiggyBank|null
*/
public function find(int $piggyBankId): ?PiggyBank
{
// phpstan doesn't get the Model.
return $this->user->piggyBanks()->find($piggyBankId); // @phpstan-ignore-line
}
/**
* Find by name or return NULL.
*
* @param string $name
*
* @return PiggyBank|null
*/
public function findByName(string $name): ?PiggyBank
{
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first(['piggy_banks.*']);
}
/**
* @inheritDoc
*/
@@ -150,16 +150,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return (string)$rep->currentamount;
}
/**
* @param PiggyBank $piggyBank
*
* @return PiggyBankRepetition|null
*/
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
{
return $piggyBank->piggyBankRepetitions()->first();
}
/**
* @param PiggyBank $piggyBank
*
@@ -274,16 +264,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return (string)$amount;
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* @return int
*/
@@ -310,6 +290,22 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $note->text;
}
/**
* @return Collection
*/
public function getPiggyBanks(): Collection
{
return $this->user // @phpstan-ignore-line (phpstan does not recognize objectGroups)
->piggyBanks()
->with(
[
'account',
'objectGroups',
]
)
->orderBy('order', 'ASC')->get();
}
/**
* Also add amount in name.
*
@@ -331,19 +327,13 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
}
/**
* @return Collection
* @param PiggyBank $piggyBank
*
* @return PiggyBankRepetition|null
*/
public function getPiggyBanks(): Collection
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
{
return $this->user // @phpstan-ignore-line (phpstan does not recognize objectGroups)
->piggyBanks()
->with(
[
'account',
'objectGroups',
]
)
->orderBy('order', 'ASC')->get();
return $piggyBank->piggyBankRepetitions()->first();
}
/**
@@ -422,4 +412,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $search->take($limit)->get();
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
}