Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand action and clean up code.
James Cole5a3596043449
diff --git a/.ci/php-cs-fixer/.php-cs-fixer.php b/.ci/php-cs-fixer/.php-cs-fixer.phpindex 1e5a1c2dff..a6af9177fd 100644--- a/.ci/php-cs-fixer/.php-cs-fixer.php+++ b/.ci/php-cs-fixer/.php-cs-fixer.php@@ -27,7 +27,7 @@ $paths = [$current . '/../../database',$current . '/../../routes',$current . '/../../tests',- $current . '/../../resources/lang',+ $current . '/../../resources/lang/en_US',];$finder = PhpCsFixer\Finder::create()@@ -36,9 +36,11 @@ $finder = PhpCsFixer\Finder::create()$config = new PhpCsFixer\Config();return $config->setRules([- '@PSR12' => true,- 'declare_strict_types' => true,- 'strict_param' => true,- 'array_syntax' => ['syntax' => 'short'],+ '@PhpCsFixer:risky' => true,+ // '@PSR12:risky' => true,+ 'declare_strict_types' => true,+ 'strict_param' => true,+ 'array_syntax' => ['syntax' => 'short'],+ 'native_function_invocation' => false,])->setFinder($finder);diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lockindex e68e86b2d3..0e28dfb1d6 100644--- a/.ci/php-cs-fixer/composer.lock+++ b/.ci/php-cs-fixer/composer.lock@@ -226,16 +226,16 @@},{"name": "friendsofphp/php-cs-fixer",- "version": "v3.37.0",+ "version": "v3.37.1","source": {"type": "git","url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",- "reference": "d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b"+ "reference": "c3fe76976081ab871aa654e872da588077e19679"},"dist": {"type": "zip",- "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b",- "reference": "d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b",+ "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/c3fe76976081ab871aa654e872da588077e19679",+ "reference": "c3fe76976081ab871aa654e872da588077e19679","shasum": ""},"require": {@@ -307,7 +307,7 @@],"support": {"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",- "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.37.0"+ "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.37.1"},"funding": [{@@ -315,7 +315,7 @@"type": "github"}],- "time": "2023-10-28T14:49:50+00:00"+ "time": "2023-10-29T20:51:23+00:00"},{"name": "psr/container",diff --git a/.ci/phpcs.sh b/.ci/phpcs.shindex 49c6420f04..fac892de3e 100755--- a/.ci/phpcs.sh+++ b/.ci/phpcs.sh@@ -28,11 +28,30 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )# enable test .env file.# cp .ci/.env.ci .env+OUTPUT_FORMAT=txt+EXTRA_PARAMS=""++if [[ $GITHUB_ACTIONS = "true" ]]+then+ OUTPUT_FORMAT=github+ EXTRA_PARAMS="--diff --dry-run"+fi+# clean up php codecd $SCRIPT_DIR/php-cs-fixercomposer update --quietrm -f .php-cs-fixer.cache-PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php --allow-risky=yes+PHP_CS_FIXER_IGNORE_ENV=true+./vendor/bin/php-cs-fixer fix \+ --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \+ --format=$OUTPUT_FORMAT \+ --allow-risky=yes \+ $EXTRA_PARAMS++EXIT_CODE=$?++echo "Exit code for CS fixer is $EXIT_CODE."+cd $SCRIPT_DIR/..-exit 0+exit $EXIT_CODEdiff --git a/.ci/phpmd/phpmd.xml b/.ci/phpmd/phpmd.xmlindex 47c3f85687..9255fde854 100644--- a/.ci/phpmd/phpmd.xml+++ b/.ci/phpmd/phpmd.xml@@ -66,6 +66,8 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r<!-- include clean code manually --><rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" /><rule ref="rulesets/cleancode.xml/ElseExpression" />+ <rule ref="rulesets/cleancode.xml/MissingImport" />+ <rule ref="rulesets/cleancode.xml/UndefinedVariable" /><!-- no this one --><!--<rule ref="rulesets/cleancode.xml/StaticAccess" />-->diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.ymlindex 1b01749d34..f219315ac5 100644--- a/.github/workflows/sonarcloud.yml+++ b/.github/workflows/sonarcloud.yml@@ -54,6 +54,9 @@ jobs:- name: PHPMDrun: .ci/phpmd.sh+ - name: PHP CS Fixer+ run: .ci/phpcs.sh+- name: "Create database file"run: touch storage/database/database.sqlitediff --git a/app/Api/V2/Controllers/Chart/AccountController.php b/app/Api/V2/Controllers/Chart/AccountController.phpindex b45fa09e9f..15442e4d84 100644--- a/app/Api/V2/Controllers/Chart/AccountController.php+++ b/app/Api/V2/Controllers/Chart/AccountController.php@@ -96,15 +96,17 @@ class AccountController extends Controller// user's preferences$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray();$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);- /** @var TransactionCurrency $default */- $default = app('amount')->getDefaultCurrency();- $accounts = $this->repository->getAccountsById($frontPage->data);- $chartData = [];if (!(is_array($frontPage->data) && count($frontPage->data) > 0)) {$frontPage->data = $defaultSet;$frontPage->save();}++ /** @var TransactionCurrency $default */+ $default = app('amount')->getDefaultCurrency();+ $accounts = $this->repository->getAccountsById($frontPage->data);+ $chartData = [];+/** @var Account $account */foreach ($accounts as $account) {$currency = $this->repository->getAccountCurrency($account);diff --git a/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php b/app/Api/V2/Controllers/Model/BudgetLimit/ListController.phpindex c921ed72b9..4cfbb19069 100644--- a/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php+++ b/app/Api/V2/Controllers/Model/BudgetLimit/ListController.php@@ -38,19 +38,19 @@ use Illuminate\Pagination\LengthAwarePaginator;*/class ListController extends Controller{-// private BudgetLimitRepositoryInterface $repository;-//-// public function __construct()-// {-// parent::__construct();-// $this->middleware(-// function ($request, $next) {-// $this->repository = app(BudgetLimitRepositoryInterface::class);-//-// return $next($request);-// }-// );-// }+ // private BudgetLimitRepositoryInterface $repository;+ //+ // public function __construct()+ // {+ // parent::__construct();+ // $this->middleware(+ // function ($request, $next) {+ // $this->repository = app(BudgetLimitRepositoryInterface::class);+ //+ // return $next($request);+ // }+ // );+ // }/*** This endpoint is documented at:@@ -59,18 +59,18 @@ class ListController extends Controllerpublic function index(DateRequest $request, Budget $budget): JsonResponse{return response()->json([]);-// throw new FireflyException('Needs refactoring, move to IndexController.');-// $pageSize = $this->parameters->get('limit');-// $dates = $request->getAll();-// $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);-// $total = $collection->count();-// $collection->slice($pageSize * $this->parameters->get('page'), $pageSize);-//-// $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page'));-// $transformer = new BudgetLimitTransformer();-//-// return response()-// ->api($this->jsonApiList('budget-limits', $paginator, $transformer))-// ->header('Content-Type', self::CONTENT_TYPE);+ // throw new FireflyException('Needs refactoring, move to IndexController.');+ // $pageSize = $this->parameters->get('limit');+ // $dates = $request->getAll();+ // $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);+ // $total = $collection->count();+ // $collection->slice($pageSize * $this->parameters->get('page'), $pageSize);+ //+ // $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page'));+ // $transformer = new BudgetLimitTransformer();+ //+ // return response()+ // ->api($this->jsonApiList('budget-limits', $paginator, $transformer))+ // ->header('Content-Type', self::CONTENT_TYPE);}}diff --git a/app/Console/Commands/System/ForceDecimalSize.php b/app/Console/Commands/System/ForceDecimalSize.phpindex 685324f20c..5d963ff900 100644--- a/app/Console/Commands/System/ForceDecimalSize.php+++ b/app/Console/Commands/System/ForceDecimalSize.php@@ -53,8 +53,8 @@ class ForceDecimalSize extends Command{use ShowsFriendlyMessages;- protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';- protected $signature = 'firefly-iii:force-decimal-size';+ protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';+ protected $signature = 'firefly-iii:force-decimal-size';private string $cast;private array $classes= [diff --git a/app/Console/Commands/Upgrade/MigrateToRules.php b/app/Console/Commands/Upgrade/MigrateToRules.phpindex d35610d6d5..43a325544f 100644--- a/app/Console/Commands/Upgrade/MigrateToRules.php+++ b/app/Console/Commands/Upgrade/MigrateToRules.php@@ -56,7 +56,7 @@ class MigrateToRules extends Command** @var string*/- protected $signature = 'firefly-iii:bills-to-rules {--F|force : Force the execution of this command.}';+ protected $signature = 'firefly-iii:bills-to-rules {--F|force : Force the execution of this command.}';private BillRepositoryInterface $billRepository;private int $count;private RuleGroupRepositoryInterface $ruleGroupRepository;diff --git a/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php b/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.phpindex f1f23df484..8e3699eaab 100644--- a/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php+++ b/app/Console/Commands/Upgrade/UpgradeLiabilitiesEight.php@@ -249,11 +249,11 @@ class UpgradeLiabilitiesEight extends Command// code is kept in place so I can revisit my reasoning.$delete = false;-// if ($delete) {+ // if ($delete) {$service = app(TransactionGroupDestroyService::class);$service->destroy($journal->transactionGroup);$count++;-// }+ // }}return $count;diff --git a/app/Exceptions/IntervalException.php b/app/Exceptions/IntervalException.phpindex 6c14be925e..6c841b0462 100644--- a/app/Exceptions/IntervalException.php+++ b/app/Exceptions/IntervalException.php@@ -34,11 +34,10 @@ use Throwable;*/final class IntervalException extends Exception{-public array $availableIntervals;public Periodicity $periodicity;/** @var string */- protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';+ protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null){@@ -60,8 +59,7 @@ final class IntervalException extends Exceptionarray $intervals,int $code = 0,?Throwable $previous = null- ): IntervalException- {+ ): IntervalException {$message = sprintf('The periodicity %s is unknown. Choose one of available periodicity: %s',$periodicity->name,diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.phpindex c4f11c87e9..9e0761f11b 100644--- a/app/Helpers/Attachments/AttachmentHelper.php+++ b/app/Helpers/Attachments/AttachmentHelper.php@@ -48,8 +48,7 @@ class AttachmentHelper implements AttachmentHelperInterfaceprotected array $allowedMimes = [];protected int $maxUploadSize = 0;- /** @var Filesystem The disk where attachments are stored. */- protected $uploadDisk;+ protected Filesystem $uploadDisk;/*** AttachmentHelper constructor.diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.phpindex 60d331fe03..a7e3b61b8c 100644--- a/app/Http/Controllers/Transaction/MassController.php+++ b/app/Http/Controllers/Transaction/MassController.php@@ -252,7 +252,7 @@ class MassController extends Controllertry {$carbon = Carbon::parse($value[$journalId]);} catch (InvalidArgumentException $e) {- Log::warning(sprintf('Could not parse "%s" but dont mind',$value[$journalId]));+ Log::warning(sprintf('Could not parse "%s" but dont mind', $value[$journalId]));Log::warning($e->getMessage());return null;diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.phpindex c9ad7e71c5..654309c22d 100644--- a/app/Repositories/Tag/TagRepository.php+++ b/app/Repositories/Tag/TagRepository.php@@ -113,7 +113,7 @@ class TagRepository implements TagRepositoryInterface*/public function setUser(User | Authenticatable | null $user): void{- if ($user instanceof User ) {+ if ($user instanceof User) {$this->user = $user;}}diff --git a/app/Rules/IsBoolean.php b/app/Rules/IsBoolean.phpindex 22c4cda2b7..7b45e3bb04 100644--- a/app/Rules/IsBoolean.php+++ b/app/Rules/IsBoolean.php@@ -32,7 +32,6 @@ use Illuminate\Contracts\Validation\ValidationRule;*/class IsBoolean implements ValidationRule{-/*** @param string $attribute* @param mixed $valuediff --git a/app/Rules/IsDateOrTime.php b/app/Rules/IsDateOrTime.phpindex 8de0a1ffd7..4c5f637d5e 100644--- a/app/Rules/IsDateOrTime.php+++ b/app/Rules/IsDateOrTime.php@@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;*/class IsDateOrTime implements ValidationRule{-/*** @param string $attribute* @param mixed $value@@ -47,7 +46,8 @@ class IsDateOrTime implements ValidationRule{$value = (string)$value;if ('' === $value) {- $fail('validation.date_or_time')->translate();;+ $fail('validation.date_or_time')->translate();+ ;return;}if (10 === strlen($value)) {@@ -57,12 +57,14 @@ class IsDateOrTime implements ValidationRule} catch (InvalidDateException $e) { // @phpstan-ignore-lineapp('log')->error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));- $fail('validation.date_or_time')->translate();;+ $fail('validation.date_or_time')->translate();+ ;return;} catch (InvalidFormatException $e) { // @phpstan-ignore-lineapp('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage()));- $fail('validation.date_or_time')->translate();;+ $fail('validation.date_or_time')->translate();+ ;return;}@@ -74,12 +76,14 @@ class IsDateOrTime implements ValidationRule} catch (InvalidDateException $e) { // @phpstan-ignore-lineapp('log')->error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));- $fail('validation.date_or_time')->translate();;+ $fail('validation.date_or_time')->translate();+ ;return;} catch (InvalidFormatException $e) {app('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage()));- $fail('validation.date_or_time')->translate();;+ $fail('validation.date_or_time')->translate();+ ;return;}}diff --git a/app/Rules/IsTransferAccount.php b/app/Rules/IsTransferAccount.phpindex 34688b262f..6c69a0fd03 100644--- a/app/Rules/IsTransferAccount.php+++ b/app/Rules/IsTransferAccount.php@@ -34,7 +34,6 @@ use Illuminate\Contracts\Validation\ValidationRule;*/class IsTransferAccount implements ValidationRule{-/*** @param string $attribute* @param mixed $valuediff --git a/app/Rules/ValidJournals.php b/app/Rules/ValidJournals.phpindex d1d4a02b23..580d38a7f4 100644--- a/app/Rules/ValidJournals.php+++ b/app/Rules/ValidJournals.php@@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;*/class ValidJournals implements ValidationRule{-/*** @param string $attribute* @param mixed $valuediff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.phpindex b66ef92be2..95f5ab6188 100644--- a/app/Services/Internal/Update/RecurrenceUpdateService.php+++ b/app/Services/Internal/Update/RecurrenceUpdateService.php@@ -293,7 +293,8 @@ class RecurrenceUpdateServiceif (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) {$currency = $currencyFactory->find(array_key_exists('currency_id', $submitted) ? (int)$submitted['currency_id'] : null,- array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null);+ array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null+ );}if (null === $currency) {unset($submitted['currency_id'], $submitted['currency_code']);@@ -304,7 +305,8 @@ class RecurrenceUpdateServiceif (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {$foreignCurrency = $currencyFactory->find(array_key_exists('foreign_currency_id', $submitted) ? (int)$submitted['foreign_currency_id'] : null,- array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null);+ array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null+ );}if (null === $foreignCurrency) {unset($submitted['foreign_currency_id'], $currency['foreign_currency_code']);diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex 2ba2956767..f9a43667c0 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -89,10 +89,10 @@ class Navigationif (!array_key_exists($repeatFreq, $functionMap)) {Log::error(sprintf(- 'The periodicity %s is unknown. Choose one of available periodicity: %s',- $repeatFreq,- join(', ', array_keys($functionMap))- ));+ 'The periodicity %s is unknown. Choose one of available periodicity: %s',+ $repeatFreq,+ join(', ', array_keys($functionMap))+ ));return $theDate;}@@ -352,12 +352,12 @@ class Navigationpublic function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int{Log::debug(sprintf(- 'diffInPeriods: %s (skip: %d), between %s and %s.',- $period,- $skip,- $beginning->format('Y-m-d'),- $end->format('Y-m-d')- ));+ 'diffInPeriods: %s (skip: %d), between %s and %s.',+ $period,+ $skip,+ $beginning->format('Y-m-d'),+ $end->format('Y-m-d')+ ));$map = ['daily' => 'floatDiffInDays','weekly' => 'floatDiffInWeeks',@@ -394,11 +394,11 @@ class Navigation$parameter = $skip + 1;$diff = ceil($diff / $parameter) * $parameter;Log::debug(sprintf(- 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',- $skip,- $parameter,- $diff- ));+ 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',+ $skip,+ $parameter,+ $diff+ ));}return (int)$diff;diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 609ee56836..d200dd681a 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -322,15 +322,15 @@ class Steam$balances[$format] = $currentBalance;app('log')->debug(sprintf(- '%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',- $format,- $currency->code,- $rate,- $currency->code,- $transaction['amount'],- $native->code,- $convertedAmount- ));+ '%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',+ $format,+ $currency->code,+ $rate,+ $currency->code,+ $transaction['amount'],+ $native->code,+ $convertedAmount+ ));}diff --git a/app/Transformers/V2/TransactionGroupTransformer.php b/app/Transformers/V2/TransactionGroupTransformer.phpindex ca31cae79f..6868554516 100644--- a/app/Transformers/V2/TransactionGroupTransformer.php+++ b/app/Transformers/V2/TransactionGroupTransformer.php@@ -43,7 +43,6 @@ use stdClass;*/class TransactionGroupTransformer extends AbstractTransformer{-private ExchangeRateConverter $converter;private array $currencies = [];private TransactionCurrency $default;diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.phpindex ca0c9f0087..c980bb6d22 100644--- a/app/Validation/FireflyValidator.php+++ b/app/Validation/FireflyValidator.php@@ -47,7 +47,6 @@ use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;use ValueError;-/*** Class FireflyValidator.*/