mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 23:50:09 +00:00
Various code optimalisations.
This commit is contained in:
@@ -239,15 +239,15 @@ class JournalFormRequest extends Request
|
||||
$data = $validator->getData();
|
||||
$type = $data['what'] ?? 'invalid';
|
||||
Log::debug(sprintf('Type is %s', $type));
|
||||
if ($type === 'withdrawal') {
|
||||
if ('withdrawal' === $type) {
|
||||
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency));
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
&& 0 !== $selectedCurrency
|
||||
&& 0 !== $accountCurrency
|
||||
) {
|
||||
Log::debug('ADD validation error on native_amount');
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
@@ -257,13 +257,13 @@ class JournalFormRequest extends Request
|
||||
}
|
||||
|
||||
// same thing for deposits:
|
||||
if ($type === 'deposit') {
|
||||
if ('deposit' === $type) {
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
&& 0 !== $selectedCurrency
|
||||
&& 0 !== $accountCurrency
|
||||
) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
|
||||
@@ -272,7 +272,7 @@ class JournalFormRequest extends Request
|
||||
}
|
||||
|
||||
// and for transfers
|
||||
if ($type === 'transfer') {
|
||||
if ('transfer' === $type) {
|
||||
|
||||
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
@@ -282,15 +282,15 @@ class JournalFormRequest extends Request
|
||||
Log::debug(sprintf('Source currency is %d, destination currency is %d', $sourceCurrency, $destinationCurrency));
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
&& 0 !== $sourceCurrency
|
||||
&& 0 !== $destinationCurrency
|
||||
) {
|
||||
$validator->errors()->add('source_amount', trans('validation.numeric_source'));
|
||||
}
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
&& 0 !== $sourceCurrency
|
||||
&& 0 !== $destinationCurrency
|
||||
) {
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric_destination'));
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric', ['attribute' => 'destination_amount']));
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
@@ -174,16 +174,16 @@ class RecurrenceFormRequest extends Request
|
||||
}
|
||||
|
||||
// if ends after X repetitions, set another rule
|
||||
if ($this->string('repetition_end') === 'times') {
|
||||
if ('times' === $this->string('repetition_end')) {
|
||||
$rules['repetitions'] = 'required|numeric|between:0,254';
|
||||
}
|
||||
// if foreign amount, currency must be different.
|
||||
if ($this->float('foreign_amount') !== 0.0) {
|
||||
if (0.0 !== $this->float('foreign_amount')) {
|
||||
$rules['foreign_currency_id'] = 'exists:transaction_currencies,id|different:transaction_currency_id';
|
||||
}
|
||||
|
||||
// if ends at date X, set another rule.
|
||||
if ($this->string('repetition_end') === 'until_date') {
|
||||
if ('until_date' === $this->string('repetition_end')) {
|
||||
$rules['repeat_until'] = 'required|date|after:' . $tomorrow->format('Y-m-d');
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ class RecurrenceFormRequest extends Request
|
||||
'moment' => '',
|
||||
];
|
||||
|
||||
if ($value === 'daily') {
|
||||
if ('daily' === $value) {
|
||||
$return['type'] = $value;
|
||||
}
|
||||
//monthly,17
|
||||
|
||||
@@ -125,8 +125,9 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon($parts[1]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date range.', $range));
|
||||
throw new FireflyException(sprintf('"%s" is not a valid date range.', $range));
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
@@ -172,8 +173,9 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon($parts[0]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date range.', $range));
|
||||
throw new FireflyException(sprintf('"%s" is not a valid date range.', $range));
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ class Request extends FormRequest
|
||||
*/
|
||||
public function boolean(string $field): bool
|
||||
{
|
||||
if ((string)$this->input($field) === 'true') {
|
||||
if ('true' === (string)$this->input($field)) {
|
||||
return true;
|
||||
}
|
||||
if ((string)$this->input($field) === 'false') {
|
||||
if ('false' === (string)$this->input($field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class RuleFormRequest extends Request
|
||||
$data['rule-triggers'][] = [
|
||||
'name' => $value,
|
||||
'value' => $triggerValues[$index] ?? '',
|
||||
'stop-processing' => (int)($triggerStop[$index] ?? 0) === 1,
|
||||
'stop-processing' => 1 === (int)($triggerStop[$index] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class RuleFormRequest extends Request
|
||||
$data['rule-actions'][] = [
|
||||
'name' => $value,
|
||||
'value' => $actionValues[$index] ?? '',
|
||||
'stop-processing' => (int)($actionStop[$index] ?? 0) === 1,
|
||||
'stop-processing' => 1 === (int)($actionStop[$index] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ class SplitJournalFormRequest extends Request
|
||||
$transactions = $data['transactions'] ?? [];
|
||||
/** @var array $array */
|
||||
foreach ($transactions as $array) {
|
||||
if ($array['destination_id'] !== null && $array['source_id'] !== null && $array['destination_id'] === $array['source_id']) {
|
||||
if (null !== $array['destination_id'] && null !== $array['source_id'] && $array['destination_id'] === $array['source_id']) {
|
||||
$validator->errors()->add('journal_source_id', trans('validation.source_equals_destination'));
|
||||
$validator->errors()->add('journal_destination_id', trans('validation.source_equals_destination'));
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ class TagFormRequest extends Request
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var TagRepositoryInterface $repository */
|
||||
$repository = app(TagRepositoryInterface::class);
|
||||
$idRule = '';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag';
|
||||
if (null !== $repository->find((int)$this->get('id'))->id) {
|
||||
if (null !== $repository->findNull((int)$this->get('id'))) {
|
||||
$idRule = 'belongsToUser:tags';
|
||||
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,' . $this->get('id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user