mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Remove unnecessary loops.
This commit is contained in:
@@ -90,17 +90,7 @@ class BudgetFactory
|
||||
*/
|
||||
public function findByName(string $name): ?Budget
|
||||
{
|
||||
/** @var Collection $collection */
|
||||
$collection = $this->user->budgets()->get();
|
||||
// TODO no longer need to loop like this
|
||||
/** @var Budget $budget */
|
||||
foreach ($collection as $budget) {
|
||||
if ($budget->name === $name) {
|
||||
return $budget;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->user->budgets()->where('name', $name)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -55,21 +55,7 @@ class CategoryFactory
|
||||
*/
|
||||
public function findByName(string $name): ?Category
|
||||
{
|
||||
$result = null;
|
||||
/** @var Collection $collection */
|
||||
$collection = $this->user->categories()->get();
|
||||
|
||||
// TODO no longer need to loop like this
|
||||
|
||||
/** @var Category $category */
|
||||
foreach ($collection as $category) {
|
||||
if ($category->name === $name) {
|
||||
$result = $category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $this->user->categories()->where('name', $name)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -90,18 +90,7 @@ class PiggyBankFactory
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank
|
||||
{
|
||||
$set = $this->user->piggyBanks()->get();
|
||||
|
||||
// TODO no longer need to loop like this
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($set as $piggy) {
|
||||
if ($piggy->name === $name) {
|
||||
return $piggy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->user->piggyBanks()->where('name', $name)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user