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