Refactor old methods.

This commit is contained in:
James Cole 2021-04-06 13:30:09 +02:00
parent 5ceef2e9c3
commit 69b1769f22
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
54 changed files with 191 additions and 478 deletions

View File

@ -73,7 +73,7 @@ class StoreRequest extends FormRequest
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('credit_card_type'),
'cc_monthly_payment_date' => $this->string('monthly_payment_date'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];

View File

@ -62,7 +62,7 @@ class UpdateRequest extends FormRequest
'opening_balance_date' => ['opening_balance_date', 'date'],
'cc_type' => ['credit_card_type', 'string'],
'cc_monthly_payment_date' => ['monthly_payment_date', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'interest' => ['interest', 'string'],
'interest_period' => ['interest_period', 'string'],
'order' => ['order', 'integer'],
@ -73,9 +73,9 @@ class UpdateRequest extends FormRequest
$data = $this->appendLocationData($data, null);
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'] = bcmul($this->string('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
$data['account_type_name'] = $this->nullableString('liability_type');
$data['account_type_name'] = $this->string('liability_type');
$data['account_type_id'] = null;
}
@ -97,9 +97,9 @@ class UpdateRequest extends FormRequest
$rules = [
'name' => sprintf('min:1|uniqueAccountForUser:%d', $account->id),
'type' => sprintf('in:%s', $types),
'iban' => ['iban', 'nullable', new UniqueIban($account, $this->nullableString('type'))],
'iban' => ['iban', 'nullable', new UniqueIban($account, $this->string('type'))],
'bic' => 'bic|nullable',
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->nullableString('type'))],
'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->string('type'))],
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',

View File

@ -47,7 +47,7 @@ class StoreRequest extends FormRequest
return [
'filename' => $this->string('filename'),
'title' => $this->string('title'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'attachable_type' => $this->string('attachable_type'),
'attachable_id' => $this->integer('attachable_id'),
];

View File

@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
$fields = [
'filename' => ['filename', 'string'],
'title' => ['title', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'attachable_type' => ['attachable_type', 'string'],
'attachable_id' => ['attachable_id', 'integer'],
];

View File

@ -59,7 +59,7 @@ class StoreRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];

View File

@ -57,7 +57,7 @@ class UpdateRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];

View File

@ -46,7 +46,7 @@ class StoreRequest extends FormRequest
{
return [
'name' => $this->string('name'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@ -45,7 +45,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'name' => ['name', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
];
return $this->getAllData($fields);

View File

@ -53,7 +53,7 @@ class StoreRequest extends FormRequest
$data['current_amount'] = $this->string('current_amount');
$data['startdate'] = $this->date('start_date');
$data['targetdate'] = $this->date('target_date');
$data['notes'] = $this->nlString('notes');
$data['notes'] = $this->stringWithNewlines('notes');
$data['object_group_id'] = $this->integer('object_group_id');
$data['object_group_title'] = $this->string('object_group_title');

View File

@ -52,7 +52,7 @@ class UpdateRequest extends FormRequest
'current_amount' => ['current_amount', 'string'],
'startdate' => ['start_date', 'date'],
'targetdate' => ['target_date', 'string'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
'order' => ['order', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
'object_group_id' => ['object_group_id', 'integer'],

View File

@ -58,7 +58,7 @@ class StoreRequest extends FormRequest
'nr_of_repetitions' => ['nr_of_repetitions', 'integer'],
'apply_rules' => ['apply_rules', 'boolean'],
'active' => ['active', 'boolean'],
'notes' => ['notes', 'nlString'],
'notes' => ['notes', 'stringWithNewlines'],
];
$recurrence = $this->getAllData($fields);

View File

@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'title' => ['title', 'string'],
'description' => ['description', 'nlString'],
'description' => ['description', 'stringWithNewlines'],
'rule_group_id' => ['rule_group_id', 'integer'],
'trigger' => ['trigger', 'string'],
'strict' => ['strict', 'boolean'],

View File

@ -46,7 +46,7 @@ class UpdateRequest extends FormRequest
// This is the way.
$fields = [
'title' => ['title', 'string'],
'description' => ['description', 'nlString'],
'description' => ['description', 'stringWithNewlines'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
];

View File

@ -78,75 +78,75 @@ class StoreRequest extends FormRequest
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),
'type' => $this->clearString($object['type'], false),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
'currency_code' => $this->clearString($object['currency_code'], false),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue((string)$object['foreign_currency_code']),
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string)$object['amount']),
'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']),
'amount' => $this->clearString((string)$object['amount'], false),
'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
// description.
'description' => $this->stringFromValue($object['description']),
'description' => $this->clearString($object['description'], false),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->stringFromValue((string)$object['source_name']),
'source_iban' => $this->stringFromValue((string)$object['source_iban']),
'source_number' => $this->stringFromValue((string)$object['source_number']),
'source_bic' => $this->stringFromValue((string)$object['source_bic']),
'source_name' => $this->clearString((string)$object['source_name'], false),
'source_iban' => $this->clearString((string)$object['source_iban'], false),
'source_number' => $this->clearString((string)$object['source_number'], false),
'source_bic' => $this->clearString((string)$object['source_bic'], false),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->stringFromValue((string)$object['destination_name']),
'destination_iban' => $this->stringFromValue((string)$object['destination_iban']),
'destination_number' => $this->stringFromValue((string)$object['destination_number']),
'destination_bic' => $this->stringFromValue((string)$object['destination_bic']),
'destination_name' => $this->clearString((string)$object['destination_name'], false),
'destination_iban' => $this->clearString((string)$object['destination_iban'], false),
'destination_number' => $this->clearString((string)$object['destination_number'], false),
'destination_bic' => $this->clearString((string)$object['destination_bic'], false),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->stringFromValue((string)$object['budget_name']),
'budget_name' => $this->clearString((string)$object['budget_name'], false),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->stringFromValue((string)$object['category_name']),
'category_name' => $this->clearString((string)$object['category_name'], false),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->stringFromValue((string)$object['bill_name']),
'bill_name' => $this->clearString((string)$object['bill_name'], false),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue((string)$object['piggy_bank_name']),
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->nlStringFromValue((string)$object['notes']),
'notes' => $this->clearString((string)$object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->stringFromValue((string)$object['internal_reference']),
'external_id' => $this->stringFromValue((string)$object['external_id']),
'internal_reference' => $this->clearString((string)$object['internal_reference'],false),
'external_id' => $this->clearString((string)$object['external_id'], false),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->stringFromValue((string)$object['bunq_payment_id']),
'external_uri' => $this->stringFromValue((string)$object['external_uri']),
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'],false),
'external_uri' => $this->clearString((string)$object['external_uri'], false),
'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
'sepa_db' => $this->stringFromValue($object['sepa_db']),
'sepa_country' => $this->stringFromValue($object['sepa_country']),
'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
'sepa_cc' => $this->clearString($object['sepa_cc'],false),
'sepa_ct_op' => $this->clearString($object['sepa_ct_op'],false),
'sepa_ct_id' => $this->clearString($object['sepa_ct_id'],false),
'sepa_db' => $this->clearString($object['sepa_db'],false),
'sepa_country' => $this->clearString($object['sepa_country'],false),
'sepa_ep' => $this->clearString($object['sepa_ep'],false),
'sepa_ci' => $this->clearString($object['sepa_ci'],false),
'sepa_batch_id' => $this->clearString($object['sepa_batch_id'],false),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),

View File

@ -194,7 +194,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->stringFromValue((string)$transaction[$fieldName]);
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName], false);
}
}
@ -211,7 +211,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->nlStringFromValue((string)$transaction[$fieldName]);
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
}
}

View File

@ -50,7 +50,7 @@ class StoreRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@ -50,7 +50,7 @@ class UpdateRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
'notes' => $this->nullableNlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@ -161,7 +161,7 @@ class TransactionJournalFactory
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']);
$billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null;
$description = app('steam')->cleanString((string)$row['description']);
$description = (string)$row['description'];
/** Manipulate basic fields */
$carbon->setTimezone(config('app.timezone'));

View File

@ -137,7 +137,7 @@ class EditController extends Controller
{
$data = [
'title' => $request->string('title'),
'description' => $request->nlString('description'),
'description' => $request->stringWithNewlines('description'),
'active' => 1 === (int)$request->input('active'),
];

View File

@ -58,7 +58,7 @@ class AccountFormRequest extends FormRequest
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('cc_type'),
'cc_monthly_payment_date' => $this->string('cc_monthly_payment_date'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
'include_net_worth' => '1',

View File

@ -49,7 +49,7 @@ class BillStoreRequest extends FormRequest
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'active' => $this->boolean('active'),
'object_group_title' => $this->string('object_group'),
];

View File

@ -50,7 +50,7 @@ class BillUpdateRequest extends FormRequest
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'active' => $this->boolean('active'),
'object_group_title' => $this->string('object_group'),
];

View File

@ -43,7 +43,7 @@ class CategoryFormRequest extends FormRequest
{
return [
'name' => $this->string('name'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
];
}

View File

@ -46,7 +46,7 @@ class PiggyBankStoreRequest extends FormRequest
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->string('object_group'),
];
}

View File

@ -47,7 +47,7 @@ class PiggyBankUpdateRequest extends FormRequest
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
'notes' => $this->nlString('notes'),
'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->string('object_group'),
];
}

View File

@ -48,7 +48,7 @@ class RuleFormRequest extends FormRequest
'rule_group_id' => $this->integer('rule_group_id'),
'active' => $this->boolean('active'),
'trigger' => $this->string('trigger'),
'description' => $this->nlString('description'),
'description' => $this->stringWithNewlines('description'),
'stop_processing' => $this->boolean('stop_processing'),
'strict' => $this->boolean('strict'),
'triggers' => $this->getRuleTriggerData(),

View File

@ -49,7 +49,7 @@ class RuleGroupFormRequest extends FormRequest
return [
'title' => $this->string('title'),
'description' => $this->nlString('description'),
'description' => $this->stringWithNewlines('description'),
'active' => $active,
];
}

View File

@ -44,6 +44,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int $transaction_journal_id
* @property string|null $description
* @property int|null $transaction_currency_id
* @property string $modified
* @property string $modified_foreign
* @property string $date
* @property string $max_date
* @property string $amount
* @property string|null $foreign_amount
* @property int|null $foreign_currency_id

View File

@ -23,9 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Cache;
use Carbon\Carbon;
use FireflyIII\Models\Category;
use Illuminate\Support\Collection;
use JsonException;
/**
* Class CacheProperties.
@ -34,10 +33,8 @@ use Illuminate\Support\Collection;
*/
class CacheProperties
{
/** @var string */
protected $hash = '';
/** @var Collection */
protected $properties;
protected string $hash = '';
protected Collection $properties;
/**
*
@ -52,8 +49,7 @@ class CacheProperties
}
/**
* @param $property
* @param Collection|Carbon|Category|array|int|string $property
* @param mixed $property
*/
public function addProperty($property): void
{
@ -90,19 +86,24 @@ class CacheProperties
}
/**
* @throws JsonException
*/
private function hash(): void
{
$content = '';
foreach ($this->properties as $property) {
$content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
try {
$content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
} catch (JsonException $e) {
// @ignoreException
$content .= md5(time());
}
}
$this->hash = substr(hash('sha256', $content), 0, 16);
}
/**
* @param $data
* @param (array|mixed)[]|Collection|\Carbon\Carbon|string $data
* @param mixed $data
*/
public function store($data): void
{

View File

@ -249,13 +249,4 @@ trait AppendsLocationData
}
/**
* Abstract method to ensure filling later.
*
* @param string $field
*
* @return string|null
*/
abstract protected function nullableString(string $field): ?string;
}

View File

@ -32,6 +32,70 @@ use Log;
*/
trait ConvertsDataTypes
{
/**
* Remove weird chars from strings.
*
* @param string $string
* @param bool $keepNewlines
*
* @return string
*/
public function clearString(string $string, bool $keepNewlines = true): string
{
$search = [
"\u{0001}", // start of heading
"\u{0002}", // start of text
"\u{0003}", // end of text
"\u{0004}", // end of transmission
"\u{0005}", // enquiry
"\u{0006}", // ACK
"\u{0007}", // BEL
"\u{0008}", // backspace
"\u{000E}", // shift out
"\u{000F}", // shift in
"\u{0010}", // data link escape
"\u{0011}", // DC1
"\u{0012}", // DC2
"\u{0013}", // DC3
"\u{0014}", // DC4
"\u{0015}", // NAK
"\u{0016}", // SYN
"\u{0017}", // ETB
"\u{0018}", // CAN
"\u{0019}", // EM
"\u{001A}", // SUB
"\u{001B}", // escape
"\u{001C}", // file separator
"\u{001D}", // group separator
"\u{001E}", // record separator
"\u{001F}", // unit separator
"\u{007F}", // DEL
"\u{00A0}", // non-breaking space
"\u{1680}", // ogham space mark
"\u{180E}", // mongolian vowel separator
"\u{2000}", // en quad
"\u{2001}", // em quad
"\u{2002}", // en space
"\u{2003}", // em space
"\u{2004}", // three-per-em space
"\u{2005}", // four-per-em space
"\u{2006}", // six-per-em space
"\u{2007}", // figure space
"\u{2008}", // punctuation space
"\u{2009}", // thin space
"\u{200A}", // hair space
"\u{200B}", // zero width space
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
];
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$secondSearch = $keepNewlines ? ["\r"] : ["\r", "\n", "\t", "\036", "\025"];
$string = str_replace($secondSearch, '', $string);
return trim($string);
}
/**
* Return integer value.
@ -45,18 +109,6 @@ trait ConvertsDataTypes
return (int)$this->get($field);
}
/**
* Return string value, but keep newlines.
*
* @param string $field
*
* @return string
*/
public function nlString(string $field): string
{
return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
}
/**
* Return string value.
*
@ -66,7 +118,19 @@ trait ConvertsDataTypes
*/
public function string(string $field): string
{
return app('steam')->cleanString((string)($this->get($field) ?? ''));
return $this->clearString((string)($this->get($field) ?? ''), false);
}
/**
* Return string value with newlines.
*
* @param string $field
*
* @return string
*/
public function stringWithNewlines(string $field): string
{
return $this->clearString((string)($this->get($field) ?? ''));
}
/**
@ -222,24 +286,6 @@ trait ConvertsDataTypes
return (int)$string;
}
/**
* Parse and clean a string, but keep the newlines.
*
* @param string|null $string
*
* @return string|null
*/
protected function nlStringFromValue(?string $string): ?string
{
if (null === $string) {
return null;
}
$result = app('steam')->nlCleanString($string);
return '' === $result ? null : $result;
}
/**
* Return integer value, or NULL when it's not set.
*
@ -261,56 +307,4 @@ trait ConvertsDataTypes
return (int)$value;
}
/**
* Return string value, but keep newlines, or NULL if empty.
*
* @param string $field
*
* @return string
*/
protected function nullableNlString(string $field): ?string
{
if (!$this->has($field)) {
return null;
}
return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
}
/**
* Return string value, or NULL if empty.
*
* @param string $field
*
* @return string|null
*/
protected function nullableString(string $field): ?string
{
if (!$this->has($field)) {
return null;
}
$res = trim(app('steam')->cleanString((string)($this->get($field) ?? '')));
if ('' === $res) {
return null;
}
return $res;
}
/**
* Parse and clean a string.
*
* @param string|null $string
*
* @return string|null
*/
protected function stringFromValue(?string $string): ?string
{
if (null === $string) {
return null;
}
$result = app('steam')->cleanString($string);
return '' === $result ? null : $result;
}
}

View File

@ -70,14 +70,14 @@ class OperatorQuerySearch implements SearchInterface
private CurrencyRepositoryInterface $currencyRepository;
private Carbon $date;
private int $limit;
private Collection $modifiers;
private Collection $modifiers;
private Collection $operators;
private string $originalQuery;
private int $page;
private ParsedQuery $query;
private float $startTime;
private TagRepositoryInterface $tagRepository;
private TransactionTypeRepositoryInterface $typeRepository; // obsolete
private TransactionTypeRepositoryInterface $typeRepository; // obsolete
private User $user;
private array $validOperators;
private array $words;
@ -179,7 +179,7 @@ private Collection $modifiers;
public function searchTransactions(): LengthAwarePaginator
{
if (0 === count($this->getWords()) && 0 === count($this->getOperators())) {
return new LengthAwarePaginator;
return new LengthAwarePaginator([],0,5,1);
}
return $this->collector->getPaginatedGroups();
@ -245,7 +245,9 @@ private Collection $modifiers;
Log::error(sprintf('Cannot handle node %s', $class));
throw new FireflyException(sprintf('Firefly III search cant handle "%s"-nodes', $class));
case Subquery::class:
/** @var Subquery $searchNode */
// loop all notes in subquery:
/** @var Node $subNode */
foreach ($searchNode->getNodes() as $subNode) {
$this->handleSearchNode($subNode); // lets hope its not too recursive!
}

View File

@ -179,8 +179,6 @@ class Steam
$formatted = $start->format('Y-m-d');
$startBalance = $this->balance($account, $start, $currency);
/** @var AccountRepositoryInterface $repository */
$balances[$formatted] = $startBalance;
if (null === $currency) {
$repository = app(AccountRepositoryInterface::class);
@ -333,136 +331,6 @@ class Steam
return $result;
}
/**
* Remove weird chars from strings.
*
* @param string $string
* TODO migrate to trait.
*
* @return string
* @deprecated
*/
public function cleanString(string $string): string
{
$search = [
"\u{0001}", // start of heading
"\u{0002}", // start of text
"\u{0003}", // end of text
"\u{0004}", // end of transmission
"\u{0005}", // enquiry
"\u{0006}", // ACK
"\u{0007}", // BEL
"\u{0008}", // backspace
"\u{000E}", // shift out
"\u{000F}", // shift in
"\u{0010}", // data link escape
"\u{0011}", // DC1
"\u{0012}", // DC2
"\u{0013}", // DC3
"\u{0014}", // DC4
"\u{0015}", // NAK
"\u{0016}", // SYN
"\u{0017}", // ETB
"\u{0018}", // CAN
"\u{0019}", // EM
"\u{001A}", // SUB
"\u{001B}", // escape
"\u{001C}", // file separator
"\u{001D}", // group separator
"\u{001E}", // record separator
"\u{001F}", // unit separator
"\u{007F}", // DEL
"\u{00A0}", // non-breaking space
"\u{1680}", // ogham space mark
"\u{180E}", // mongolian vowel separator
"\u{2000}", // en quad
"\u{2001}", // em quad
"\u{2002}", // en space
"\u{2003}", // em space
"\u{2004}", // three-per-em space
"\u{2005}", // four-per-em space
"\u{2006}", // six-per-em space
"\u{2007}", // figure space
"\u{2008}", // punctuation space
"\u{2009}", // thin space
"\u{200A}", // hair space
"\u{200B}", // zero width space
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
];
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$string = str_replace(["\n", "\t", "\r"], "\x20", $string);
return trim($string);
}
/**
* Remove weird chars from strings, but keep newlines and tabs.
*
* @param string $string
* TODO migrate to trait.
*
* @return string
* @deprecated
*/
public function nlCleanString(string $string): string
{
$search = [
"\u{0001}", // start of heading
"\u{0002}", // start of text
"\u{0003}", // end of text
"\u{0004}", // end of transmission
"\u{0005}", // enquiry
"\u{0006}", // ACK
"\u{0007}", // BEL
"\u{0008}", // backspace
"\u{000E}", // shift out
"\u{000F}", // shift in
"\u{0010}", // data link escape
"\u{0011}", // DC1
"\u{0012}", // DC2
"\u{0013}", // DC3
"\u{0014}", // DC4
"\u{0015}", // NAK
"\u{0016}", // SYN
"\u{0017}", // ETB
"\u{0018}", // CAN
"\u{0019}", // EM
"\u{001A}", // SUB
"\u{001B}", // escape
"\u{001C}", // file separator
"\u{001D}", // group separator
"\u{001E}", // record separator
"\u{001F}", // unit separator
"\u{007F}", // DEL
"\u{00A0}", // non-breaking space
"\u{1680}", // ogham space mark
"\u{180E}", // mongolian vowel separator
"\u{2000}", // en quad
"\u{2001}", // em quad
"\u{2002}", // en space
"\u{2003}", // em space
"\u{2004}", // three-per-em space
"\u{2005}", // four-per-em space
"\u{2006}", // six-per-em space
"\u{2007}", // figure space
"\u{2008}", // punctuation space
"\u{2009}", // thin space
"\u{200A}", // hair space
"\u{200B}", // zero width space
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
];
$replace = "\x20"; // plain old normal space
$string = str_replace($search, $replace, $string);
$string = str_replace("\r", '', $string);
return trim($string);
}
/**
* @param array $accounts
*
@ -584,7 +452,6 @@ class Steam
*/
public function getLocale(): string // get preference
{
/** @var string $language */
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
if ('equal' === $locale) {
$locale = $this->getLanguage();

View File

@ -93,8 +93,7 @@ class AmountFormat extends AbstractExtension
* Will format the amount by the currency related to the given account.
*
* @return TwigFunction
* @deprecated
* TODO remove me because it executes a query in a view.
* TODO remove me when layout v1 is deprecated.
*/
protected function formatAmountByAccount(): TwigFunction
{

View File

@ -355,8 +355,7 @@ class General extends AbstractExtension
/**
* @return TwigFunction
* @deprecated because it uses a query in a view
* TODO remove me.
* TODO remove me once layout v1 is deprecated.
*/
protected function getMetaField(): TwigFunction
{

View File

@ -22,20 +22,11 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
/**
* Interface ActionInterface.
*/
interface ActionInterface
{
/**
* ActionInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action);
/**
* Execute the action on an array. Returns "true" if the action was a success and the action
* was applied. Returns false if otherwise.

View File

@ -31,15 +31,6 @@ use Log;
*/
class ClearBudget implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@ -31,15 +31,6 @@ use Log;
*/
class ClearCategory implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@ -32,15 +32,6 @@ use Log;
*/
class ClearNotes implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@ -149,7 +149,6 @@ class ConvertToDeposit implements ActionInterface
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE);
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['source_account_name']));
unset($source);
// update source transaction(s) to be revenue account
DB::table('transactions')

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
@ -34,15 +33,6 @@ use Log;
*/
class DeleteTransaction implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use DB;
use FireflyIII\Models\RuleAction;
use Log;
/**
@ -31,15 +30,6 @@ use Log;
*/
class RemoveAllTags implements ActionInterface
{
/**
* TriggerInterface constructor.
*
* @param RuleAction $action
*/
public function __construct(RuleAction $action)
{
}
/**
* @inheritDoc
*/
@ -50,4 +40,5 @@ class RemoveAllTags implements ActionInterface
return true;
}
}

View File

@ -56,12 +56,9 @@ class SetDestinationAccount implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $object */
/** @var AccountRepositoryInterface repository */
/** @var Transaction $source */
$user = User::find($journal['user_id']);
$type = $journal['transaction_type_type'];
/** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class);
@ -86,6 +83,7 @@ class SetDestinationAccount implements ActionInterface
}
// new destination account must be different from the current source account:
/** @var Transaction|null $source */
$source = $object->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
Log::error('Could not find source transaction.');
@ -113,11 +111,6 @@ class SetDestinationAccount implements ActionInterface
if (TransactionType::WITHDRAWAL === $type) {
$newAccount = $this->findExpenseAccount();
}
if (null === $newAccount) {
Log::error('New expense account is NULL');
return false;
}
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
@ -150,9 +143,9 @@ class SetDestinationAccount implements ActionInterface
}
/**
* @return Account|null
* @return Account
*/
private function findExpenseAccount(): ?Account
private function findExpenseAccount(): Account
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
if (null === $account) {

View File

@ -55,12 +55,9 @@ class SetSourceAccount implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
/** @var TransactionJournal $object */
/** @var AccountRepositoryInterface repository */
/** @var Transaction $destination */
$user = User::find($journal['user_id']);
$type = $journal['transaction_type_type'];
/** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class);
@ -83,6 +80,7 @@ class SetSourceAccount implements ActionInterface
}
// new source account must be different from the current destination account:
/** @var Transaction|null $destination */
$destination = $object->transactions()->where('amount', '>', 0)->first();
if (null === $destination) {
Log::error('Could not find destination transaction.');
@ -110,11 +108,6 @@ class SetSourceAccount implements ActionInterface
if (TransactionType::DEPOSIT === $type) {
$newAccount = $this->findRevenueAccount();
}
if (null === $newAccount) {
Log::error('New account is NULL');
return false;
}
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
@ -145,9 +138,9 @@ class SetSourceAccount implements ActionInterface
}
/**
* @return Account|null
* @return Account
*/
private function findRevenueAccount(): ?Account
private function findRevenueAccount(): Account
{
$allowed = config('firefly.expected_source_types.source.Deposit');
$account = $this->repository->findByName($this->action->action_value, $allowed);

View File

@ -390,7 +390,7 @@ class SearchRuleEngine implements RuleEngineInterface
$result = $actionClass->actOnArray($transaction);
$journalId = $transaction['transaction_journal_id'] ?? 0;
if (true === $result) {
$this->resultCount[$journalId] = isset($this->resultCount[$journalId]) ? $this->resultCount[$journalId]++ : 1;
$this->resultCount[$journalId] = array_key_exists($journalId, $this->resultCount) ? $this->resultCount[$journalId]++ : 1;
Log::debug(
sprintf(
'Action "%s" on journal #%d was executed, so count a result. Updated transaction journal count is now %d.',
@ -514,7 +514,7 @@ class SearchRuleEngine implements RuleEngineInterface
{
$all = false;
Log::debug(sprintf('Going to fire group #%d with %d rule(s)', $group->id, $group->rules->count()));
/** @var $rule */
/** @var Rule $rule */
foreach ($group->rules as $rule) {
Log::debug(sprintf('Going to fire rule #%d from group #%d', $rule->id, $group->id));
$result = $this->fireRule($rule);

View File

@ -37,7 +37,7 @@ abstract class AbstractTransformer extends TransformerAbstract
/**
* @return ParameterBag
*/
public function getParameters(): ParameterBag
final public function getParameters(): ParameterBag
{
return $this->parameters;
}
@ -45,7 +45,7 @@ abstract class AbstractTransformer extends TransformerAbstract
/**
* @param ParameterBag $parameters
*/
public function setParameters(ParameterBag $parameters): void
final public function setParameters(ParameterBag $parameters): void
{
$this->parameters = $parameters;
}

View File

@ -206,8 +206,6 @@ class AccountTransformer extends AbstractTransformer
* @param Account $account
* @param string $accountType
*
* @param int $decimalPlaces
*
* @return array
*
* TODO refactor call to getOpeningBalanceAmount / Date because its extra queries.

View File

@ -22,11 +22,11 @@
declare(strict_types=1);
namespace FireflyIII\Transformers;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use Illuminate\Support\Collection;
/**
* Class AvailableBudgetTransformer
@ -97,11 +97,9 @@ class AvailableBudgetTransformer extends AbstractTransformer
private function getSpentInBudgets(): array
{
$allActive = $this->repository->getActiveBudgets();
$sums = $this->opsRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'), null, $allActive);
return $this->opsRepository->spentInPeriodMc(
$allActive, new Collection, $this->parameters->get('start'), $this->parameters->get('end')
);
return array_values($sums);
}
/**
@ -109,7 +107,8 @@ class AvailableBudgetTransformer extends AbstractTransformer
*/
private function spentOutsideBudgets(): array
{
return $this->noBudgetRepository->spentInPeriodWoBudgetMc(new Collection, $this->parameters->get('start'), $this->parameters->get('end'));
}
$sums = $this->noBudgetRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'));
return array_values($sums);
}
}

View File

@ -212,7 +212,7 @@ class BillTransformer extends AbstractTransformer
return $default; // @codeCoverageIgnore
}
$latest = $dates->first()->date;
/** @var TransactionJournal $date */
/** @var TransactionJournal $journal */
foreach ($dates as $journal) {
if ($journal->date->gte($latest)) {
$latest = $journal->date;

View File

@ -1,67 +0,0 @@
<?php
/**
* CurrencyExchangeRateTransformer.php
* Copyright (c) 2019 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\Transformers;
use FireflyIII\Models\CurrencyExchangeRate;
/**
* Class CurrencyExchangeRateTransformer
*/
class CurrencyExchangeRateTransformer extends AbstractTransformer
{
/**
* @param CurrencyExchangeRate $rate
*
* @return array
*/
public function transform(CurrencyExchangeRate $rate): array
{
$result = number_format((float)$rate->rate * (float)$this->parameters->get('amount'), $rate->toCurrency->decimal_places, '.', '');
$result = 0.0 === $result ? null : $result;
return [
'id' => (int)$rate->id,
'created_at' => $rate->created_at->toAtomString(),
'updated_at' => $rate->updated_at->toAtomString(),
'from_currency_id' => (int)$rate->fromCurrency->id,
'from_currency_name' => $rate->fromCurrency->name,
'from_currency_code' => $rate->fromCurrency->code,
'from_currency_symbol' => $rate->fromCurrency->symbol,
'from_currency_decimal_places' => (int)$rate->fromCurrency->decimal_places,
'to_currency_id' => (int)$rate->toCurrency->id,
'to_currency_name' => $rate->toCurrency->name,
'to_currency_code' => $rate->toCurrency->code,
'to_currency_symbol' => $rate->toCurrency->symbol,
'to_currency_decimal_places' => (int)$rate->toCurrency->decimal_places,
'date' => $rate->date->format('Y-m-d'),
'rate' => (float)$rate->rate,
'amount' => $result,
'links' => [
[
'rel' => 'self',
'uri' => '/currency_exchange_rates/' . $rate->id,
],
],
];
}
}

View File

@ -276,7 +276,6 @@ class RecurrenceTransformer extends AbstractTransformer
$array['category_name'] = $category->name;
}
break;
break;
case 'category_name':
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
if (null !== $category) {

View File

@ -304,7 +304,7 @@ class TransactionGroupTransformer extends AbstractTransformer
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id));
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id), 0, $e);
}
// do something else.

View File

@ -67,17 +67,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*
* @property int $id
* @property string $email
* @property bool $isAdmin used in admin user
* controller.
* @property bool $has2FA used in admin user
* controller.
* @property array $prefs used in admin user
* controller.
* @property string password
* @property bool $isAdmin
* @property bool $has2FA
* @property array $prefs
* @property string $password
* @property string $mfa_secret
* @property Collection roles
* @property string blocked_code
* @property bool blocked
* @property Collection $roles
* @property string $blocked_code
* @property bool $blocked
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $remember_token

View File

@ -34,7 +34,7 @@ trait DepositValidation
{
/**
* @param int|null $accountId
* @param $accountName
* @param mixed $accountName
*
* @return bool
*/