Various code cleanup.

This commit is contained in:
James Cole 2017-02-17 06:42:36 +01:00
parent 1d979778e8
commit 5d0cdc4ffa
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
31 changed files with 168 additions and 169 deletions

View File

@ -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]);

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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');

View File

@ -503,6 +503,7 @@ class JournalCollector implements JournalCollectorInterface
public function withOpposingAccount(): JournalCollectorInterface
{
$this->joinOpposingTables();
return $this;
}

View File

@ -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);
}

View File

@ -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;
/**

View File

@ -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;

View File

@ -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
*/

View File

@ -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'));

View File

@ -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
*/

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -12,7 +12,6 @@
declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use Carbon\Carbon;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
/**

View File

@ -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;
}

View File

@ -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;

View File

@ -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',];

View File

@ -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);
}

View File

@ -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;
}
);

View File

@ -51,6 +51,7 @@ class RuleServiceProvider extends ServiceProvider
if ($app->auth->check()) {
$repository->setUser(auth()->user());
}
return $repository;
}
);

View File

@ -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
*

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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));

View File

@ -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));

View File

@ -75,7 +75,6 @@ class AbstractTrigger
}
/**
* @param RuleTrigger $trigger
* @param TransactionJournal $journal

View File

@ -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);
}