mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-06 01:45:22 +00:00
Refactor findNull to find
This commit is contained in:
@@ -87,17 +87,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function findByName(string $name): ?Category
|
||||
{
|
||||
$categories = $this->user->categories()->get(['categories.*']);
|
||||
|
||||
// See reference nr. 7
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if ($category->name === $name) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->user->categories()->where('name', $name)->first(['categories.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +101,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
Log::debug('Now in findCategory()');
|
||||
Log::debug(sprintf('Searching for category with ID #%d...', $categoryId));
|
||||
$result = $this->findNull((int)$categoryId);
|
||||
$result = $this->find((int)$categoryId);
|
||||
if (null === $result) {
|
||||
Log::debug(sprintf('Searching for category with name %s...', $categoryName));
|
||||
$result = $this->findByName((string)$categoryName);
|
||||
@@ -135,7 +125,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findNull(int $categoryId): ?Category
|
||||
public function find(int $categoryId): ?Category
|
||||
{
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findNull(int $categoryId): ?Category;
|
||||
public function find(int $categoryId): ?Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
|
||||
Reference in New Issue
Block a user