chore: reformat code.

This commit is contained in:
James Cole
2023-06-21 12:34:58 +02:00
parent 8d87abde64
commit 3dcb35710b
799 changed files with 23319 additions and 22173 deletions

View File

@@ -75,7 +75,7 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param Category $category
*
* @return bool
*
@@ -107,32 +107,18 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* Find a category or return NULL
* Returns a list of all the categories belonging to a user.
*
* @param int $categoryId
*
* @return Category|null
* @return Collection
*/
public function find(int $categoryId): ?Category
public function getCategories(): Collection
{
return $this->user->categories()->find($categoryId);
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
}
/**
* Find a category.
*
* @param string $name
*
* @return Category|null
*/
public function findByName(string $name): ?Category
{
return $this->user->categories()->where('name', $name)->first(['categories.*']);
}
/**
* @param int|null $categoryId
* @param string|null $categoryName
* @param int|null $categoryId
* @param string|null $categoryName
*
* @return Category|null
* @throws FireflyException
@@ -159,154 +145,31 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* Find a category or return NULL
*
* @return Carbon|null
* @param int $categoryId
*
* @return Category|null
*/
public function firstUseDate(Category $category): ?Carbon
public function find(int $categoryId): ?Category
{
$firstJournalDate = $this->getFirstJournalDate($category);
$firstTransactionDate = $this->getFirstTransactionDate($category);
if (null === $firstTransactionDate && null === $firstJournalDate) {
return null;
}
if (null === $firstTransactionDate) {
return $firstJournalDate;
}
if (null === $firstJournalDate) {
return $firstTransactionDate;
}
if ($firstTransactionDate < $firstJournalDate) {
return $firstTransactionDate;
}
return $firstJournalDate;
return $this->user->categories()->find($categoryId);
}
/**
* @inheritDoc
*/
public function getAttachments(Category $category): Collection
{
$set = $category->attachments()->get();
/** @var Storage $disk */
$disk = Storage::disk('upload');
return $set->each(
static function (Attachment $attachment) use ($disk) {
$notes = $attachment->notes()->first();
$attachment->file_exists = $disk->exists($attachment->fileName());
$attachment->notes = $notes ? $notes->text : '';
return $attachment;
}
);
}
/**
* Get all categories with ID's.
* Find a category.
*
* @param array $categoryIds
* @param string $name
*
* @return Collection
* @return Category|null
*/
public function getByIds(array $categoryIds): Collection
public function findByName(string $name): ?Category
{
return $this->user->categories()->whereIn('id', $categoryIds)->get();
return $this->user->categories()->where('name', $name)->first(['categories.*']);
}
/**
* Returns a list of all the categories belonging to a user.
*
* @return Collection
*/
public function getCategories(): Collection
{
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
}
/**
* @inheritDoc
*/
public function getNoteText(Category $category): ?string
{
$dbNote = $category->notes()->first();
if (null === $dbNote) {
return null;
}
return $dbNote->text;
}
/**
* @param Category $category
* @param Collection $accounts
*
* @return Carbon|null
* @throws Exception
*/
public function lastUseDate(Category $category, Collection $accounts): ?Carbon
{
$lastJournalDate = $this->getLastJournalDate($category, $accounts);
$lastTransactionDate = $this->getLastTransactionDate($category, $accounts);
if (null === $lastTransactionDate && null === $lastJournalDate) {
return null;
}
if (null === $lastTransactionDate) {
return $lastJournalDate;
}
if (null === $lastJournalDate) {
return $lastTransactionDate;
}
if ($lastTransactionDate > $lastJournalDate) {
return $lastTransactionDate;
}
return $lastJournalDate;
}
/**
* @param Category $category
*/
public function removeNotes(Category $category): void
{
$category->notes()->delete();
}
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchCategory(string $query, int $limit): Collection
{
$search = $this->user->categories();
if ('' !== $query) {
$search->where('name', 'LIKE', sprintf('%%%s%%', $query));
}
return $search->take($limit)->get();
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* @param array $data
* @param array $data
*
* @return Category
* @throws FireflyException
@@ -334,19 +197,21 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param array $data
*
* @return Category
* @throws Exception
* @param User|Authenticatable|null $user
*/
public function update(Category $category, array $data): Category
public function setUser(User | Authenticatable | null $user): void
{
/** @var CategoryUpdateService $service */
$service = app(CategoryUpdateService::class);
$service->setUser($this->user);
if (null !== $user) {
$this->user = $user;
}
}
return $service->update($category, $data);
/**
* @param Category $category
*/
public function removeNotes(Category $category): void
{
$category->notes()->delete();
}
/**
@@ -364,7 +229,35 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param Category $category
*
* @return Carbon|null
*
*/
public function firstUseDate(Category $category): ?Carbon
{
$firstJournalDate = $this->getFirstJournalDate($category);
$firstTransactionDate = $this->getFirstTransactionDate($category);
if (null === $firstTransactionDate && null === $firstJournalDate) {
return null;
}
if (null === $firstTransactionDate) {
return $firstJournalDate;
}
if (null === $firstJournalDate) {
return $firstTransactionDate;
}
if ($firstTransactionDate < $firstJournalDate) {
return $firstTransactionDate;
}
return $firstJournalDate;
}
/**
* @param Category $category
*
* @return Carbon|null
*/
@@ -381,7 +274,7 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param Category $category
*
* @return Carbon|null
*/
@@ -401,8 +294,83 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param Collection $accounts
* @inheritDoc
*/
public function getAttachments(Category $category): Collection
{
$set = $category->attachments()->get();
/** @var Storage $disk */
$disk = Storage::disk('upload');
return $set->each(
static function (Attachment $attachment) use ($disk) {
$notes = $attachment->notes()->first();
$attachment->file_exists = $disk->exists($attachment->fileName());
$attachment->notes = $notes ? $notes->text : '';
return $attachment;
}
);
}
/**
* Get all categories with ID's.
*
* @param array $categoryIds
*
* @return Collection
*/
public function getByIds(array $categoryIds): Collection
{
return $this->user->categories()->whereIn('id', $categoryIds)->get();
}
/**
* @inheritDoc
*/
public function getNoteText(Category $category): ?string
{
$dbNote = $category->notes()->first();
if (null === $dbNote) {
return null;
}
return $dbNote->text;
}
/**
* @param Category $category
* @param Collection $accounts
*
* @return Carbon|null
* @throws Exception
*/
public function lastUseDate(Category $category, Collection $accounts): ?Carbon
{
$lastJournalDate = $this->getLastJournalDate($category, $accounts);
$lastTransactionDate = $this->getLastTransactionDate($category, $accounts);
if (null === $lastTransactionDate && null === $lastJournalDate) {
return null;
}
if (null === $lastTransactionDate) {
return $lastJournalDate;
}
if (null === $lastJournalDate) {
return $lastTransactionDate;
}
if ($lastTransactionDate > $lastJournalDate) {
return $lastTransactionDate;
}
return $lastJournalDate;
}
/**
* @param Category $category
* @param Collection $accounts
*
* @return Carbon|null
*/
@@ -425,8 +393,8 @@ class CategoryRepository implements CategoryRepositoryInterface
}
/**
* @param Category $category
* @param Collection $accounts
* @param Category $category
* @param Collection $accounts
*
* @return Carbon|null
* @throws Exception
@@ -449,4 +417,36 @@ class CategoryRepository implements CategoryRepositoryInterface
return null;
}
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchCategory(string $query, int $limit): Collection
{
$search = $this->user->categories();
if ('' !== $query) {
$search->where('name', 'LIKE', sprintf('%%%s%%', $query));
}
return $search->take($limit)->get();
}
/**
* @param Category $category
* @param array $data
*
* @return Category
* @throws Exception
*/
public function update(Category $category, array $data): Category
{
/** @var CategoryUpdateService $service */
$service = app(CategoryUpdateService::class);
$service->setUser($this->user);
return $service->update($category, $data);
}
}

View File

@@ -36,23 +36,23 @@ use Illuminate\Support\Collection;
interface CategoryRepositoryInterface
{
/**
* @param string $query
* @param int $limit
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function categoryEndsWith(string $query, int $limit): Collection;
/**
* @param string $query
* @param int $limit
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function categoryStartsWith(string $query, int $limit): Collection;
/**
* @param Category $category
* @param Category $category
*
* @return bool
*/
@@ -66,7 +66,7 @@ interface CategoryRepositoryInterface
/**
* Find a category or return NULL
*
* @param int $categoryId
* @param int $categoryId
*
* @return Category|null
*/
@@ -75,29 +75,29 @@ interface CategoryRepositoryInterface
/**
* Find a category.
*
* @param string $name
* @param string $name
*
* @return Category|null
*/
public function findByName(string $name): ?Category;
/**
* @param int|null $categoryId
* @param string|null $categoryName
* @param int|null $categoryId
* @param string|null $categoryName
*
* @return Category|null
*/
public function findCategory(?int $categoryId, ?string $categoryName): ?Category;
/**
* @param Category $category
* @param Category $category
*
* @return Carbon|null
*/
public function firstUseDate(Category $category): ?Carbon;
/**
* @param Category $category
* @param Category $category
*
* @return Collection
*/
@@ -106,7 +106,7 @@ interface CategoryRepositoryInterface
/**
* Get all categories with ID's.
*
* @param array $categoryIds
* @param array $categoryIds
*
* @return Collection
*/
@@ -120,7 +120,7 @@ interface CategoryRepositoryInterface
public function getCategories(): Collection;
/**
* @param Category $category
* @param Category $category
*
* @return string|null
*/
@@ -129,8 +129,8 @@ interface CategoryRepositoryInterface
/**
* Return most recent transaction(journal) date or null when never used before.
*
* @param Category $category
* @param Collection $accounts
* @param Category $category
* @param Collection $accounts
*
* @return Carbon|null
*/
@@ -139,25 +139,25 @@ interface CategoryRepositoryInterface
/**
* Remove notes.
*
* @param Category $category
* @param Category $category
*/
public function removeNotes(Category $category): void;
/**
* @param string $query
* @param int $limit
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchCategory(string $query, int $limit): Collection;
/**
* @param User|Authenticatable|null $user
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void;
public function setUser(User | Authenticatable | null $user): void;
/**
* @param array $data
* @param array $data
*
* @return Category
* @throws FireflyException
@@ -165,16 +165,16 @@ interface CategoryRepositoryInterface
public function store(array $data): Category;
/**
* @param Category $category
* @param array $data
* @param Category $category
* @param array $data
*
* @return Category
*/
public function update(Category $category, array $data): Category;
/**
* @param Category $category
* @param string $notes
* @param Category $category
* @param string $notes
*/
public function updateNotes(Category $category, string $notes): void;
}

View File

@@ -43,9 +43,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
* which have no category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -90,14 +90,24 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
return $array;
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User | Authenticatable | null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
* which have no category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -142,22 +152,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
return $array;
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -192,9 +192,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
/**
* Sum of income journals in period without a category, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/

View File

@@ -39,9 +39,9 @@ interface NoCategoryRepositoryInterface
* which have no category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -52,25 +52,25 @@ interface NoCategoryRepositoryInterface
* which have no category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array;
/**
* @param User|Authenticatable|null $user
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void;
public function setUser(User | Authenticatable | null $user): void;
/**
* Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -79,9 +79,9 @@ interface NoCategoryRepositoryInterface
/**
* Sum of income journals in period without a category, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/
@@ -90,9 +90,9 @@ interface NoCategoryRepositoryInterface
/**
* Sum of transfers in period without a category, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
*
* @return array
*/

View File

@@ -45,10 +45,10 @@ class OperationsRepository implements OperationsRepositoryInterface
*
* First currency, then categories.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -116,15 +116,35 @@ class OperationsRepository implements OperationsRepositoryInterface
return $array;
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User | Authenticatable | null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* Returns a list of all the categories belonging to a user.
*
* @return Collection
*/
private function getCategories(): Collection
{
return $this->user->categories()->get();
}
/**
* This method returns a list of all the deposit transaction journals (as arrays) set in that period
* which have the specified category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -321,23 +341,13 @@ class OperationsRepository implements OperationsRepositoryInterface
return $array;
}
/**
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void
{
if (null !== $user) {
$this->user = $user;
}
}
/**
* Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -378,10 +388,10 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -421,10 +431,10 @@ class OperationsRepository implements OperationsRepositoryInterface
/**
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -460,14 +470,4 @@ class OperationsRepository implements OperationsRepositoryInterface
return $array;
}
/**
* Returns a list of all the categories belonging to a user.
*
* @return Collection
*/
private function getCategories(): Collection
{
return $this->user->categories()->get();
}
}

View File

@@ -39,10 +39,10 @@ interface OperationsRepositoryInterface
* which have the specified category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -53,10 +53,10 @@ interface OperationsRepositoryInterface
* which have the specified category set to them. It's grouped per currency, with as few details in the array
* as possible. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -68,10 +68,10 @@ interface OperationsRepositoryInterface
* It excludes any transfers between the listed accounts.
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -83,27 +83,27 @@ interface OperationsRepositoryInterface
* It excludes any transfers between the listed accounts.
* It's grouped per currency, with as few details in the array as possible. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection|null $categories
*
* @return array
*/
public function listTransferredOut(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array;
/**
* @param User|Authenticatable|null $user
* @param User|Authenticatable|null $user
*/
public function setUser(User|Authenticatable|null $user): void;
public function setUser(User | Authenticatable | null $user): void;
/**
* Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -112,10 +112,10 @@ interface OperationsRepositoryInterface
/**
* Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/
@@ -124,10 +124,10 @@ interface OperationsRepositoryInterface
/**
* Sum of transfers in period for a set of categories, grouped per currency. Amounts are always positive.
*
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
* @param Carbon $start
* @param Carbon $end
* @param Collection|null $accounts
* @param Collection|null $categories
*
* @return array
*/