From 5d0cdc4ffa12ece600ab78d70eacefc9f3903068 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 17 Feb 2017 06:42:36 +0100 Subject: [PATCH] Various code cleanup. --- app/Console/Commands/CreateImport.php | 2 +- .../Commands/UpgradeFireflyInstructions.php | 31 ++++--- app/Export/Collector/AttachmentCollector.php | 1 - app/Export/Collector/CollectorInterface.php | 14 +-- app/Helpers/Attachments/AttachmentHelper.php | 2 +- app/Helpers/Collector/JournalCollector.php | 1 + app/Helpers/Report/BalanceReportHelper.php | 4 +- app/Helpers/Report/ReportHelper.php | 3 - app/Helpers/Report/ReportHelperInterface.php | 1 - app/Http/Controllers/AccountController.php | 26 +++--- app/Http/Controllers/HomeController.php | 3 +- app/Http/Controllers/ReportController.php | 72 +++++++-------- app/Http/Middleware/Range.php | 1 - app/Http/Middleware/StartFireflySession.php | 1 - app/Http/Middleware/VerifyCsrfToken.php | 8 +- app/Http/Requests/Request.php | 2 +- app/Http/Requests/TagFormRequest.php | 1 - app/Import/ImportStorage.php | 4 +- app/Import/Setup/CsvSetup.php | 4 +- app/Models/Budget.php | 2 +- app/Providers/FireflyServiceProvider.php | 6 +- app/Providers/PiggyBankServiceProvider.php | 2 +- app/Providers/RuleServiceProvider.php | 1 + .../Currency/CurrencyRepository.php | 16 ++-- .../Journal/JournalRepository.php | 16 ++-- app/Repositories/Tag/TagRepository.php | 92 +++++++++---------- app/Rules/Actions/SetBudget.php | 6 +- app/Rules/Actions/SetDestinationAccount.php | 2 +- app/Rules/Actions/SetSourceAccount.php | 2 +- app/Rules/Triggers/AbstractTrigger.php | 1 - app/Support/Search/SearchInterface.php | 10 +- 31 files changed, 168 insertions(+), 169 deletions(-) diff --git a/app/Console/Commands/CreateImport.php b/app/Console/Commands/CreateImport.php index 00ff5094c6..d9b51a3b6d 100644 --- a/app/Console/Commands/CreateImport.php +++ b/app/Console/Commands/CreateImport.php @@ -81,7 +81,7 @@ class CreateImport extends Command /** @var ImportJobRepositoryInterface $jobRepository */ $jobRepository = app(ImportJobRepositoryInterface::class); $jobRepository->setUser($user); - $job = $jobRepository->create($type); + $job = $jobRepository->create($type); $this->line(sprintf('Created job "%s"...', $job->key)); Artisan::call('firefly:encrypt', ['file' => $file, 'key' => $job->key]); diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php index a88c8ab79c..03e7761172 100644 --- a/app/Console/Commands/UpgradeFireflyInstructions.php +++ b/app/Console/Commands/UpgradeFireflyInstructions.php @@ -84,21 +84,8 @@ class UpgradeFireflyInstructions extends Command } } - /** - * Show a line - */ - private function showLine() + private function installInstructions() { - $line = '+'; - for ($i = 0; $i < 78; $i++) { - $line .= '-'; - } - $line .= '+'; - $this->line($line); - - } - - private function installInstructions() { /** @var string $version */ $version = config('firefly.version'); $config = config('upgrade.text.install'); @@ -120,6 +107,7 @@ class UpgradeFireflyInstructions extends Command $this->boxed('Firefly III should be ready for use.'); $this->boxed(''); $this->showLine(); + return; } @@ -129,6 +117,20 @@ class UpgradeFireflyInstructions extends Command $this->showLine(); } + /** + * Show a line + */ + private function showLine() + { + $line = '+'; + for ($i = 0; $i < 78; $i++) { + $line .= '-'; + } + $line .= '+'; + $this->line($line); + + } + private function updateInstructions() { /** @var string $version */ @@ -152,6 +154,7 @@ class UpgradeFireflyInstructions extends Command $this->boxed('Firefly III should be ready for use.'); $this->boxed(''); $this->showLine(); + return; } diff --git a/app/Export/Collector/AttachmentCollector.php b/app/Export/Collector/AttachmentCollector.php index 810dc1db85..f65cb72ae3 100644 --- a/app/Export/Collector/AttachmentCollector.php +++ b/app/Export/Collector/AttachmentCollector.php @@ -16,7 +16,6 @@ namespace FireflyIII\Export\Collector; use Carbon\Carbon; use Crypt; use FireflyIII\Models\Attachment; -use FireflyIII\Models\ExportJob; use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Collection; diff --git a/app/Export/Collector/CollectorInterface.php b/app/Export/Collector/CollectorInterface.php index 54a3fa88a1..6cbbac9c2a 100644 --- a/app/Export/Collector/CollectorInterface.php +++ b/app/Export/Collector/CollectorInterface.php @@ -33,13 +33,6 @@ interface CollectorInterface */ public function run(): bool; - /** - * @param ExportJob $job - * - * @return mixed - */ - public function setJob(ExportJob $job); - /** * @param Collection $entries * @@ -48,4 +41,11 @@ interface CollectorInterface */ public function setEntries(Collection $entries); + /** + * @param ExportJob $job + * + * @return mixed + */ + public function setJob(ExportJob $job); + } diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index c7f7902109..74b189469b 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -45,7 +45,7 @@ class AttachmentHelper implements AttachmentHelperInterface public function __construct() { $this->maxUploadSize = intval(config('firefly.maxUploadSize')); - $this->allowedMimes = (array) config('firefly.allowedMimes'); + $this->allowedMimes = (array)config('firefly.allowedMimes'); $this->errors = new MessageBag; $this->messages = new MessageBag; $this->uploadDisk = Storage::disk('upload'); diff --git a/app/Helpers/Collector/JournalCollector.php b/app/Helpers/Collector/JournalCollector.php index f709eff9ba..3a146310fd 100644 --- a/app/Helpers/Collector/JournalCollector.php +++ b/app/Helpers/Collector/JournalCollector.php @@ -503,6 +503,7 @@ class JournalCollector implements JournalCollectorInterface public function withOpposingAccount(): JournalCollectorInterface { $this->joinOpposingTables(); + return $this; } diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.php index ca0667cf66..2c6dae78a8 100644 --- a/app/Helpers/Report/BalanceReportHelper.php +++ b/app/Helpers/Report/BalanceReportHelper.php @@ -158,7 +158,9 @@ class BalanceReportHelper implements BalanceReportHelperInterface foreach ($accounts as $account) { $balanceEntry = new BalanceEntry; $balanceEntry->setAccount($account); - $spent = $this->budgetRepository->spentInPeriod(new Collection([$budgetLimit->budget]), new Collection([$account]), $budgetLimit->start_date, $budgetLimit->end_date); + $spent = $this->budgetRepository->spentInPeriod( + new Collection([$budgetLimit->budget]), new Collection([$account]), $budgetLimit->start_date, $budgetLimit->end_date + ); $balanceEntry->setSpent($spent); $line->addBalanceEntry($balanceEntry); } diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 2dfb605ee3..20a008e87a 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -16,15 +16,12 @@ namespace FireflyIII\Helpers\Report; use Carbon\Carbon; use FireflyIII\Helpers\Collection\Bill as BillCollection; use FireflyIII\Helpers\Collection\BillLine; -use FireflyIII\Helpers\Collection\Category as CategoryCollection; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\FiscalHelperInterface; use FireflyIII\Models\Bill; -use FireflyIII\Models\Category; use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; -use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use Illuminate\Support\Collection; /** diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 9124821593..fb14625126 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -15,7 +15,6 @@ namespace FireflyIII\Helpers\Report; use Carbon\Carbon; use FireflyIII\Helpers\Collection\Bill as BillCollection; -use FireflyIII\Helpers\Collection\Category as CategoryCollection; use FireflyIII\Helpers\Collection\Expense; use FireflyIII\Helpers\Collection\Income; use Illuminate\Support\Collection; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 66b2ff26a0..47febc0f84 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -116,9 +116,9 @@ class AccountController extends Controller } /** - * @param Request $request - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param Request $request + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ @@ -190,8 +190,8 @@ class AccountController extends Controller } /** - * @param AccountRepositoryInterface $repository - * @param string $what + * @param AccountRepositoryInterface $repository + * @param string $what * * @return View */ @@ -260,9 +260,9 @@ class AccountController extends Controller } /** - * @param Request $request - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param Request $request + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return View */ @@ -323,8 +323,8 @@ class AccountController extends Controller } /** - * @param AccountFormRequest $request - * @param AccountRepositoryInterface $repository + * @param AccountFormRequest $request + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @@ -356,9 +356,9 @@ class AccountController extends Controller } /** - * @param AccountFormRequest $request - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param AccountFormRequest $request + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 9dbce2de32..460a3e98cd 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -23,7 +23,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Collection; use Log; use Preferences; -use Route; use Session; use View; @@ -91,7 +90,7 @@ class HomeController extends Controller public function flush(Request $request) { Preferences::mark(); - $request->session()->forget(['start', 'end','_previous', 'viewRange', 'range', 'is_custom_range']); + $request->session()->forget(['start', 'end', '_previous', 'viewRange', 'range', 'is_custom_range']); Artisan::call('cache:clear'); return redirect(route('index')); diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 5c32e086f9..a3ac8ab74a 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -98,42 +98,6 @@ class ReportController extends Controller } - /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end - * - * @return string - */ - public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) - { - if ($end < $start) { - return view('error')->with('message', trans('firefly.end_after_start_date')); - } - if ($start < session('first')) { - $start = session('first'); - } - - View::share( - 'subTitle', trans( - 'firefly.report_tag', - [ - 'start' => $start->formatLocalized($this->monthFormat), - 'end' => $end->formatLocalized($this->monthFormat), - ] - ) - ); - - $generator = ReportGeneratorFactory::reportGenerator('Tag', $start, $end); - $generator->setAccounts($accounts); - $generator->setTags($tags); - $result = $generator->generate(); - - return $result; - - } - /** * @param Collection $accounts * @param Collection $budgets @@ -357,6 +321,42 @@ class ReportController extends Controller return redirect($uri); } + /** + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end + * + * @return string + */ + public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) + { + if ($end < $start) { + return view('error')->with('message', trans('firefly.end_after_start_date')); + } + if ($start < session('first')) { + $start = session('first'); + } + + View::share( + 'subTitle', trans( + 'firefly.report_tag', + [ + 'start' => $start->formatLocalized($this->monthFormat), + 'end' => $end->formatLocalized($this->monthFormat), + ] + ) + ); + + $generator = ReportGeneratorFactory::reportGenerator('Tag', $start, $end); + $generator->setAccounts($accounts); + $generator->setTags($tags); + $result = $generator->generate(); + + return $result; + + } + /** * @return string */ diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index fdf5322a4d..7bc60818c9 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -17,7 +17,6 @@ use Amount; use App; use Carbon\Carbon; use Closure; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Contracts\Auth\Guard; use Illuminate\Http\Request; diff --git a/app/Http/Middleware/StartFireflySession.php b/app/Http/Middleware/StartFireflySession.php index ba6c518a08..f72e13aed3 100644 --- a/app/Http/Middleware/StartFireflySession.php +++ b/app/Http/Middleware/StartFireflySession.php @@ -14,7 +14,6 @@ namespace FireflyIII\Http\Middleware; use Illuminate\Http\Request; use Illuminate\Session\Middleware\StartSession; use Illuminate\Session\SessionManager; -use Log; /** * Class StartFireflySession diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 11ec0455c9..0c7c3ed591 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,9 +12,10 @@ declare(strict_types = 1); namespace FireflyIII\Http\Middleware; +use Carbon\Carbon; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; use Symfony\Component\HttpFoundation\Cookie; -use Carbon\Carbon; + /** * Class VerifyCsrfToken * @@ -35,8 +36,9 @@ class VerifyCsrfToken extends BaseVerifier /** * Add the CSRF token to the response cookies. * - * @param \Illuminate\Http\Request $request - * @param \Symfony\Component\HttpFoundation\Response $response + * @param \Illuminate\Http\Request $request + * @param \Symfony\Component\HttpFoundation\Response $response + * * @return \Symfony\Component\HttpFoundation\Response */ protected function addCookieToResponse($request, $response) diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index e73b17ac60..cf8bbae71e 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -87,7 +87,7 @@ class Request extends FormRequest */ protected function string(string $field): string { - $string = $this->get($field) ?? ''; + $string = $this->get($field) ?? ''; $search = [ "\u{0001}", // start of heading "\u{0002}", // start of text diff --git a/app/Http/Requests/TagFormRequest.php b/app/Http/Requests/TagFormRequest.php index 544b53c0b0..ce85aaa94f 100644 --- a/app/Http/Requests/TagFormRequest.php +++ b/app/Http/Requests/TagFormRequest.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Requests; -use Carbon\Carbon; use FireflyIII\Repositories\Tag\TagRepositoryInterface; /** diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.php index ec68385e0d..89b5e76ded 100644 --- a/app/Import/ImportStorage.php +++ b/app/Import/ImportStorage.php @@ -162,7 +162,7 @@ class ImportStorage /** @var TagRepositoryInterface $repository */ $repository = app(TagRepositoryInterface::class); $repository->setUser($this->user); - $data = [ + $data = [ 'tag' => trans('firefly.import_with_key', ['key' => $this->job->key]), 'date' => new Carbon, 'description' => null, @@ -171,7 +171,7 @@ class ImportStorage 'zoomLevel' => null, 'tagMode' => 'nothing', ]; - $tag = $repository->store($data); + $tag = $repository->store($data); return $tag; } diff --git a/app/Import/Setup/CsvSetup.php b/app/Import/Setup/CsvSetup.php index 3d0fc10ed3..01fcdc756a 100644 --- a/app/Import/Setup/CsvSetup.php +++ b/app/Import/Setup/CsvSetup.php @@ -182,8 +182,8 @@ class CsvSetup implements SetupInterface { /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); - $importId = $data['csv_import_account'] ?? 0; - $account = $repository->find(intval($importId)); + $importId = $data['csv_import_account'] ?? 0; + $account = $repository->find(intval($importId)); $hasHeaders = isset($data['has_headers']) && intval($data['has_headers']) === 1 ? true : false; $config = $this->job->configuration; diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 504802e05a..84ef039aa0 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -44,7 +44,7 @@ class Budget extends Model 'encrypted' => 'boolean', ]; /** @var array */ - protected $dates = ['created_at', 'updated_at', 'deleted_at']; + protected $dates = ['created_at', 'updated_at', 'deleted_at']; protected $fillable = ['user_id', 'name', 'active']; protected $hidden = ['encrypted']; protected $rules = ['name' => 'required|between:1,200',]; diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 2ef97e48d2..40f456b4d0 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -122,14 +122,14 @@ class FireflyServiceProvider extends ServiceProvider $this->app->bind(MetaPieChartInterface::class, MetaPieChart::class); // other generators - $this->app->bind(ProcessorInterface::class,Processor::class); - $this->app->bind(ImportProcedureInterface::class,ImportProcedure::class); + $this->app->bind(ProcessorInterface::class, Processor::class); + $this->app->bind(ImportProcedureInterface::class, ImportProcedure::class); $this->app->bind(UserRepositoryInterface::class, UserRepository::class); $this->app->bind(AttachmentHelperInterface::class, AttachmentHelper::class); $this->app->bind(HelpInterface::class, Help::class); $this->app->bind(ReportHelperInterface::class, ReportHelper::class); - $this->app->bind(FiscalHelperInterface::class,FiscalHelper::class); + $this->app->bind(FiscalHelperInterface::class, FiscalHelper::class); $this->app->bind(BalanceReportHelperInterface::class, BalanceReportHelper::class); $this->app->bind(BudgetReportHelperInterface::class, BudgetReportHelper::class); } diff --git a/app/Providers/PiggyBankServiceProvider.php b/app/Providers/PiggyBankServiceProvider.php index fb1aaf7d5f..d91f362114 100644 --- a/app/Providers/PiggyBankServiceProvider.php +++ b/app/Providers/PiggyBankServiceProvider.php @@ -14,7 +14,6 @@ declare(strict_types = 1); namespace FireflyIII\Providers; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\PiggyBank\PiggyBankRepository; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use Illuminate\Foundation\Application; @@ -53,6 +52,7 @@ class PiggyBankServiceProvider extends ServiceProvider if ($app->auth->check()) { $repository->setUser(auth()->user()); } + return $repository; } ); diff --git a/app/Providers/RuleServiceProvider.php b/app/Providers/RuleServiceProvider.php index 5d694411b3..9d047d9e74 100644 --- a/app/Providers/RuleServiceProvider.php +++ b/app/Providers/RuleServiceProvider.php @@ -51,6 +51,7 @@ class RuleServiceProvider extends ServiceProvider if ($app->auth->check()) { $repository->setUser(auth()->user()); } + return $repository; } ); diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php index bb1444d73c..b053780cac 100644 --- a/app/Repositories/Currency/CurrencyRepository.php +++ b/app/Repositories/Currency/CurrencyRepository.php @@ -30,14 +30,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** @var User */ private $user; - /** - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } - /** * @param TransactionCurrency $currency * @@ -186,6 +178,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface return $preferred; } + /** + * @param User $user + */ + public function setUser(User $user) + { + $this->user = $user; + } + /** * @param array $data * diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 12ce898ff1..31ac868afa 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -43,14 +43,6 @@ class JournalRepository implements JournalRepositoryInterface /** @var array */ private $validMetaFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'notes']; - /** - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } - /** * @param TransactionJournal $journal * @param TransactionType $type @@ -143,6 +135,14 @@ class JournalRepository implements JournalRepositoryInterface return TransactionType::orderBy('type', 'ASC')->get(); } + /** + * @param User $user + */ + public function setUser(User $user) + { + $this->user = $user; + } + /** * @param array $data * diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 9f91816252..57bade58b5 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -34,14 +34,6 @@ class TagRepository implements TagRepositoryInterface /** @var User */ private $user; - /** - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } - /** * * @param TransactionJournal $journal @@ -88,6 +80,25 @@ class TagRepository implements TagRepositoryInterface return true; } + /** + * @param Tag $tag + * @param Carbon $start + * @param Carbon $end + * + * @return string + */ + public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string + { + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setUser($this->user); + $collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag); + $set = $collector->getJournals(); + $sum = strval($set->sum('transaction_amount')); + + return $sum; + } + /** * @param int $tagId * @@ -167,6 +178,33 @@ class TagRepository implements TagRepositoryInterface return new Carbon; } + /** + * @param User $user + */ + public function setUser(User $user) + { + $this->user = $user; + } + + /** + * @param Tag $tag + * @param Carbon $start + * @param Carbon $end + * + * @return string + */ + public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string + { + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setUser($this->user); + $collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag); + $set = $collector->getJournals(); + $sum = strval($set->sum('transaction_amount')); + + return $sum; + } + /** * @param array $data * @@ -383,42 +421,4 @@ class TagRepository implements TagRepositoryInterface return false; } - - /** - * @param Tag $tag - * @param Carbon $start - * @param Carbon $end - * - * @return string - */ - public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string - { - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setUser($this->user); - $collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag); - $set = $collector->getJournals(); - $sum = strval($set->sum('transaction_amount')); - - return $sum; - } - - /** - * @param Tag $tag - * @param Carbon $start - * @param Carbon $end - * - * @return string - */ - public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string - { - /** @var JournalCollectorInterface $collector */ - $collector = app(JournalCollectorInterface::class); - $collector->setUser($this->user); - $collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag); - $set = $collector->getJournals(); - $sum = strval($set->sum('transaction_amount')); - - return $sum; - } } diff --git a/app/Rules/Actions/SetBudget.php b/app/Rules/Actions/SetBudget.php index e9f8c1fae9..7797501e2b 100644 --- a/app/Rules/Actions/SetBudget.php +++ b/app/Rules/Actions/SetBudget.php @@ -52,9 +52,9 @@ class SetBudget implements ActionInterface /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class); $repository->setUser($journal->user); - $search = $this->action->action_value; - $budgets = $repository->getActiveBudgets(); - $budget = $budgets->filter( + $search = $this->action->action_value; + $budgets = $repository->getActiveBudgets(); + $budget = $budgets->filter( function (Budget $current) use ($search) { return $current->name == $search; } diff --git a/app/Rules/Actions/SetDestinationAccount.php b/app/Rules/Actions/SetDestinationAccount.php index 25677e546b..33ca3d27c3 100644 --- a/app/Rules/Actions/SetDestinationAccount.php +++ b/app/Rules/Actions/SetDestinationAccount.php @@ -62,7 +62,7 @@ class SetDestinationAccount implements ActionInterface $this->journal = $journal; $this->repository = app(AccountRepositoryInterface::class); $this->repository->setUser($journal->user); - $count = $journal->transactions()->count(); + $count = $journal->transactions()->count(); if ($count > 2) { Log::error(sprintf('Cannot change destination account of journal #%d because it is a split journal.', $journal->id)); diff --git a/app/Rules/Actions/SetSourceAccount.php b/app/Rules/Actions/SetSourceAccount.php index fc8067856c..07f0125d4a 100644 --- a/app/Rules/Actions/SetSourceAccount.php +++ b/app/Rules/Actions/SetSourceAccount.php @@ -62,7 +62,7 @@ class SetSourceAccount implements ActionInterface $this->journal = $journal; $this->repository = app(AccountRepositoryInterface::class); $this->repository->setUser($journal->user); - $count = $journal->transactions()->count(); + $count = $journal->transactions()->count(); if ($count > 2) { Log::error(sprintf('Cannot change source account of journal #%d because it is a split journal.', $journal->id)); diff --git a/app/Rules/Triggers/AbstractTrigger.php b/app/Rules/Triggers/AbstractTrigger.php index 0fd9a3bfd8..d38e1dcd9f 100644 --- a/app/Rules/Triggers/AbstractTrigger.php +++ b/app/Rules/Triggers/AbstractTrigger.php @@ -75,7 +75,6 @@ class AbstractTrigger } - /** * @param RuleTrigger $trigger * @param TransactionJournal $journal diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php index ed9c3c6c88..918f3caee3 100644 --- a/app/Support/Search/SearchInterface.php +++ b/app/Support/Search/SearchInterface.php @@ -30,11 +30,6 @@ interface SearchInterface */ public function searchAccounts(array $words): Collection; - /** - * @param User $user - */ - public function setUser(User $user); - /** * @param array $words * @@ -63,4 +58,9 @@ interface SearchInterface * @return Collection */ public function searchTransactions(array $words): Collection; + + /** + * @param User $user + */ + public function setUser(User $user); }