Skip to content

Commit

Permalink
Reformat code.
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Mar 10, 2024
1 parent c9ce5df commit 1961487
Show file tree
Hide file tree
Showing 21 changed files with 572 additions and 571 deletions.
3 changes: 3 additions & 0 deletions .ci/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions app/Api/V1/Controllers/Models/Rule/ExpressionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
7 changes: 2 additions & 5 deletions app/Api/V1/Requests/Models/Rule/ValidateExpressionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public function rules(): array
/**
* 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
{
Expand All @@ -58,7 +55,7 @@ protected function failedValidation(Validator $validator): void
$validator,
response()->json([
'valid' => false,
'error' => $error
'error' => $error,
], 200)
);
}
Expand Down
14 changes: 7 additions & 7 deletions app/Api/V2/Request/Model/Account/IndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -50,13 +57,6 @@ public function getDate(): Carbon
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.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/Collector/Extensions/CollectorProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait CollectorProperties
public const string TEST = 'Test';

/** @var array<int, string> */
public array $sorting;
public array $sorting;
private ?int $endRow;
private bool $expandGroupSearch;
private array $fields;
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace FireflyIII\Http\Controllers\Auth;

use Cookie;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
Expand Down
14 changes: 7 additions & 7 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ class Account extends Model

protected $casts
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'user_id' => 'integer',
'deleted_at' => 'datetime',
'active' => 'boolean',
'encrypted' => 'boolean',
];
'created_at' => 'datetime',
'updated_at' => 'datetime',
'user_id' => 'integer',
'deleted_at' => 'datetime',
'active' => 'boolean',
'encrypted' => 'boolean',
];

protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];

Expand Down
13 changes: 7 additions & 6 deletions app/Models/RuleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -94,10 +101,4 @@ protected function ruleId(): Attribute
get: static fn ($value) => (int)$value,
);
}

public function getValue(array $journal): string
{
$expr = new ActionExpression($this->action_value);
return $expr->evaluate($journal);
}
}
1 change: 1 addition & 0 deletions app/Providers/FireflyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static function (Application $app) {
static function () {
$expressionLanguage = new ExpressionLanguage();
$expressionLanguage->registerProvider(new ActionExpressionLanguageProvider());

return $expressionLanguage;
}
);
Expand Down
10 changes: 5 additions & 5 deletions app/Rules/IsValidActionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@

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(),
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Support/Search/OperatorQuerySearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class OperatorQuerySearch implements SearchInterface
private GroupCollectorInterface $collector;
private CurrencyRepositoryInterface $currencyRepository;
private array $excludeTags;
private array $includeAnyTags;
private array $includeAnyTags;
// added to fix #8632
private array $includeTags;
private array $includeTags;
private array $invalidOperators;
private int $limit;
private Collection $operators;
Expand Down
116 changes: 59 additions & 57 deletions app/TransactionRules/Expressions/ActionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,57 @@

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;
Expand All @@ -89,15 +89,15 @@ class ActionExpression
public function __construct(string $expr)
{
$this->expressionLanguage = app(ExpressionLanguage::class);
$this->expr = $expr;
$this->expr = $expr;

$this->isExpression = self::isExpression($expr);
$this->validationError = $this->validate();
$this->isExpression = self::isExpression($expr);
$this->validationError = $this->validate();
}

private static function isExpression(string $expr): bool
{
return str_starts_with($expr, "=");
return str_starts_with($expr, '=');
}

private function validate(): ?SyntaxError
Expand All @@ -108,6 +108,7 @@ private function validate(): ?SyntaxError

try {
$this->lint();

return null;
} catch (SyntaxError $e) {
return $e;
Expand All @@ -130,7 +131,7 @@ private function lint(): void

public function isValid(): bool
{
return $this->validationError === null;
return null === $this->validationError;
}

public function getValidationError(): ?SyntaxError
Expand All @@ -141,7 +142,8 @@ public function getValidationError(): ?SyntaxError
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}
}
1 change: 0 additions & 1 deletion app/Validation/FireflyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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;
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

if (!function_exists('envNonEmpty')) {
/**
* @param string $key
* @param string|int|bool|null $default
* @param string $key
* @param string|int|bool|null $default
*
* @return mixed|null
*/
function envNonEmpty(string $key, string|int|bool|null $default = null)
function envNonEmpty(string $key, string | int | bool | null $default = null)
{
$result = env($key, $default);
if ('' === $result) {
Expand Down
1 change: 1 addition & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

declare(strict_types=1);

use FireflyIII\User;

if ('ldap' === strtolower((string)env('AUTHENTICATION_GUARD'))) {
Expand Down
1 change: 1 addition & 0 deletions config/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

declare(strict_types=1);

use Diglactic\Breadcrumbs\Generator;
use Diglactic\Breadcrumbs\Manager;

Expand Down
Loading

0 comments on commit 1961487

Please sign in to comment.