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 . '/../../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);

View File

@ -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",

View File

@ -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 code
cd $SCRIPT_DIR/php-cs-fixer
composer update --quiet
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/..
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 -->
<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" />-->

View File

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

View File

@ -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);

View File

@ -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 Controller
public 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);
}
}

View File

@ -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
= [

View File

@ -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;

View File

@ -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;

View File

@ -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 Exception
array $intervals,
int $code = 0,
?Throwable $previous = null
): IntervalException
{
): IntervalException {
$message = sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$periodicity->name,

View File

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

View File

@ -252,7 +252,7 @@ class MassController extends Controller
try {
$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;

View File

@ -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;
}
}

View File

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

View File

@ -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-line
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;
} catch (InvalidFormatException $e) { // @phpstan-ignore-line
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;
}
@ -74,12 +76,14 @@ class IsDateOrTime implements ValidationRule
} catch (InvalidDateException $e) { // @phpstan-ignore-line
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;
} 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;
}
}

View File

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

View File

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

View File

@ -293,7 +293,8 @@ class RecurrenceUpdateService
if (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 RecurrenceUpdateService
if (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']);

View File

@ -89,10 +89,10 @@ class Navigation
if (!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 Navigation
public 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;

View File

@ -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
));
}

View File

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

View File

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