Clean up some code.

This commit is contained in:
James Cole 2021-04-05 21:52:55 +02:00
parent 6d855e119d
commit e4802ec958
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
35 changed files with 74 additions and 216 deletions

View File

@ -66,7 +66,7 @@ class ObjectGroupController extends Controller
$return = [];
$result = $this->repository->search($data['query'], $data['limit']);
/** @var ObjectGroup $account */
/** @var ObjectGroup $objectGroup */
foreach ($result as $objectGroup) {
$return[] = [
'id' => (string)$objectGroup->id,

View File

@ -25,7 +25,6 @@ namespace FireflyIII\Api\V1\Controllers\Data\Export;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\Export\ExportRequest;
use FireflyIII\Support\Export\ExportDataGenerator;
use FireflyIII\User;
use Illuminate\Http\Response as LaravelResponse;
use League\Csv\CannotInsertRecord;
@ -44,11 +43,8 @@ class ExportController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var ExportDataGenerator $exporter */
$this->exporter = app(ExportDataGenerator::class);
$this->exporter->setUser($user);
$this->exporter->setUser(auth()->user());
return $next($request);
}
@ -92,7 +88,7 @@ class ExportController extends Controller
->header('Expires', '0')
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->header('Pragma', 'public')
->header('Content-Length', strlen($data[$key]));
->header('Content-Length', (string)strlen($data[$key]));
return $response;
}

View File

@ -44,9 +44,8 @@ class TagController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$user = auth()->user();
$this->repository = app(TagRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}
@ -128,7 +127,7 @@ class TagController extends Controller
$collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end)->setSourceAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $entry */
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];

View File

@ -130,7 +130,7 @@ class TagController extends Controller
$collector->setTypes([TransactionType::DEPOSIT])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $entry */
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];

View File

@ -132,7 +132,7 @@ class TagController extends Controller
$collector->setTypes([TransactionType::TRANSFER])->setRange($start, $end)->setDestinationAccounts($accounts);
$collector->setTags($tags);
$genericSet = $collector->getExtractedJournals();
/** @var array $entry */
/** @var array $journal */
foreach ($genericSet as $journal) {
$currencyId = (int)$journal['currency_id'];
$foreignCurrencyId = (int)$journal['foreign_currency_id'];

View File

@ -100,7 +100,7 @@ class ShowController extends Controller
->header('Expires', '0')
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->header('Pragma', 'public')
->header('Content-Length', strlen($content));
->header('Content-Length', (string)strlen($content));
return $response;
}

View File

@ -46,12 +46,8 @@ class DestroyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -57,12 +57,8 @@ class ListController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -51,12 +51,8 @@ class ShowController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -52,12 +52,8 @@ class StoreController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -49,12 +49,8 @@ class UpdateController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var BillRepositoryInterface repository */
$this->repository = app(BillRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -46,12 +46,8 @@ class DestroyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -56,12 +56,8 @@ class ListController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -51,12 +51,8 @@ class ShowController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -49,12 +49,8 @@ class StoreController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -49,12 +49,8 @@ class UpdateController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $admin */
$admin = auth()->user();
/** @var CategoryRepositoryInterface repository */
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository->setUser($admin);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -46,12 +46,8 @@ class DestroyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -54,12 +54,8 @@ class ListController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -51,12 +51,8 @@ class ShowController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -49,12 +49,8 @@ class StoreController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -1,86 +0,0 @@
<?php
/*
* TriggerController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Log;
/**
* Class TriggerController
*/
class TriggerController extends Controller
{
private RecurringRepositoryInterface $repository;
/**
* RecurrenceController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
return $next($request);
}
);
}
/**
* @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
*
* TODO currently unused + unreachable.
*/
public function trigger(): JsonResponse
{
/** @var RecurringCronjob $recurring */
$recurring = app(RecurringCronjob::class);
try {
$result = $recurring->fire();
} catch (FireflyException $e) {
Log::error($e->getMessage());
throw new FireflyException('200022: Error in cron job.', 0, $e);
}
if (false === $result) {
return response()->json([], 204);
}
return response()->json();
}
}

View File

@ -49,12 +49,8 @@ class UpdateController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
/** @var RecurringRepositoryInterface repository */
$this->repository = app(RecurringRepositoryInterface::class);
$this->repository->setUser($user);
$this->repository->setUser(auth()->user());
return $next($request);
}

View File

@ -37,6 +37,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use Exception;
/**
* Class TriggerController

View File

@ -61,7 +61,7 @@ class MoveTransactionsRequest extends FormRequest
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
* TODO duplicate code.
* TODO duplicate code.
*
* @return void
*/

View File

@ -80,10 +80,10 @@ class StoreRequest extends FormRequest
// append Location information.
$data = $this->appendLocationData($data, null);
if ('liability' === $data['account_type'] || 'liabilities' === $data['account_type']) {
if ('liability' === $data['account_type_name'] || 'liabilities' === $data['account_type_name']) {
$data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
$data['account_type'] = $this->string('liability_type');
$data['account_type_name'] = $this->string('liability_type');
$data['account_type_id'] = null;
}

View File

@ -51,7 +51,7 @@ class UpdateRequest extends FormRequest
'name' => ['name', 'string'],
'active' => ['active', 'boolean'],
'include_net_worth' => ['include_net_worth', 'boolean'],
'account_type' => ['type', 'string'],
'account_type_name' => ['type', 'string'],
'virtual_balance' => ['virtual_balance', 'string'],
'iban' => ['iban', 'string'],
'BIC' => ['bic', 'string'],
@ -72,10 +72,10 @@ class UpdateRequest extends FormRequest
$data = $this->getAllData($fields);
$data = $this->appendLocationData($data, null);
if (array_key_exists('account_type', $data) && 'liability' === $data['account_type']) {
if (array_key_exists('account_type_name', $data) && 'liability' === $data['account_type_name']) {
$data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
$data['account_type'] = $this->nullableString('liability_type');
$data['account_type_name'] = $this->nullableString('liability_type');
$data['account_type_id'] = null;
}

View File

@ -85,13 +85,13 @@ class AccountFactory
Log::debug('Found nothing. Will create a new one.');
$return = $this->create(
[
'user_id' => $this->user->id,
'name' => $accountName,
'account_type_id' => $type->id,
'account_type' => null,
'virtual_balance' => '0',
'iban' => null,
'active' => true,
'user_id' => $this->user->id,
'name' => $accountName,
'account_type_id' => $type->id,
'account_type_name' => null,
'virtual_balance' => '0',
'iban' => null,
'active' => true,
]
);
}

View File

@ -38,7 +38,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $user_id
* @property string $name
* @property array|null $data
* @property int|string|array|null $data
* @property-read User $user
* @method static Builder|Preference newModelQuery()
* @method static Builder|Preference newQuery()

View File

@ -504,12 +504,12 @@ class AccountRepository implements AccountRepositoryInterface
}
$data = [
'account_type_id' => null,
'account_type' => AccountType::RECONCILIATION,
'active' => true,
'name' => $name,
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'account_type_id' => null,
'account_type_name' => AccountType::RECONCILIATION,
'active' => true,
'name' => $name,
'currency_id' => $currency->id,
'currency_code' => $currency->code,
];
/** @var AccountFactory $factory */

View File

@ -180,6 +180,14 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
return $objectGroup;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
/**
* @inheritDoc
*/
@ -197,12 +205,4 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
return $objectGroup;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
}

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\ObjectGroup;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
@ -87,6 +88,11 @@ interface ObjectGroupRepositoryInterface
*/
public function setOrder(ObjectGroup $objectGroup, int $newOrder): ObjectGroup;
/**
* @param User $user
*/
public function setUser(User $user): void;
/**
* @param ObjectGroup $objectGroup
* @param array $data

View File

@ -197,14 +197,14 @@ trait JournalServiceTrait
$account = $this->accountRepository->store(
[
'account_type_id' => null,
'account_type' => $preferredType,
'name' => $data['name'],
'virtual_balance' => null,
'active' => true,
'iban' => $data['iban'],
'currency_id' => $data['currency_id'] ?? null,
'order' => $this->accountRepository->maxOrder($preferredType),
'account_type_id' => null,
'account_type_name' => $preferredType,
'name' => $data['name'],
'virtual_balance' => null,
'active' => true,
'iban' => $data['iban'],
'currency_id' => $data['currency_id'] ?? null,
'order' => $this->accountRepository->maxOrder($preferredType),
]
);
// store BIC

View File

@ -32,6 +32,7 @@ use Laravel\Passport\Passport;
use Log;
use phpseclib\Crypt\RSA as LegacyRSA;
use phpseclib3\Crypt\RSA;
/**
* Trait CreateStuff
*
@ -54,7 +55,7 @@ trait CreateStuff
$assetAccount = [
'name' => $request->get('bank_name'),
'iban' => null,
'account_type' => 'asset',
'account_type_name' => 'asset',
'virtual_balance' => 0,
'account_type_id' => null,
'active' => true,
@ -84,7 +85,7 @@ trait CreateStuff
$assetAccount = [
'name' => (string)trans('firefly.cash_wallet', [], $language),
'iban' => null,
'account_type' => 'asset',
'account_type_name' => 'asset',
'virtual_balance' => 0,
'account_type_id' => null,
'active' => true,
@ -151,7 +152,7 @@ trait CreateStuff
$savingsAccount = [
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
'iban' => null,
'account_type' => 'asset',
'account_type_name' => 'asset',
'account_type_id' => null,
'virtual_balance' => 0,
'active' => true,

View File

@ -143,9 +143,9 @@ class Preferences
}
/**
* @param User $user
* @param string $name
* @param null|string $default
* @param User $user
* @param string $name
* @param null|string|int $default
*
* @return \FireflyIII\Models\Preference|null
*/

View File

@ -4,3 +4,4 @@ sonar.sources=app,bootstrap,database,resources/assets,resources/views,routes,tes
sonar.login=2859ca0fb90d8419e211190a8892b3e1721244cb
sonar.sourceEncoding=UTF-8
sonar.php.coverage.reportPaths=storage/build/clover-all.xml
sonar.host.url=http://172.16.21.6:10005