Expand action and clean up code.

This commit is contained in:
James Cole 2023-11-04 14:09:51 +01:00
parent 6eabe5fa8c
commit 5a35960434
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
23 changed files with 119 additions and 93 deletions

View File

@ -27,7 +27,7 @@ $paths = [
$current . '/../../database', $current . '/../../database',
$current . '/../../routes', $current . '/../../routes',
$current . '/../../tests', $current . '/../../tests',
$current . '/../../resources/lang', $current . '/../../resources/lang/en_US',
]; ];
$finder = PhpCsFixer\Finder::create() $finder = PhpCsFixer\Finder::create()
@ -36,9 +36,11 @@ $finder = PhpCsFixer\Finder::create()
$config = new PhpCsFixer\Config(); $config = new PhpCsFixer\Config();
return $config->setRules([ return $config->setRules([
'@PSR12' => true, '@PhpCsFixer:risky' => true,
'declare_strict_types' => true, // '@PSR12:risky' => true,
'strict_param' => true, 'declare_strict_types' => true,
'array_syntax' => ['syntax' => 'short'], 'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'native_function_invocation' => false,
]) ])
->setFinder($finder); ->setFinder($finder);

View File

@ -226,16 +226,16 @@
}, },
{ {
"name": "friendsofphp/php-cs-fixer", "name": "friendsofphp/php-cs-fixer",
"version": "v3.37.0", "version": "v3.37.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
"reference": "d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b" "reference": "c3fe76976081ab871aa654e872da588077e19679"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b", "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/c3fe76976081ab871aa654e872da588077e19679",
"reference": "d5ccc3807fd496ac2b448e8e5e57aa0772f0d18b", "reference": "c3fe76976081ab871aa654e872da588077e19679",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -307,7 +307,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", "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": [ "funding": [
{ {
@ -315,7 +315,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-10-28T14:49:50+00:00" "time": "2023-10-29T20:51:23+00:00"
}, },
{ {
"name": "psr/container", "name": "psr/container",

View File

@ -28,11 +28,30 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# enable test .env file. # enable test .env file.
# cp .ci/.env.ci .env # 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 code # clean up php code
cd $SCRIPT_DIR/php-cs-fixer cd $SCRIPT_DIR/php-cs-fixer
composer update --quiet composer update --quiet
rm -f .php-cs-fixer.cache rm -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/.. cd $SCRIPT_DIR/..
exit 0 exit $EXIT_CODE

View File

@ -66,6 +66,8 @@ phpmd database,app,tests html /gdrive-all/development/phpmd/phpmd.xml > public/r
<!-- include clean code manually --> <!-- include clean code manually -->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" /> <rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
<rule ref="rulesets/cleancode.xml/ElseExpression" /> <rule ref="rulesets/cleancode.xml/ElseExpression" />
<rule ref="rulesets/cleancode.xml/MissingImport" />
<rule ref="rulesets/cleancode.xml/UndefinedVariable" />
<!-- no this one --> <!-- no this one -->
<!--<rule ref="rulesets/cleancode.xml/StaticAccess" />--> <!--<rule ref="rulesets/cleancode.xml/StaticAccess" />-->

View File

@ -54,6 +54,9 @@ jobs:
- name: PHPMD - name: PHPMD
run: .ci/phpmd.sh run: .ci/phpmd.sh
- name: PHP CS Fixer
run: .ci/phpcs.sh
- name: "Create database file" - name: "Create database file"
run: touch storage/database/database.sqlite run: touch storage/database/database.sqlite

View File

@ -96,15 +96,17 @@ class AccountController extends Controller
// user's preferences // user's preferences
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray(); $defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); $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)) { if (!(is_array($frontPage->data) && count($frontPage->data) > 0)) {
$frontPage->data = $defaultSet; $frontPage->data = $defaultSet;
$frontPage->save(); $frontPage->save();
} }
/** @var TransactionCurrency $default */
$default = app('amount')->getDefaultCurrency();
$accounts = $this->repository->getAccountsById($frontPage->data);
$chartData = [];
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
$currency = $this->repository->getAccountCurrency($account); $currency = $this->repository->getAccountCurrency($account);

View File

@ -38,19 +38,19 @@ use Illuminate\Pagination\LengthAwarePaginator;
*/ */
class ListController extends Controller class ListController extends Controller
{ {
// private BudgetLimitRepositoryInterface $repository; // private BudgetLimitRepositoryInterface $repository;
// //
// public function __construct() // public function __construct()
// { // {
// parent::__construct(); // parent::__construct();
// $this->middleware( // $this->middleware(
// function ($request, $next) { // function ($request, $next) {
// $this->repository = app(BudgetLimitRepositoryInterface::class); // $this->repository = app(BudgetLimitRepositoryInterface::class);
// //
// return $next($request); // return $next($request);
// } // }
// ); // );
// } // }
/** /**
* This endpoint is documented at: * This endpoint is documented at:
@ -59,18 +59,18 @@ class ListController extends Controller
public function index(DateRequest $request, Budget $budget): JsonResponse public function index(DateRequest $request, Budget $budget): JsonResponse
{ {
return response()->json([]); return response()->json([]);
// throw new FireflyException('Needs refactoring, move to IndexController.'); // throw new FireflyException('Needs refactoring, move to IndexController.');
// $pageSize = $this->parameters->get('limit'); // $pageSize = $this->parameters->get('limit');
// $dates = $request->getAll(); // $dates = $request->getAll();
// $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']); // $collection = $this->repository->getBudgetLimits($budget, $dates['start'], $dates['end']);
// $total = $collection->count(); // $total = $collection->count();
// $collection->slice($pageSize * $this->parameters->get('page'), $pageSize); // $collection->slice($pageSize * $this->parameters->get('page'), $pageSize);
// //
// $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page')); // $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page'));
// $transformer = new BudgetLimitTransformer(); // $transformer = new BudgetLimitTransformer();
// //
// return response() // return response()
// ->api($this->jsonApiList('budget-limits', $paginator, $transformer)) // ->api($this->jsonApiList('budget-limits', $paginator, $transformer))
// ->header('Content-Type', self::CONTENT_TYPE); // ->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@ -53,8 +53,8 @@ class ForceDecimalSize extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).'; protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size'; protected $signature = 'firefly-iii:force-decimal-size';
private string $cast; private string $cast;
private array $classes private array $classes
= [ = [

View File

@ -56,7 +56,7 @@ class MigrateToRules extends Command
* *
* @var string * @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 BillRepositoryInterface $billRepository;
private int $count; private int $count;
private RuleGroupRepositoryInterface $ruleGroupRepository; private RuleGroupRepositoryInterface $ruleGroupRepository;

View File

@ -249,11 +249,11 @@ class UpgradeLiabilitiesEight extends Command
// code is kept in place so I can revisit my reasoning. // code is kept in place so I can revisit my reasoning.
$delete = false; $delete = false;
// if ($delete) { // if ($delete) {
$service = app(TransactionGroupDestroyService::class); $service = app(TransactionGroupDestroyService::class);
$service->destroy($journal->transactionGroup); $service->destroy($journal->transactionGroup);
$count++; $count++;
// } // }
} }
return $count; return $count;

View File

@ -34,11 +34,10 @@ use Throwable;
*/ */
final class IntervalException extends Exception final class IntervalException extends Exception
{ {
public array $availableIntervals; public array $availableIntervals;
public Periodicity $periodicity; public Periodicity $periodicity;
/** @var string */ /** @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) public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
{ {
@ -60,8 +59,7 @@ final class IntervalException extends Exception
array $intervals, array $intervals,
int $code = 0, int $code = 0,
?Throwable $previous = null ?Throwable $previous = null
): IntervalException ): IntervalException {
{
$message = sprintf( $message = sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s', 'The periodicity %s is unknown. Choose one of available periodicity: %s',
$periodicity->name, $periodicity->name,

View File

@ -48,8 +48,7 @@ class AttachmentHelper implements AttachmentHelperInterface
protected array $allowedMimes = []; protected array $allowedMimes = [];
protected int $maxUploadSize = 0; protected int $maxUploadSize = 0;
/** @var Filesystem The disk where attachments are stored. */ protected Filesystem $uploadDisk;
protected $uploadDisk;
/** /**
* AttachmentHelper constructor. * AttachmentHelper constructor.

View File

@ -252,7 +252,7 @@ class MassController extends Controller
try { try {
$carbon = Carbon::parse($value[$journalId]); $carbon = Carbon::parse($value[$journalId]);
} catch (InvalidArgumentException $e) { } 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()); Log::warning($e->getMessage());
return null; return null;

View File

@ -113,7 +113,7 @@ class TagRepository implements TagRepositoryInterface
*/ */
public function setUser(User | Authenticatable | null $user): void public function setUser(User | Authenticatable | null $user): void
{ {
if ($user instanceof User ) { if ($user instanceof User) {
$this->user = $user; $this->user = $user;
} }
} }

View File

@ -32,7 +32,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/ */
class IsBoolean implements ValidationRule class IsBoolean implements ValidationRule
{ {
/** /**
* @param string $attribute * @param string $attribute
* @param mixed $value * @param mixed $value

View File

@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/ */
class IsDateOrTime implements ValidationRule class IsDateOrTime implements ValidationRule
{ {
/** /**
* @param string $attribute * @param string $attribute
* @param mixed $value * @param mixed $value
@ -47,7 +46,8 @@ class IsDateOrTime implements ValidationRule
{ {
$value = (string)$value; $value = (string)$value;
if ('' === $value) { if ('' === $value) {
$fail('validation.date_or_time')->translate();; $fail('validation.date_or_time')->translate();
;
return; return;
} }
if (10 === strlen($value)) { if (10 === strlen($value)) {
@ -57,12 +57,14 @@ class IsDateOrTime implements ValidationRule
} catch (InvalidDateException $e) { // @phpstan-ignore-line } catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage())); app('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; return;
} catch (InvalidFormatException $e) { // @phpstan-ignore-line } catch (InvalidFormatException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage())); 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; return;
} }
@ -74,12 +76,14 @@ class IsDateOrTime implements ValidationRule
} catch (InvalidDateException $e) { // @phpstan-ignore-line } catch (InvalidDateException $e) { // @phpstan-ignore-line
app('log')->error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage())); app('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; return;
} catch (InvalidFormatException $e) { } catch (InvalidFormatException $e) {
app('log')->error(sprintf('"%s" is of an invalid format: %s', $value, $e->getMessage())); 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; return;
} }
} }

View File

@ -34,7 +34,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/ */
class IsTransferAccount implements ValidationRule class IsTransferAccount implements ValidationRule
{ {
/** /**
* @param string $attribute * @param string $attribute
* @param mixed $value * @param mixed $value

View File

@ -35,7 +35,6 @@ use Illuminate\Contracts\Validation\ValidationRule;
*/ */
class ValidJournals implements ValidationRule class ValidJournals implements ValidationRule
{ {
/** /**
* @param string $attribute * @param string $attribute
* @param mixed $value * @param mixed $value

View File

@ -293,7 +293,8 @@ class RecurrenceUpdateService
if (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) { if (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) {
$currency = $currencyFactory->find( $currency = $currencyFactory->find(
array_key_exists('currency_id', $submitted) ? (int)$submitted['currency_id'] : null, 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) { if (null === $currency) {
unset($submitted['currency_id'], $submitted['currency_code']); unset($submitted['currency_id'], $submitted['currency_code']);
@ -304,7 +305,8 @@ class RecurrenceUpdateService
if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) { if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {
$foreignCurrency = $currencyFactory->find( $foreignCurrency = $currencyFactory->find(
array_key_exists('foreign_currency_id', $submitted) ? (int)$submitted['foreign_currency_id'] : null, 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) { if (null === $foreignCurrency) {
unset($submitted['foreign_currency_id'], $currency['foreign_currency_code']); unset($submitted['foreign_currency_id'], $currency['foreign_currency_code']);

View File

@ -89,10 +89,10 @@ class Navigation
if (!array_key_exists($repeatFreq, $functionMap)) { if (!array_key_exists($repeatFreq, $functionMap)) {
Log::error(sprintf( Log::error(sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s', 'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq, $repeatFreq,
join(', ', array_keys($functionMap)) join(', ', array_keys($functionMap))
)); ));
return $theDate; return $theDate;
} }
@ -352,12 +352,12 @@ class Navigation
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
{ {
Log::debug(sprintf( Log::debug(sprintf(
'diffInPeriods: %s (skip: %d), between %s and %s.', 'diffInPeriods: %s (skip: %d), between %s and %s.',
$period, $period,
$skip, $skip,
$beginning->format('Y-m-d'), $beginning->format('Y-m-d'),
$end->format('Y-m-d') $end->format('Y-m-d')
)); ));
$map = [ $map = [
'daily' => 'floatDiffInDays', 'daily' => 'floatDiffInDays',
'weekly' => 'floatDiffInWeeks', 'weekly' => 'floatDiffInWeeks',
@ -394,11 +394,11 @@ class Navigation
$parameter = $skip + 1; $parameter = $skip + 1;
$diff = ceil($diff / $parameter) * $parameter; $diff = ceil($diff / $parameter) * $parameter;
Log::debug(sprintf( Log::debug(sprintf(
'diffInPeriods: skip is %d, so param is %d, and diff becomes %d', 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
$skip, $skip,
$parameter, $parameter,
$diff $diff
)); ));
} }
return (int)$diff; return (int)$diff;

View File

@ -322,15 +322,15 @@ class Steam
$balances[$format] = $currentBalance; $balances[$format] = $currentBalance;
app('log')->debug(sprintf( app('log')->debug(sprintf(
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s', '%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format, $format,
$currency->code, $currency->code,
$rate, $rate,
$currency->code, $currency->code,
$transaction['amount'], $transaction['amount'],
$native->code, $native->code,
$convertedAmount $convertedAmount
)); ));
} }

View File

@ -43,7 +43,6 @@ use stdClass;
*/ */
class TransactionGroupTransformer extends AbstractTransformer class TransactionGroupTransformer extends AbstractTransformer
{ {
private ExchangeRateConverter $converter; private ExchangeRateConverter $converter;
private array $currencies = []; private array $currencies = [];
private TransactionCurrency $default; private TransactionCurrency $default;

View File

@ -47,7 +47,6 @@ use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
use ValueError; use ValueError;
/** /**
* Class FireflyValidator. * Class FireflyValidator.
*/ */