Small code cleanup

This commit is contained in:
James Cole
2024-01-04 07:44:52 +01:00
parent ff98f3cc3e
commit 8be27a2201
17 changed files with 1860 additions and 1874 deletions

View File

@@ -226,21 +226,22 @@
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v3.45.0",
"version": "v3.46.0",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "c0daa33cb2533cd73f48dde1c70c2afa3e7953b5"
"reference": "be6831c9af1740470d2a773119b9273f8ac1c3d2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/c0daa33cb2533cd73f48dde1c70c2afa3e7953b5",
"reference": "c0daa33cb2533cd73f48dde1c70c2afa3e7953b5",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/be6831c9af1740470d2a773119b9273f8ac1c3d2",
"reference": "be6831c9af1740470d2a773119b9273f8ac1c3d2",
"shasum": ""
},
"require": {
"composer/semver": "^3.4",
"composer/xdebug-handler": "^3.0.3",
"ext-filter": "*",
"ext-json": "*",
"ext-tokenizer": "*",
"php": "^7.4 || ^8.0",
@@ -304,7 +305,7 @@
],
"support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.45.0"
"source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.46.0"
},
"funding": [
{
@@ -312,7 +313,7 @@
"type": "github"
}
],
"time": "2023-12-30T02:07:07+00:00"
"time": "2024-01-03T21:38:46+00:00"
},
{
"name": "psr/container",

View File

@@ -59,9 +59,7 @@ class MoveTransactionsRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param validator $validator
* TODO this is duplicate
* TODO this is duplicate.
*/
public function withValidator(Validator $validator): void
{

View File

@@ -70,9 +70,7 @@ class UpdateRequest extends FormRequest
/**
* Configure the validator instance with special rules for after the basic validation rules.
*
* @param Validator $validator
* TODO duplicate code
* TODO duplicate code.
*/
public function withValidator(Validator $validator): void
{

View File

@@ -77,11 +77,8 @@ class BudgetController extends Controller
}
/**
* @param DateRequest $request
*
* TODO see autocomplete/accountcontroller
*
* @throws FireflyException
* TODO see autocomplete/accountcontroller.
*/
public function dashboard(DateRequest $request): JsonResponse
{

View File

@@ -169,7 +169,6 @@ class StoreRequest extends FormRequest
'transactions.*.invoice_date' => 'date|nullable',
// TODO include location and ability to process it.
];
}

View File

@@ -374,7 +374,8 @@ class TransactionJournalFactory
->where('transaction_journals.user_id', $this->user->id)
->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
->with(['transactionJournal', 'transactionJournal.transactionGroup'])
->first(['journal_meta.*']);
->first(['journal_meta.*'])
;
if (null !== $result) {
app('log')->warning(sprintf('Found a duplicate in errorIfDuplicate because hash %s is not unique!', $hash));
$journal = $result->transactionJournal()->withTrashed()->first();

View File

@@ -129,8 +129,8 @@ class CreateController extends Controller
];
// var_dump($optionalFields);
// exit;
$optionalFields['external_url'] = $optionalFields['external_url'] ?? false;
$optionalFields['location'] = $optionalFields['location'] ?? false;
$optionalFields['external_url'] ??= false;
$optionalFields['location'] ??= false;
session()->put('preFilled', $preFilled);
return view(

View File

@@ -72,8 +72,7 @@ class AccountRepository implements AccountRepositoryInterface
/** @var Account $account */
foreach ($accounts as $account) {
$byName = $this->user->accounts()->where('name', $account->name)
->where('id', '!=', $account->id)->first()
;
->where('id', '!=', $account->id)->first();
if (null !== $byName) {
$result->push($account);
$result->push($byName);
@@ -82,8 +81,7 @@ class AccountRepository implements AccountRepositoryInterface
}
if (null !== $account->iban) {
$byIban = $this->user->accounts()->where('iban', $account->iban)
->where('id', '!=', $account->id)->first()
;
->where('id', '!=', $account->id)->first();
if (null !== $byIban) {
$result->push($account);
$result->push($byIban);
@@ -109,8 +107,7 @@ class AccountRepository implements AccountRepositoryInterface
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
)
;
);
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -246,8 +243,7 @@ class AccountRepository implements AccountRepositoryInterface
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*'])
;
->first(['transaction_journals.*']);
return $journal?->transactionGroup;
}
@@ -294,8 +290,7 @@ class AccountRepository implements AccountRepositoryInterface
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*'])
;
->first(['transaction_journals.*']);
if (null === $journal) {
return null;
}
@@ -315,8 +310,7 @@ class AccountRepository implements AccountRepositoryInterface
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s')
;
->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s');
}
public function getOpeningBalanceGroup(Account $account): ?TransactionGroup
@@ -326,13 +320,19 @@ class AccountRepository implements AccountRepositoryInterface
return $journal?->transactionGroup;
}
/**
*
*
* @param Account $account
*
* @return TransactionJournal|null
*/
public function getOpeningBalance(Account $account): ?TransactionJournal
{
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*'])
;
->first(['transaction_journals.*']);
}
public function getPiggyBanks(Account $account): Collection
@@ -357,8 +357,7 @@ class AccountRepository implements AccountRepositoryInterface
/** @var null|Account $current */
$current = $this->user->accounts()->where('account_type_id', $type->id)
->where('name', $name)
->first()
;
->first();
if (null !== $current) {
return $current;
@@ -517,8 +516,7 @@ class AccountRepository implements AccountRepositoryInterface
->orderBy('transaction_journals.order', 'DESC')
->where('transaction_journals.user_id', $this->user->id)
->orderBy('transaction_journals.id', 'ASC')
->first(['transaction_journals.id'])
;
->first(['transaction_journals.id']);
if (null !== $first) {
return TransactionJournal::find($first->id);
}
@@ -561,8 +559,7 @@ class AccountRepository implements AccountRepositoryInterface
->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC')
->with(['accountType'])
;
->with(['accountType']);
if ('' !== $query) {
// split query on spaces just in case:
$parts = explode(' ', $query);
@@ -587,8 +584,7 @@ class AccountRepository implements AccountRepositoryInterface
->orderBy('accounts.order', 'ASC')
->orderBy('accounts.account_type_id', 'ASC')
->orderBy('accounts.name', 'ASC')
->with(['accountType', 'accountMeta'])
;
->with(['accountType', 'accountMeta']);
if ('' !== $query) {
// split query on spaces just in case:
$parts = explode(' ', $query);

View File

@@ -273,10 +273,6 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return TransactionCurrency::where('code', $currencyCode)->first();
}
/**
* @param TransactionCurrency $currency
* Enables a currency
*/
public function enable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id]);

View File

@@ -216,10 +216,9 @@ class Preferences
}
/**
* @param null $default
* TODO remove me.
*
* @return null|preference
* TODO remove me
* @param null $default
*
* @throws FireflyException
*/

View File

@@ -65,6 +65,23 @@ trait AppendsLocationData
*/
abstract public function boolean($key = null, $default = false);
public function addFromromTransactionStore(array $information, array $return): array
{
$return['store_location'] = false;
if (true === $information['store_location']) {
$long = array_key_exists('longitude', $information) ? $information['longitude'] : null;
$lat = array_key_exists('latitude', $information) ? $information['latitude'] : null;
if (null !== $long && null !== $lat && $this->validLongitude($long) && $this->validLatitude($lat)) {
$return['store_location'] = true;
$return['longitude'] = $information['longitude'];
$return['latitude'] = $information['latitude'];
$return['zoom_level'] = $information['zoom_level'];
}
}
return $return;
}
/**
* Read the submitted Request data and add new or updated Location data to the array.
*/
@@ -119,37 +136,17 @@ trait AppendsLocationData
return $data;
}
/**
* @param array $information
* @param array $return
*
* @return array
*/
public function addFromromTransactionStore(array $information, array $return): array
{
$return['store_location'] = false;
if (true === $information['store_location']) {
$long = array_key_exists('longitude', $information) ? $information['longitude'] : null;
$lat = array_key_exists('latitude', $information) ? $information['latitude'] : null;
if (null !== $long && null !== $lat && $this->validLongitude($long) && $this->validLatitude($lat)) {
$return['store_location'] = true;
$return['longitude'] = $information['longitude'];
$return['latitude'] = $information['latitude'];
$return['zoom_level'] = $information['zoom_level'];
}
}
return $return;
}
private function validLongitude(string $longitude): bool
{
$number = (float) $longitude;
return $number >= -180 && $number <= 180;
}
private function validLatitude(string $latitude): bool
{
$number = (float) $latitude;
return $number >= -90 && $number <= 90;
}

View File

@@ -81,8 +81,7 @@ class AmountFormat extends AbstractExtension
/**
* Will format the amount by the currency related to the given account.
*
* @return twigFunction
* TODO remove me when layout v1 is deprecated
* TODO Remove me when v2 hits.
*/
protected function formatAmountByAccount(): TwigFunction
{

View File

@@ -346,8 +346,9 @@ class General extends AbstractExtension
}
/**
* @return twigFunction
* TODO remove me when layout v1 is deprecated
* TODO Remove me when v2 hits.
*
* @return TwigFunction
*/
protected function getMetaField(): TwigFunction
{

View File

@@ -199,9 +199,12 @@ class AccountTransformer extends AbstractTransformer
}
/**
* @return array
*
* TODO refactor call to get~OpeningBalanceAmount / Date because it is a lot of queries
*
* @param Account $account
* @param string $accountType
*
* @return array
*/
private function getOpeningBalance(Account $account, string $accountType): array
{

View File

@@ -103,7 +103,8 @@ class TransactionGroupTransformer extends AbstractTransformer
$tags = DB::table('tag_transaction_journal')
->leftJoin('tags', 'tags.id', 'tag_transaction_journal.tag_id')
->whereIn('tag_transaction_journal.transaction_journal_id', array_keys($journals))
->get(['tag_transaction_journal.transaction_journal_id', 'tags.tag']);
->get(['tag_transaction_journal.transaction_journal_id', 'tags.tag'])
;
/** @var \stdClass $tag */
foreach ($tags as $tag) {