mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Reformat code.
This commit is contained in:
parent
c9ce5df74b
commit
1961487055
@ -22,6 +22,9 @@
|
||||
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
echo "Running PHP CS Fixer"
|
||||
$SCRIPT_DIR/phpcs.sh
|
||||
echo "Running PHPStan"
|
||||
$SCRIPT_DIR/phpstan.sh
|
||||
echo "Running PHPMD"
|
||||
$SCRIPT_DIR/phpmd.sh
|
||||
|
@ -36,16 +36,12 @@ class ExpressionController extends Controller
|
||||
* This endpoint is documented at:
|
||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/rules/validateExpression
|
||||
*
|
||||
* @param ValidateExpressionRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateExpression(ValidateExpressionRequest $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
"valid" => true,
|
||||
'valid' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +45,7 @@ class ValidateExpressionRequest extends FormRequest
|
||||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
protected function failedValidation(Validator $validator): void
|
||||
{
|
||||
@ -58,7 +55,7 @@ class ValidateExpressionRequest extends FormRequest
|
||||
$validator,
|
||||
response()->json([
|
||||
'valid' => false,
|
||||
'error' => $error
|
||||
'error' => $error,
|
||||
], 200)
|
||||
);
|
||||
}
|
||||
|
@ -42,6 +42,13 @@ class IndexRequest extends FormRequest
|
||||
use ConvertsDataTypes;
|
||||
use GetSortInstructions;
|
||||
|
||||
public function getAccountTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
|
||||
return $this->mapAccountTypes($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data from the request.
|
||||
*/
|
||||
@ -50,13 +57,6 @@ class IndexRequest extends FormRequest
|
||||
return $this->getCarbonDate('date');
|
||||
}
|
||||
|
||||
public function getAccountTypes(): array
|
||||
{
|
||||
$type = (string)$this->get('type', 'default');
|
||||
|
||||
return $this->mapAccountTypes($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules that the incoming request must be matched against.
|
||||
*/
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Auth;
|
||||
|
||||
use Cookie;
|
||||
use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
|
@ -76,6 +76,13 @@ class RuleAction extends Model
|
||||
|
||||
protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing'];
|
||||
|
||||
public function getValue(array $journal): string
|
||||
{
|
||||
$expr = new ActionExpression($this->action_value);
|
||||
|
||||
return $expr->evaluate($journal);
|
||||
}
|
||||
|
||||
public function rule(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Rule::class);
|
||||
@ -94,10 +101,4 @@ class RuleAction extends Model
|
||||
get: static fn ($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
|
||||
public function getValue(array $journal): string
|
||||
{
|
||||
$expr = new ActionExpression($this->action_value);
|
||||
return $expr->evaluate($journal);
|
||||
}
|
||||
}
|
||||
|
@ -208,6 +208,7 @@ class FireflyServiceProvider extends ServiceProvider
|
||||
static function () {
|
||||
$expressionLanguage = new ExpressionLanguage();
|
||||
$expressionLanguage->registerProvider(new ActionExpressionLanguageProvider());
|
||||
|
||||
return $expressionLanguage;
|
||||
}
|
||||
);
|
||||
|
@ -25,27 +25,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use FireflyIII\TransactionRules\Expressions\ActionExpression;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
|
||||
class IsValidActionExpression implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Check that the given action expression is syntactically valid.
|
||||
*
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @param \Closure(string): PotentiallyTranslatedString $fail
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
public function validate(string $attribute, mixed $value, \Closure $fail): void
|
||||
{
|
||||
$value ??= '';
|
||||
$expr = new ActionExpression($value);
|
||||
|
||||
if (!$expr->isValid()) {
|
||||
$fail('validation.rule_action_expression')->translate([
|
||||
'error' => $expr->getValidationError()->getMessage()
|
||||
'error' => $expr->getValidationError()->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -29,57 +29,57 @@ use Symfony\Component\ExpressionLanguage\SyntaxError;
|
||||
|
||||
class ActionExpression
|
||||
{
|
||||
private static array $NAMES = array(
|
||||
"transaction_group_id",
|
||||
"user_id",
|
||||
"user_group_id",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"transaction_group_title",
|
||||
"group_created_at",
|
||||
"group_updated_at",
|
||||
"transaction_journal_id",
|
||||
"transaction_type_id",
|
||||
"description",
|
||||
"date",
|
||||
"order",
|
||||
"transaction_type_type",
|
||||
"source_transaction_id",
|
||||
"source_account_id",
|
||||
"reconciled",
|
||||
"amount",
|
||||
"currency_id",
|
||||
"currency_code",
|
||||
"currency_name",
|
||||
"currency_symbol",
|
||||
"currency_decimal_places",
|
||||
"foreign_amount",
|
||||
"foreign_currency_id",
|
||||
"foreign_currency_code",
|
||||
"foreign_currency_name",
|
||||
"foreign_currency_symbol",
|
||||
"foreign_currency_decimal_places",
|
||||
"destination_account_id",
|
||||
"source_account_name",
|
||||
"source_account_iban",
|
||||
"source_account_type",
|
||||
"destination_account_name",
|
||||
"destination_account_iban",
|
||||
"destination_account_type",
|
||||
"category_id",
|
||||
"category_name",
|
||||
"budget_id",
|
||||
"budget_name",
|
||||
"tags",
|
||||
"attachments",
|
||||
"interest_date",
|
||||
"payment_date",
|
||||
"invoice_date",
|
||||
"book_date",
|
||||
"due_date",
|
||||
"process_date",
|
||||
"destination_transaction_id"
|
||||
);
|
||||
private static array $NAMES = [
|
||||
'transaction_group_id',
|
||||
'user_id',
|
||||
'user_group_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'transaction_group_title',
|
||||
'group_created_at',
|
||||
'group_updated_at',
|
||||
'transaction_journal_id',
|
||||
'transaction_type_id',
|
||||
'description',
|
||||
'date',
|
||||
'order',
|
||||
'transaction_type_type',
|
||||
'source_transaction_id',
|
||||
'source_account_id',
|
||||
'reconciled',
|
||||
'amount',
|
||||
'currency_id',
|
||||
'currency_code',
|
||||
'currency_name',
|
||||
'currency_symbol',
|
||||
'currency_decimal_places',
|
||||
'foreign_amount',
|
||||
'foreign_currency_id',
|
||||
'foreign_currency_code',
|
||||
'foreign_currency_name',
|
||||
'foreign_currency_symbol',
|
||||
'foreign_currency_decimal_places',
|
||||
'destination_account_id',
|
||||
'source_account_name',
|
||||
'source_account_iban',
|
||||
'source_account_type',
|
||||
'destination_account_name',
|
||||
'destination_account_iban',
|
||||
'destination_account_type',
|
||||
'category_id',
|
||||
'category_name',
|
||||
'budget_id',
|
||||
'budget_name',
|
||||
'tags',
|
||||
'attachments',
|
||||
'interest_date',
|
||||
'payment_date',
|
||||
'invoice_date',
|
||||
'book_date',
|
||||
'due_date',
|
||||
'process_date',
|
||||
'destination_transaction_id',
|
||||
];
|
||||
|
||||
private ExpressionLanguage $expressionLanguage;
|
||||
private string $expr;
|
||||
@ -97,7 +97,7 @@ class ActionExpression
|
||||
|
||||
private static function isExpression(string $expr): bool
|
||||
{
|
||||
return str_starts_with($expr, "=");
|
||||
return str_starts_with($expr, '=');
|
||||
}
|
||||
|
||||
private function validate(): ?SyntaxError
|
||||
@ -108,6 +108,7 @@ class ActionExpression
|
||||
|
||||
try {
|
||||
$this->lint();
|
||||
|
||||
return null;
|
||||
} catch (SyntaxError $e) {
|
||||
return $e;
|
||||
@ -130,7 +131,7 @@ class ActionExpression
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->validationError === null;
|
||||
return null === $this->validationError;
|
||||
}
|
||||
|
||||
public function getValidationError(): ?SyntaxError
|
||||
@ -141,7 +142,8 @@ class ActionExpression
|
||||
private function evaluateExpression(string $expr, array $journal): string
|
||||
{
|
||||
$result = $this->expressionLanguage->evaluate($expr, $journal);
|
||||
return strval($result);
|
||||
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
public function evaluate(array $journal): string
|
||||
|
@ -32,8 +32,8 @@ class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInte
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
ExpressionFunction::fromPhp("substr"),
|
||||
ExpressionFunction::fromPhp("strlen")
|
||||
ExpressionFunction::fromPhp('substr'),
|
||||
ExpressionFunction::fromPhp('strlen'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Services\Password\Verifier;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\TransactionRules\Expressions\ActionExpression;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Validation\Validator;
|
||||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use FireflyIII\User;
|
||||
|
||||
if ('ldap' === strtolower((string)env('AUTHENTICATION_GUARD'))) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Diglactic\Breadcrumbs\Generator;
|
||||
use Diglactic\Breadcrumbs\Manager;
|
||||
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
$databaseUrl = getenv('DATABASE_URL');
|
||||
$host = '';
|
||||
$username = '';
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use FireflyIII\User;
|
||||
|
||||
return [
|
||||
|
Loading…
Reference in New Issue
Block a user