diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.php index 8007f071f9..152f9da4d3 100644 --- a/app/Http/Requests/RuleFormRequest.php +++ b/app/Http/Requests/RuleFormRequest.php @@ -1,4 +1,5 @@ $trigger['type'] ?? 'invalid', 'value' => $trigger['value'] ?? '', - 'stop_processing' => 1 === (int) $stopProcessing, - 'prohibited' => 1 === (int) $prohibited, + 'stop_processing' => 1 === (int)$stopProcessing, + 'prohibited' => 1 === (int)$prohibited, ]; - $return[] = $set; + $set = self::replaceAmountTrigger($set); + $return[] = $set; } } return $return; } + /** + * @param array $array + * @return array + */ + public static function replaceAmountTrigger(array $array): array + { + // do some sneaky search and replace. + $amountFields = [ + 'amount_is', + 'amount', + 'amount_exactly', + 'amount_less', + 'amount_max', + 'amount_more', + 'amount_min', + 'foreign_amount_is', + 'foreign_amount', + 'foreign_amount_less', + 'foreign_amount_max', + 'foreign_amount_more', + 'foreign_amount_min', + ]; + if (in_array($array['type'], $amountFields, true) && '0' === $array['value']) { + $array['value'] = '0.00'; + } + return $array; + } + /** * @return array */ @@ -95,7 +125,7 @@ class RuleFormRequest extends FormRequest $return[] = [ 'type' => $action['type'] ?? 'invalid', 'value' => $action['value'] ?? '', - 'stop_processing' => 1 === (int) $stopProcessing, + 'stop_processing' => 1 === (int)$stopProcessing, ]; } } @@ -126,9 +156,9 @@ class RuleFormRequest extends FormRequest 'stop_processing' => 'boolean', 'rule_group_id' => 'required|belongsToUser:rule_groups', 'trigger' => 'required|in:store-journal,update-journal', - 'triggers.*.type' => 'required|in:' . implode(',', $validTriggers), + 'triggers.*.type' => 'required|in:'.implode(',', $validTriggers), 'triggers.*.value' => sprintf('required_if:triggers.*.type,%s|min:1|ruleTriggerValue', $contextTriggers), - 'actions.*.type' => 'required|in:' . implode(',', $validActions), + 'actions.*.type' => 'required|in:'.implode(',', $validActions), 'actions.*.value' => sprintf('required_if:actions.*.type,%s|min:0|max:255|ruleActionValue', $contextActions), 'strict' => 'in:0,1', ]; @@ -137,7 +167,7 @@ class RuleFormRequest extends FormRequest $rule = $this->route()->parameter('rule'); if (null !== $rule) { - $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,' . $rule->id; + $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,'.$rule->id; } return $rules; diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index d4ecb83252..f0d9ca2d73 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -27,6 +27,7 @@ use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\ValidationException; use FireflyIII\Helpers\Help\HelpInterface; +use FireflyIII\Http\Requests\RuleFormRequest; use FireflyIII\Http\Requests\TestRuleFormRequest; use FireflyIII\Support\Binder\AccountList; use FireflyIII\User; @@ -60,7 +61,7 @@ trait RequestInformation /** * Get a list of triggers. * - * @param TestRuleFormRequest $request + * @param TestRuleFormRequest $request * * @return array */ @@ -70,14 +71,15 @@ trait RequestInformation $data = $request->get('triggers'); if (is_array($data)) { foreach ($data as $triggerInfo) { - $triggers[] = [ + $current = [ 'type' => $triggerInfo['type'] ?? '', 'value' => $triggerInfo['value'] ?? '', - 'stop_processing' => 1 === (int) ($triggerInfo['stop_processing'] ?? '0'), + 'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'), ]; + $current = RuleFormRequest::replaceAmountTrigger($current); + $triggers[] = $current; } } - return $triggers; } @@ -127,13 +129,13 @@ trait RequestInformation */ final protected function getSpecificPageName(): string // get request info { - return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType'); + return null === RouteFacade::current()->parameter('objectType') ? '' : '_'.RouteFacade::current()->parameter('objectType'); } /** * Check if date is outside session range. * - * @param Carbon $date + * @param Carbon $date * * @return bool * @@ -159,7 +161,7 @@ trait RequestInformation /** * Parses attributes from URL * - * @param array $attributes + * @param array $attributes * * @return array */ @@ -189,9 +191,9 @@ trait RequestInformation /** * Validate users new password. * - * @param User $user - * @param string $current - * @param string $new + * @param User $user + * @param string $current + * @param string $new * * @return bool * @@ -200,11 +202,11 @@ trait RequestInformation final protected function validatePassword(User $user, string $current, string $new): bool //get request info { if (!Hash::check($current, $user->password)) { - throw new ValidationException((string) trans('firefly.invalid_current_password')); + throw new ValidationException((string)trans('firefly.invalid_current_password')); } if ($current === $new) { - throw new ValidationException((string) trans('firefly.should_change')); + throw new ValidationException((string)trans('firefly.should_change')); } return true; @@ -213,7 +215,7 @@ trait RequestInformation /** * Get a validator for an incoming registration request. * - * @param array $data + * @param array $data * * @return ValidatorContract * @codeCoverageIgnore diff --git a/composer.lock b/composer.lock index 739fb537a9..ef58873e52 100644 --- a/composer.lock +++ b/composer.lock @@ -5092,42 +5092,53 @@ }, { "name": "ramsey/collection", - "version": "1.2.2", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/ramsey/collection.git", - "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a" + "reference": "ad7475d1c9e70b190ecffc58f2d989416af339b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/collection/zipball/cccc74ee5e328031b15640b51056ee8d3bb66c0a", - "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a", + "url": "https://api.github.com/repos/ramsey/collection/zipball/ad7475d1c9e70b190ecffc58f2d989416af339b4", + "reference": "ad7475d1c9e70b190ecffc58f2d989416af339b4", "shasum": "" }, "require": { - "php": "^7.3 || ^8", + "php": "^7.4 || ^8.0", "symfony/polyfill-php81": "^1.23" }, "require-dev": { - "captainhook/captainhook": "^5.3", - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "ergebnis/composer-normalize": "^2.6", - "fakerphp/faker": "^1.5", - "hamcrest/hamcrest-php": "^2", - "jangregor/phpstan-prophecy": "^0.8", - "mockery/mockery": "^1.3", + "captainhook/plugin-composer": "^5.3", + "ergebnis/composer-normalize": "^2.28.3", + "fakerphp/faker": "^1.21", + "hamcrest/hamcrest-php": "^2.0", + "jangregor/phpstan-prophecy": "^1.0", + "mockery/mockery": "^1.5", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpcsstandards/phpcsutils": "^1.0.0-rc1", "phpspec/prophecy-phpunit": "^2.0", - "phpstan/extension-installer": "^1", - "phpstan/phpstan": "^0.12.32", - "phpstan/phpstan-mockery": "^0.12.5", - "phpstan/phpstan-phpunit": "^0.12.11", - "phpunit/phpunit": "^8.5 || ^9", - "psy/psysh": "^0.10.4", - "slevomat/coding-standard": "^6.3", - "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "^4.4" + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5", + "psalm/plugin-mockery": "^1.1", + "psalm/plugin-phpunit": "^0.18.4", + "ramsey/coding-standard": "^2.0.3", + "ramsey/conventional-commits": "^1.3", + "vimeo/psalm": "^5.4" }, "type": "library", + "extra": { + "captainhook": { + "force-install": true + }, + "ramsey/conventional-commits": { + "configFile": "conventional-commits.json" + } + }, "autoload": { "psr-4": { "Ramsey\\Collection\\": "src/" @@ -5155,7 +5166,7 @@ ], "support": { "issues": "https://github.com/ramsey/collection/issues", - "source": "https://github.com/ramsey/collection/tree/1.2.2" + "source": "https://github.com/ramsey/collection/tree/1.3.0" }, "funding": [ { @@ -5167,7 +5178,7 @@ "type": "tidelift" } ], - "time": "2021-10-10T03:01:02+00:00" + "time": "2022-12-27T19:12:24+00:00" }, { "name": "ramsey/uuid", @@ -5465,16 +5476,16 @@ }, { "name": "spatie/flare-client-php", - "version": "1.3.1", + "version": "1.3.2", "source": { "type": "git", "url": "https://github.com/spatie/flare-client-php.git", - "reference": "ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8" + "reference": "609903bd154ba3d71f5e23a91c3b431fa8f71868" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8", - "reference": "ebb9ae0509b75e02f128b39537eb9a3ef5ce18e8", + "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/609903bd154ba3d71f5e23a91c3b431fa8f71868", + "reference": "609903bd154ba3d71f5e23a91c3b431fa8f71868", "shasum": "" }, "require": { @@ -5522,7 +5533,7 @@ ], "support": { "issues": "https://github.com/spatie/flare-client-php/issues", - "source": "https://github.com/spatie/flare-client-php/tree/1.3.1" + "source": "https://github.com/spatie/flare-client-php/tree/1.3.2" }, "funding": [ { @@ -5530,7 +5541,7 @@ "type": "github" } ], - "time": "2022-11-16T08:30:20+00:00" + "time": "2022-12-26T14:36:46+00:00" }, { "name": "spatie/ignition", @@ -5609,16 +5620,16 @@ }, { "name": "spatie/laravel-ignition", - "version": "1.6.2", + "version": "1.6.3", "source": { "type": "git", "url": "https://github.com/spatie/laravel-ignition.git", - "reference": "d6e1e1ad93abe280abf41c33f8ea7647dfc0c233" + "reference": "2db918babd96f87b73fc26e4195f5a19328dd123" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/d6e1e1ad93abe280abf41c33f8ea7647dfc0c233", - "reference": "d6e1e1ad93abe280abf41c33f8ea7647dfc0c233", + "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/2db918babd96f87b73fc26e4195f5a19328dd123", + "reference": "2db918babd96f87b73fc26e4195f5a19328dd123", "shasum": "" }, "require": { @@ -5695,7 +5706,7 @@ "type": "github" } ], - "time": "2022-12-08T15:31:38+00:00" + "time": "2022-12-26T15:13:03+00:00" }, { "name": "stella-maris/clock", @@ -8392,16 +8403,16 @@ }, { "name": "twig/twig", - "version": "v3.4.3", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58" + "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58", - "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3ffcf4b7d890770466da3b2666f82ac054e7ec72", + "reference": "3ffcf4b7d890770466da3b2666f82ac054e7ec72", "shasum": "" }, "require": { @@ -8416,7 +8427,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "3.5-dev" } }, "autoload": { @@ -8452,7 +8463,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.4.3" + "source": "https://github.com/twigphp/Twig/tree/v3.5.0" }, "funding": [ { @@ -8464,7 +8475,7 @@ "type": "tidelift" } ], - "time": "2022-09-28T08:42:51+00:00" + "time": "2022-12-27T12:28:18+00:00" }, { "name": "vlucas/phpdotenv",