Various code cleanup.

This commit is contained in:
James Cole
2018-07-27 05:03:37 +02:00
parent 0312ba8ad7
commit e3e0e12fef
43 changed files with 167 additions and 145 deletions

View File

@@ -90,6 +90,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $opposing_id // ID of the opposing transaction, used in collector * @property int $opposing_id // ID of the opposing transaction, used in collector
* @property bool $encrypted // is the journal encrypted * @property bool $encrypted // is the journal encrypted
* @property bool reconciled * @property bool reconciled
* @property string transaction_category_encrypted
* @property string transaction_journal_category_encrypted
* @property string transaction_budget_encrypted
* @property string transaction_journal_budget_encrypted
* @property string type
* @property string name
* @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/ */
class Transaction extends Model class Transaction extends Model

View File

@@ -50,18 +50,19 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Collection $tags * @property Collection $tags
* @property mixed user_id * @property mixed user_id
* @property mixed transactions * @property mixed transactions
* @property int transaction_count * @property int transaction_count
* @property Carbon interest_date * @property Carbon interest_date
* @property Carbon book_date * @property Carbon book_date
* @property Carbon process_date * @property Carbon process_date
* @property bool encrypted * @property bool encrypted
* @property int order * @property int order
* @property int budget_id * @property int budget_id
* @property string period_marker * @property string period_marker
* @property Carbon $date * @property Carbon $date
* @property string $transaction_type_type * @property string $transaction_type_type
* @property int $id * @property int $id
* @property TransactionType $transactionType * @property TransactionType $transactionType
* @property Collection budgets
* *
* @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.CouplingBetweenObjects)

View File

@@ -155,7 +155,7 @@ class BelongsUser implements Rule
*/ */
private function validateAccountId(int $value): bool private function validateAccountId(int $value): bool
{ {
$count = Account::where('id', '=', (int)$value)->where('user_id', '=', auth()->user()->id)->count(); $count = Account::where('id', '=', $value)->where('user_id', '=', auth()->user()->id)->count();
return 1 === $count; return 1 === $count;
} }

View File

@@ -72,7 +72,6 @@ class FixerIOv2 implements ExchangeRateInterface
'http://data.fixer.io/api/%s?access_key=%s&base=%s&symbols=%s', 'http://data.fixer.io/api/%s?access_key=%s&base=%s&symbols=%s',
$date->format('Y-m-d'), $apiKey, $fromCurrency->code, $toCurrency->code $date->format('Y-m-d'), $apiKey, $fromCurrency->code, $toCurrency->code
); );
$statusCode = -1;
Log::debug(sprintf('Going to request exchange rate using URI %s', str_replace($apiKey, 'xxxx', $uri))); Log::debug(sprintf('Going to request exchange rate using URI %s', str_replace($apiKey, 'xxxx', $uri)));
$client = new Client; $client = new Client;
try { try {

View File

@@ -33,6 +33,7 @@ use Preferences as Prefs;
*/ */
class Amount class Amount
{ {
/** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* bool $sepBySpace is $localeconv['n_sep_by_space'] * bool $sepBySpace is $localeconv['n_sep_by_space']
* int $signPosn = $localeconv['n_sign_posn'] * int $signPosn = $localeconv['n_sign_posn']
@@ -116,10 +117,11 @@ class Amount
* *
* @return string * @return string
*/ */
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = true): string public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = null): string
{ {
$locale = explode(',', (string)trans('config.locale')); $coloured = $coloured ?? true;
$locale = array_map('trim', $locale); $locale = explode(',', (string)trans('config.locale'));
$locale = array_map('trim', $locale);
setlocale(LC_MONETARY, $locale); setlocale(LC_MONETARY, $locale);
$float = round($amount, 12); $float = round($amount, 12);
$info = localeconv(); $info = localeconv();
@@ -205,6 +207,7 @@ class Amount
*/ */
public function getDefaultCurrency(): TransactionCurrency public function getDefaultCurrency(): TransactionCurrency
{ {
/** @var User $user */
$user = auth()->user(); $user = auth()->user();
return $this->getDefaultCurrencyByUser($user); return $this->getDefaultCurrencyByUser($user);

View File

@@ -47,14 +47,14 @@ class AccountList implements BinderInterface
if (auth()->check()) { if (auth()->check()) {
$collection = new Collection; $collection = new Collection;
if ($value === 'allAssetAccounts') { if ('allAssetAccounts' === $value) {
/** @var \Illuminate\Support\Collection $collection */ /** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->accounts() $collection = auth()->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.type', AccountType::ASSET) ->where('account_types.type', AccountType::ASSET)
->get(['accounts.*']); ->get(['accounts.*']);
} }
if ($value !== 'allAssetAccounts') { if ('allAssetAccounts' !== $value) {
$list = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
@@ -62,7 +62,7 @@ class AccountList implements BinderInterface
$list[] = (int)$entry; $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
Log::error('Account list is empty.'); Log::error('Account list is empty.');
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }

View File

@@ -48,7 +48,7 @@ class BudgetList implements BinderInterface
$list[] = (int)$entry; $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }
@@ -59,7 +59,7 @@ class BudgetList implements BinderInterface
->get(); ->get();
// add empty budget if applicable. // add empty budget if applicable.
if (\in_array(0, $list)) { if (\in_array(0, $list, true)) {
$collection->push(new Budget); $collection->push(new Budget);
} }

View File

@@ -48,7 +48,7 @@ class CategoryList implements BinderInterface
$list[] = (int)$entry; $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }
@@ -58,7 +58,7 @@ class CategoryList implements BinderInterface
->get(); ->get();
// add empty category if applicable. // add empty category if applicable.
if (\in_array(0, $list)) { if (\in_array(0, $list, true)) {
$collection->push(new Category); $collection->push(new Category);
} }

View File

@@ -51,7 +51,7 @@ class Date implements BinderInterface
try { try {
$date = new Carbon($value); $date = new Carbon($value);
} catch (Exception $e) { } catch (Exception $e) {
Log::error('Could not parse date "' . $value . '" for user #' . auth()->user()->id); Log::error(sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage()));
throw new NotFoundHttpException; throw new NotFoundHttpException;
} }

View File

@@ -27,30 +27,14 @@ use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Routing\Route; use Illuminate\Routing\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Log; use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Class ImportProvider. * Class ImportProvider.
*/ */
class ImportProvider implements BinderInterface class ImportProvider implements BinderInterface
{ {
/**
* @param string $value
* @param Route $route
*
* @return Carbon
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public static function routeBinder(string $value, Route $route): string
{
$providers = array_keys(self::getProviders());
if (\in_array($value, $providers, true)) {
return $value;
}
throw new NotFoundHttpException;
}
/** /**
* @return array * @return array
*/ */
@@ -99,4 +83,20 @@ class ImportProvider implements BinderInterface
return $providers; return $providers;
} }
/**
* @param string $value
* @param Route $route
*
* @return Carbon
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public static function routeBinder(string $value, Route $route): string
{
$providers = array_keys(self::getProviders());
if (\in_array($value, $providers, true)) {
return $value;
}
throw new NotFoundHttpException;
}
} }

View File

@@ -47,7 +47,7 @@ class JournalList implements BinderInterface
$list[] = (int)$entry; $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }

View File

@@ -51,7 +51,7 @@ class SimpleJournalList implements BinderInterface
$list[] = (int)$entry; $list[] = (int)$entry;
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }

View File

@@ -50,7 +50,7 @@ class TagList implements BinderInterface
$list[] = strtolower(trim($entry)); $list[] = strtolower(trim($entry));
} }
$list = array_unique($list); $list = array_unique($list);
if (\count($list) === 0) { if (0 === \count($list)) {
Log::error('Tag list is empty.'); Log::error('Tag list is empty.');
throw new NotFoundHttpException; // @codeCoverageIgnore throw new NotFoundHttpException; // @codeCoverageIgnore
} }
@@ -61,7 +61,7 @@ class TagList implements BinderInterface
$collection = $allTags->filter( $collection = $allTags->filter(
function (Tag $tag) use ($list) { function (Tag $tag) use ($list) {
return \in_array(strtolower($tag->tag), $list); return \in_array(strtolower($tag->tag), $list, true);
} }
); );

View File

@@ -50,7 +50,7 @@ class CacheProperties
/** /**
* @param $property * @param $property
*/ */
public function addProperty($property) public function addProperty($property): void
{ {
$this->properties->push($property); $this->properties->push($property);
} }
@@ -87,14 +87,14 @@ class CacheProperties
/** /**
* @param $data * @param $data
*/ */
public function store($data) public function store($data): void
{ {
Cache::forever($this->hash, $data); Cache::forever($this->hash, $data);
} }
/** /**
*/ */
private function hash() private function hash(): void
{ {
$content = ''; $content = '';
foreach ($this->properties as $property) { foreach ($this->properties as $property) {

View File

@@ -36,6 +36,7 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use Form; use Form;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\MessageBag; use Illuminate\Support\MessageBag;
use Log; use Log;
use RuntimeException; use RuntimeException;
@@ -251,7 +252,7 @@ class ExpandedForm
{ {
$options = $options ?? []; $options = $options ?? [];
$value = $value ?? 1; $value = $value ?? 1;
$options['checked'] = true === $checked ? true : false; $options['checked'] = true === $checked;
if (Session::has('preFilled')) { if (Session::has('preFilled')) {
$preFilled = session('preFilled'); $preFilled = session('preFilled');
@@ -688,13 +689,13 @@ class ExpandedForm
} }
/** /**
* @param string $name * @param string $name
* @param mixed $value * @param null $value
* @param array $options * @param array|null $options
* *
* @return \Illuminate\Support\HtmlString * @return HtmlString
*/ */
public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null) public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null): HtmlString
{ {
$options = $options ?? []; $options = $options ?? [];
$options['class'] = 'form-control'; $options['class'] = 'form-control';
@@ -877,6 +878,7 @@ class ExpandedForm
} }
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
// don't care about session errors. // don't care about session errors.
Log::debug(sprintf('Run time: %s', $e->getMessage()));
} }
if ($value instanceof Carbon) { if ($value instanceof Carbon) {
$value = $value->format('Y-m-d'); $value = $value->format('Y-m-d');
@@ -929,6 +931,8 @@ class ExpandedForm
* @param array $options * @param array $options
* *
* @return string * @return string
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \FireflyIII\Exceptions\FireflyException
*/ */
private function currencyField(string $name, string $view, $value = null, array $options = null): string private function currencyField(string $name, string $view, $value = null, array $options = null): string
{ {

View File

@@ -51,11 +51,11 @@ class FireflyConfig
/** /**
* @param string $name * @param string $name
* @param mixed $default * @param mixed $default
* *
* @return \FireflyIII\Models\Configuration|null * @return \FireflyIII\Models\Configuration|null
*/ */
public function get(string $name, $default = null): ?Configuration public function get(string $name, $default = null): ?Configuration
{ {
$fullName = 'ff-config-' . $name; $fullName = 'ff-config-' . $name;
if (Cache::has($fullName)) { if (Cache::has($fullName)) {
@@ -79,7 +79,7 @@ class FireflyConfig
/** /**
* @param string $name * @param string $name
* @param mixed $default * @param mixed $default
* *
* @return \FireflyIII\Models\Configuration|null * @return \FireflyIII\Models\Configuration|null
*/ */

View File

@@ -58,7 +58,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
$config = $this->repository->getConfiguration($this->importJob); $config = $this->repository->getConfiguration($this->importJob);
$mapping = $config['mapping'] ?? []; $mapping = $config['mapping'] ?? [];
$complete = \count($mapping) > 0; $complete = \count($mapping) > 0;
if ($complete === true) { if (true === $complete) {
// move job to correct stage to download transactions // move job to correct stage to download transactions
$this->repository->setStage($this->importJob, 'go-for-import'); $this->repository->setStage($this->importJob, 'go-for-import');
} }
@@ -79,12 +79,12 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
$config = $this->repository->getConfiguration($this->importJob); $config = $this->repository->getConfiguration($this->importJob);
$accounts = $config['accounts'] ?? []; $accounts = $config['accounts'] ?? [];
$mapping = $data['account_mapping'] ?? []; $mapping = $data['account_mapping'] ?? [];
$applyRules = (int)$data['apply_rules'] === 1; $applyRules = 1 === (int)$data['apply_rules'];
$final = []; $final = [];
if (\count($accounts) === 0) { if (0 === \count($accounts)) {
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
} }
if (\count($mapping) === 0) { if (0 === \count($mapping)) {
$messages = new MessageBag; $messages = new MessageBag;
$messages->add('nomap', (string)trans('import.bunq_no_mapping')); $messages->add('nomap', (string)trans('import.bunq_no_mapping'));
@@ -116,7 +116,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
{ {
$config = $this->repository->getConfiguration($this->importJob); $config = $this->repository->getConfiguration($this->importJob);
$accounts = $config['accounts'] ?? []; $accounts = $config['accounts'] ?? [];
if (\count($accounts) === 0) { if (0 === \count($accounts)) {
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
} }
// list the users accounts: // list the users accounts:

View File

@@ -183,7 +183,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
{ {
$canBeMapped = config('csv.import_roles.' . $name . '.mappable'); $canBeMapped = config('csv.import_roles.' . $name . '.mappable');
return $canBeMapped === true && $requested === true; return true === $canBeMapped && true === $requested;
} }
/** /**
@@ -247,7 +247,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
$collection = $this->repository->getAttachments($this->importJob); $collection = $this->repository->getAttachments($this->importJob);
/** @var Attachment $attachment */ /** @var Attachment $attachment */
foreach ($collection as $attachment) { foreach ($collection as $attachment) {
if ($attachment->filename === 'import_file') { if ('import_file' === $attachment->filename) {
$content = $this->attachments->getAttachmentContent($attachment); $content = $this->attachments->getAttachmentContent($attachment);
break; break;
} }
@@ -274,7 +274,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
*/ */
public function getValuesForMapping(Reader $reader, array $config, array $columnConfig): array public function getValuesForMapping(Reader $reader, array $config, array $columnConfig): array
{ {
$offset = isset($config['has-headers']) && $config['has-headers'] === true ? 1 : 0; $offset = isset($config['has-headers']) && true === $config['has-headers'] ? 1 : 0;
try { try {
$stmt = (new Statement)->offset($offset); $stmt = (new Statement)->offset($offset);
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
@@ -295,7 +295,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
continue; continue;
} }
$value = trim($line[$columnIndex]); $value = trim($line[$columnIndex]);
if (\strlen($value) === 0) { if ('' === $value) {
// value is empty, ignore it. // value is empty, ignore it.
continue; continue;
} }
@@ -309,7 +309,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
$columnConfig[$columnIndex]['values'] = array_unique($columnConfig[$columnIndex]['values']); $columnConfig[$columnIndex]['values'] = array_unique($columnConfig[$columnIndex]['values']);
asort($columnConfig[$columnIndex]['values']); asort($columnConfig[$columnIndex]['values']);
// if the count of this array is zero, there is nothing to map. // if the count of this array is zero, there is nothing to map.
if (\count($columnConfig[$columnIndex]['values']) === 0) { if (0 === \count($columnConfig[$columnIndex]['values'])) {
unset($columnConfig[$columnIndex]); unset($columnConfig[$columnIndex]);
} }
} }

View File

@@ -76,10 +76,10 @@ class ConfigureRolesHandler implements FileConfigurationInterface
if (\in_array($role, ['amount', 'amount_credit', 'amount_debit'])) { if (\in_array($role, ['amount', 'amount_credit', 'amount_debit'])) {
$hasAmount = true; $hasAmount = true;
} }
if ($role === 'foreign-currency-code') { if ('foreign-currency-code' === $role) {
$hasForeignCode = true; $hasForeignCode = true;
} }
if ($role === 'amount_foreign') { if ('amount_foreign' === $role) {
$hasForeignAmount = true; $hasForeignAmount = true;
} }
} }
@@ -122,7 +122,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$count = $config['column-count']; $count = $config['column-count'];
for ($i = 0; $i < $count; ++$i) { for ($i = 0; $i < $count; ++$i) {
$role = $data['role'][$i] ?? '_ignore'; $role = $data['role'][$i] ?? '_ignore';
$mapping = (isset($data['map'][$i]) && $data['map'][$i] === '1'); $mapping = (isset($data['map'][$i]) && '1' === $data['map'][$i]);
$config['column-roles'][$i] = $role; $config['column-roles'][$i] = $role;
$config['column-do-mapping'][$i] = $mapping; $config['column-do-mapping'][$i] = $mapping;
Log::debug(sprintf('Column %d has been given role %s (mapping: %s)', $i, $role, var_export($mapping, true))); Log::debug(sprintf('Column %d has been given role %s (mapping: %s)', $i, $role, var_export($mapping, true)));
@@ -130,7 +130,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$config = $this->ignoreUnmappableColumns($config); $config = $this->ignoreUnmappableColumns($config);
$messages = $this->configurationComplete($config); $messages = $this->configurationComplete($config);
if ($messages->count() === 0) { if (0 === $messages->count()) {
$this->repository->setStage($this->importJob, 'ready_to_run'); $this->repository->setStage($this->importJob, 'ready_to_run');
if ($this->isMappingNecessary($config)) { if ($this->isMappingNecessary($config)) {
$this->repository->setStage($this->importJob, 'map'); $this->repository->setStage($this->importJob, 'map');
@@ -175,7 +175,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
public function getExamplesFromFile(Reader $reader, array $config): void public function getExamplesFromFile(Reader $reader, array $config): void
{ {
$limit = (int)config('csv.example_rows', 5); $limit = (int)config('csv.example_rows', 5);
$offset = isset($config['has-headers']) && $config['has-headers'] === true ? 1 : 0; $offset = isset($config['has-headers']) && true === $config['has-headers'] ? 1 : 0;
// make statement. // make statement.
try { try {
@@ -214,7 +214,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
public function getHeaders(Reader $reader, array $config): array public function getHeaders(Reader $reader, array $config): array
{ {
$headers = []; $headers = [];
if (isset($config['has-headers']) && $config['has-headers'] === true) { if (isset($config['has-headers']) && true === $config['has-headers']) {
try { try {
$stmt = (new Statement)->limit(1)->offset(0); $stmt = (new Statement)->limit(1)->offset(0);
$records = $stmt->process($reader); $records = $stmt->process($reader);
@@ -273,7 +273,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$collection = $this->repository->getAttachments($this->importJob); $collection = $this->repository->getAttachments($this->importJob);
/** @var Attachment $attachment */ /** @var Attachment $attachment */
foreach ($collection as $attachment) { foreach ($collection as $attachment) {
if ($attachment->filename === 'import_file') { if ('import_file' === $attachment->filename) {
$content = $this->attachments->getAttachmentContent($attachment); $content = $this->attachments->getAttachmentContent($attachment);
break; break;
} }

View File

@@ -57,10 +57,10 @@ class ConfigureUploadHandler implements FileConfigurationInterface
// collect values: // collect values:
$importId = isset($data['csv_import_account']) ? (int)$data['csv_import_account'] : 0; $importId = isset($data['csv_import_account']) ? (int)$data['csv_import_account'] : 0;
$delimiter = (string)$data['csv_delimiter']; $delimiter = (string)$data['csv_delimiter'];
$config['has-headers'] = (int)($data['has_headers'] ?? 0.0) === 1; $config['has-headers'] = 1 === (int)($data['has_headers'] ?? 0.0);
$config['date-format'] = (string)$data['date_format']; $config['date-format'] = (string)$data['date_format'];
$config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter; $config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter;
$config['apply-rules'] = (int)($data['apply_rules'] ?? 0.0) === 1; $config['apply-rules'] = 1 === (int)($data['apply_rules'] ?? 0.0);
$config['specifics'] = $this->getSpecifics($data); $config['specifics'] = $this->getSpecifics($data);
// validate values: // validate values:
$account = $this->accountRepos->findNull($importId); $account = $this->accountRepos->findNull($importId);

View File

@@ -123,7 +123,7 @@ class NewFileJobHandler implements FileConfigurationInterface
/** @var Attachment $attachment */ /** @var Attachment $attachment */
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
// if file is configuration file, store it into the job. // if file is configuration file, store it into the job.
if ($attachment->filename === 'configuration_file') { if ('configuration_file' === $attachment->filename) {
$this->storeConfig($attachment); $this->storeConfig($attachment);
} }
} }
@@ -162,7 +162,7 @@ class NewFileJobHandler implements FileConfigurationInterface
} }
// if file is configuration file, store it into the job. // if file is configuration file, store it into the job.
if ($attachment->filename === 'configuration_file') { if ('configuration_file' === $attachment->filename) {
$this->storeConfig($attachment); $this->storeConfig($attachment);
} }
} }
@@ -179,10 +179,10 @@ class NewFileJobHandler implements FileConfigurationInterface
{ {
$content = $this->attachments->getAttachmentContent($attachment); $content = $this->attachments->getAttachmentContent($attachment);
$result = mb_detect_encoding($content, 'UTF-8', true); $result = mb_detect_encoding($content, 'UTF-8', true);
if ($result === false) { if (false === $result) {
return false; return false;
} }
if ($result !== 'ASCII' && $result !== 'UTF-8') { if ('ASCII' !== $result && 'UTF-8' !== $result) {
return false; // @codeCoverageIgnore return false; // @codeCoverageIgnore
} }
@@ -194,7 +194,6 @@ class NewFileJobHandler implements FileConfigurationInterface
* *
* @param Attachment $attachment * @param Attachment $attachment
* *
* @throws FireflyException
*/ */
private function storeConfig(Attachment $attachment): void private function storeConfig(Attachment $attachment): void
{ {

View File

@@ -98,7 +98,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
$config['account_mapping'] = $final; $config['account_mapping'] = $final;
$config['apply-rules'] = $applyRules; $config['apply-rules'] = $applyRules;
$this->repository->setConfiguration($this->importJob, $config); $this->repository->setConfiguration($this->importJob, $config);
if ($final === [0 => 0] || \count($final) === 0) { if ($final === [0 => 0] || 0 === \count($final)) {
$messages->add('count', (string)trans('import.spectre_no_mapping')); $messages->add('count', (string)trans('import.spectre_no_mapping'));
} }
@@ -116,7 +116,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
Log::debug('Now in ChooseAccountsHandler::getnextData()'); Log::debug('Now in ChooseAccountsHandler::getnextData()');
$config = $this->importJob->configuration; $config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? []; $accounts = $config['accounts'] ?? [];
if (\count($accounts) === 0) { if (0 === \count($accounts)) {
throw new FireflyException('It seems you have no accounts with this bank. The import cannot continue.'); // @codeCoverageIgnore throw new FireflyException('It seems you have no accounts with this bank. The import cannot continue.'); // @codeCoverageIgnore
} }
$converted = []; $converted = [];
@@ -128,15 +128,15 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
$login = null; $login = null;
$logins = $config['all-logins'] ?? []; $logins = $config['all-logins'] ?? [];
$selected = $config['selected-login'] ?? 0; $selected = $config['selected-login'] ?? 0;
if (\count($logins) === 0) { if (0 === \count($logins)) {
throw new FireflyException('It seems you have no configured logins in this import job. The import cannot continue.'); // @codeCoverageIgnore throw new FireflyException('It seems you have no configured logins in this import job. The import cannot continue.'); // @codeCoverageIgnore
} }
Log::debug(sprintf('Selected login to use is %d', $selected)); Log::debug(sprintf('Selected login to use is %d', $selected));
if ($selected === 0) { if (0 === $selected) {
$login = new Login($logins[0]); $login = new Login($logins[0]);
Log::debug(sprintf('Will use login %d (%s %s)', $login->getId(), $login->getProviderName(), $login->getCountryCode())); Log::debug(sprintf('Will use login %d (%s %s)', $login->getId(), $login->getProviderName(), $login->getCountryCode()));
} }
if ($selected !== 0) { if (0 !== $selected) {
foreach ($logins as $loginArray) { foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1; $loginId = $loginArray['id'] ?? -1;
if ($loginId === $selected) { if ($loginId === $selected) {

View File

@@ -82,7 +82,7 @@ class ChooseLoginHandler implements SpectreJobConfigurationInterface
Log::debug(sprintf('The selected login by the user is #%d', $selectedLogin)); Log::debug(sprintf('The selected login by the user is #%d', $selectedLogin));
// if selected login is zero, create a new one. // if selected login is zero, create a new one.
if ($selectedLogin === 0) { if (0 === $selectedLogin) {
Log::debug('Login is zero, get Spectre customer + token and store it in config.'); Log::debug('Login is zero, get Spectre customer + token and store it in config.');
$customer = $this->getCustomer($this->importJob); $customer = $this->getCustomer($this->importJob);
// get a token for the user and redirect to next stage // get a token for the user and redirect to next stage

View File

@@ -226,7 +226,6 @@ class ImportTransaction
* Calculate the amount of this transaction. * Calculate the amount of this transaction.
* *
* @return string * @return string
* @throws FireflyException
*/ */
public function calculateAmount(): string public function calculateAmount(): string
{ {
@@ -258,7 +257,7 @@ class ImportTransaction
if ($conversion === -1) { if ($conversion === -1) {
$result = app('steam')->negative($result); $result = app('steam')->negative($result);
} }
if ($conversion === 1) { if (1 === $conversion) {
$result = app('steam')->positive($result); $result = app('steam')->positive($result);
} }
Log::debug(sprintf('convertedAmount after conversion is %s', $result)); Log::debug(sprintf('convertedAmount after conversion is %s', $result));
@@ -301,7 +300,7 @@ class ImportTransaction
if ($conversion === -1) { if ($conversion === -1) {
$result = app('steam')->negative($result); $result = app('steam')->negative($result);
} }
if ($conversion === 1) { if (1 === $conversion) {
$result = app('steam')->positive($result); $result = app('steam')->positive($result);
} }
Log::debug(sprintf('Foreign amount after conversion is %s', $result)); Log::debug(sprintf('Foreign amount after conversion is %s', $result));

View File

@@ -80,7 +80,7 @@ class StageImportDataHandler
$bunqAccountId = $bunqAccount['id'] ?? 0; $bunqAccountId = $bunqAccount['id'] ?? 0;
$localId = $mapping[$bunqAccountId] ?? 0; $localId = $mapping[$bunqAccountId] ?? 0;
Log::debug(sprintf('Looping accounts, now at bunq account #%d and local account #%d', $bunqAccountId, $localId)); Log::debug(sprintf('Looping accounts, now at bunq account #%d and local account #%d', $bunqAccountId, $localId));
if ($localId !== 0 && $bunqAccountId !== 0) { if (0 !== $localId && 0 !== $bunqAccountId) {
$localAccount = $this->getLocalAccount((int)$localId); $localAccount = $this->getLocalAccount((int)$localId);
$collection[] = $this->getTransactionsFromBunq($bunqAccountId, $localAccount); $collection[] = $this->getTransactionsFromBunq($bunqAccountId, $localAccount);
} }
@@ -122,7 +122,7 @@ class StageImportDataHandler
Log::debug(sprintf('Amount is %s %s', $amount->getCurrency(), $amount->getValue())); Log::debug(sprintf('Amount is %s %s', $amount->getCurrency(), $amount->getValue()));
$expected = AccountType::EXPENSE; $expected = AccountType::EXPENSE;
if (bccomp($amount->getValue(), '0') === 1) { if (1 === bccomp($amount->getValue(), '0')) {
// amount + means that its a deposit. // amount + means that its a deposit.
$expected = AccountType::REVENUE; $expected = AccountType::REVENUE;
$type = TransactionType::DEPOSIT; $type = TransactionType::DEPOSIT;
@@ -131,7 +131,7 @@ class StageImportDataHandler
$destination = $this->convertToAccount($counterParty, $expected); $destination = $this->convertToAccount($counterParty, $expected);
// switch source and destination if necessary. // switch source and destination if necessary.
if (bccomp($amount->getValue(), '0') === 1) { if (1 === bccomp($amount->getValue(), '0')) {
Log::debug('Will make it a deposit.'); Log::debug('Will make it a deposit.');
[$source, $destination] = [$destination, $source]; [$source, $destination] = [$destination, $source];
} }
@@ -187,11 +187,12 @@ class StageImportDataHandler
* @param string $expectedType * @param string $expectedType
* *
* @return LocalAccount * @return LocalAccount
* @throws FireflyException
*/ */
private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): LocalAccount private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): LocalAccount
{ {
Log::debug('in convertToAccount()'); Log::debug('in convertToAccount()');
if ($party->getIban() !== null) { if (null !== $party->getIban()) {
// find opposing party by IBAN first. // find opposing party by IBAN first.
$result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]); $result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]);
if (null !== $result) { if (null !== $result) {

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Fake; namespace FireflyIII\Support\Import\Routine\Fake;
use FireflyIII\Exceptions\FireflyException;
use Log; use Log;
/** /**
@@ -33,7 +32,6 @@ use Log;
class StageAhoyHandler class StageAhoyHandler
{ {
/** /**
* @throws FireflyException
*/ */
public function run(): void public function run(): void
{ {

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Fake; namespace FireflyIII\Support\Import\Routine\Fake;
use FireflyIII\Exceptions\FireflyException;
use Log; use Log;
/** /**
@@ -33,7 +32,6 @@ use Log;
class StageNewHandler class StageNewHandler
{ {
/** /**
* @throws FireflyException
*/ */
public function run(): void public function run(): void
{ {

View File

@@ -205,7 +205,7 @@ class ImportableConverter
$transactionType = $this->getTransactionType($source->accountType->type, $destination->accountType->type); $transactionType = $this->getTransactionType($source->accountType->type, $destination->accountType->type);
$currency = $currency ?? $this->getCurrency($source, $destination); $currency = $currency ?? $this->getCurrency($source, $destination);
if ($transactionType === 'unknown') { if ('unknown' === $transactionType) {
$message = sprintf( $message = sprintf(
'Cannot determine transaction type. Source account is a %s, destination is a %s', $source->accountType->type, $destination->accountType->type 'Cannot determine transaction type. Source account is a %s, destination is a %s', $source->accountType->type, $destination->accountType->type
); );
@@ -282,14 +282,14 @@ class ImportableConverter
if ($destination->accountType->type === AccountType::ASSET) { if ($destination->accountType->type === AccountType::ASSET) {
// destination is asset, might have currency preference: // destination is asset, might have currency preference:
$destinationCurrencyId = (int)$this->accountRepository->getMetaValue($destination, 'currency_id'); $destinationCurrencyId = (int)$this->accountRepository->getMetaValue($destination, 'currency_id');
$currency = $destinationCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($destinationCurrencyId, []); $currency = 0 === $destinationCurrencyId ? $this->defaultCurrency : $this->currencyMapper->map($destinationCurrencyId, []);
Log::debug(sprintf('Destination is an asset account, and has currency preference %s', $currency->code)); Log::debug(sprintf('Destination is an asset account, and has currency preference %s', $currency->code));
} }
if ($source->accountType->type === AccountType::ASSET) { if ($source->accountType->type === AccountType::ASSET) {
// source is asset, might have currency preference: // source is asset, might have currency preference:
$sourceCurrencyId = (int)$this->accountRepository->getMetaValue($source, 'currency_id'); $sourceCurrencyId = (int)$this->accountRepository->getMetaValue($source, 'currency_id');
$currency = $sourceCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($sourceCurrencyId, []); $currency = 0 === $sourceCurrencyId ? $this->defaultCurrency : $this->currencyMapper->map($sourceCurrencyId, []);
Log::debug(sprintf('Source is an asset account, and has currency preference %s', $currency->code)); Log::debug(sprintf('Source is an asset account, and has currency preference %s', $currency->code));
} }
if (null === $currency) { if (null === $currency) {

View File

@@ -123,7 +123,7 @@ class LineReader
/** @var array $config */ /** @var array $config */
$config = $this->importJob->configuration; $config = $this->importJob->configuration;
Log::debug('now in getLines()'); Log::debug('now in getLines()');
$offset = isset($config['has-headers']) && $config['has-headers'] === true ? 1 : 0; $offset = isset($config['has-headers']) && true === $config['has-headers'] ? 1 : 0;
try { try {
$stmt = (new Statement)->offset($offset); $stmt = (new Statement)->offset($offset);
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
@@ -151,7 +151,7 @@ class LineReader
$collection = $this->repository->getAttachments($this->importJob); $collection = $this->repository->getAttachments($this->importJob);
/** @var Attachment $attachment */ /** @var Attachment $attachment */
foreach ($collection as $attachment) { foreach ($collection as $attachment) {
if ($attachment->filename === 'import_file') { if ('import_file' === $attachment->filename) {
$content = $this->attachments->getAttachmentContent($attachment); $content = $this->attachments->getAttachmentContent($attachment);
break; break;
} }

View File

@@ -195,7 +195,7 @@ class MappingConverger
$value = trim($value); $value = trim($value);
$originalRole = $this->roles[$columnIndex] ?? '_ignore'; $originalRole = $this->roles[$columnIndex] ?? '_ignore';
Log::debug(sprintf('Now at column #%d (%s), value "%s"', $columnIndex, $originalRole, $value)); Log::debug(sprintf('Now at column #%d (%s), value "%s"', $columnIndex, $originalRole, $value));
if ($originalRole !== '_ignore' && \strlen($value) > 0) { if ('_ignore' !== $originalRole && \strlen($value) > 0) {
// is a mapped value present? // is a mapped value present?
$mapped = $this->mapping[$columnIndex][$value] ?? 0; $mapped = $this->mapping[$columnIndex][$value] ?? 0;

View File

@@ -53,7 +53,7 @@ class OpposingAccountMapper
$expectedType = AccountType::EXPENSE; $expectedType = AccountType::EXPENSE;
$result = null; $result = null;
Log::debug(sprintf('Going to search for accounts of type %s', $expectedType)); Log::debug(sprintf('Going to search for accounts of type %s', $expectedType));
if (bccomp($amount, '0') === 1) { if (1 === bccomp($amount, '0')) {
// more than zero. // more than zero.
$expectedType = AccountType::REVENUE; $expectedType = AccountType::REVENUE;
Log::debug(sprintf('Because amount is %s, will instead search for accounts of type %s', $amount, $expectedType)); Log::debug(sprintf('Because amount is %s, will instead search for accounts of type %s', $amount, $expectedType));

View File

@@ -57,7 +57,7 @@ class StageAuthenticatedHandler
$config = $this->importJob->configuration; $config = $this->importJob->configuration;
$logins = $config['all-logins'] ?? []; $logins = $config['all-logins'] ?? [];
Log::debug(sprintf('%d logins in config', \count($logins))); Log::debug(sprintf('%d logins in config', \count($logins)));
if (\count($logins) === 0) { if (0 === \count($logins)) {
// get logins from Spectre. // get logins from Spectre.
$logins = $this->getLogins(); $logins = $this->getLogins();
$config['all-logins'] = $logins; $config['all-logins'] = $logins;

View File

@@ -60,7 +60,7 @@ class StageImportDataHandler
$config = $this->importJob->configuration; $config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? []; $accounts = $config['accounts'] ?? [];
Log::debug(sprintf('Count of accounts in array is %d', \count($accounts))); Log::debug(sprintf('Count of accounts in array is %d', \count($accounts)));
if (\count($accounts) === 0) { if (0 === \count($accounts)) {
throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore
} }
$toImport = $config['account_mapping'] ?? []; $toImport = $config['account_mapping'] ?? [];
@@ -124,14 +124,14 @@ class StageImportDataHandler
$amount = $transaction->getAmount(); $amount = $transaction->getAmount();
$source = $originalSource; $source = $originalSource;
$destination = $this->mapper->map(null, $amount, $destinationData); $destination = $this->mapper->map(null, $amount, $destinationData);
$notes = (string)trans('import.imported_from_account', ['account' => $spectreAccount->getName()]) . ' ' . "\n"; $notes = trans('import.imported_from_account', ['account' => $spectreAccount->getName()]) . ' ' . "\n";
$foreignAmount = null; $foreignAmount = null;
$foreignCurrencyCode = null; $foreignCurrencyCode = null;
$currencyCode = $transaction->getCurrencyCode(); $currencyCode = $transaction->getCurrencyCode();
$type = 'withdrawal'; $type = 'withdrawal';
// switch source and destination if amount is greater than zero. // switch source and destination if amount is greater than zero.
if (bccomp($amount, '0') === 1) { if (1 === bccomp($amount, '0')) {
[$source, $destination] = [$destination, $source]; [$source, $destination] = [$destination, $source];
$type = 'deposit'; $type = 'deposit';
} }

View File

@@ -73,7 +73,7 @@ class Navigation
// if period is 1M and diff in month is 2 and new DOM = 1, sub a day: // if period is 1M and diff in month is 2 and new DOM = 1, sub a day:
$months = ['1M', 'month', 'monthly']; $months = ['1M', 'month', 'monthly'];
$difference = $date->month - $theDate->month; $difference = $date->month - $theDate->month;
if (\in_array($repeatFreq, $months) && 2 === $difference && 1 === $date->day) { if (2 === $difference && 1 === $date->day && \in_array($repeatFreq, $months, true)) {
$date->subDay(); $date->subDay();
} }
@@ -199,14 +199,14 @@ class Navigation
if (isset($modifierMap[$repeatFreq])) { if (isset($modifierMap[$repeatFreq])) {
$currentEnd->$function($modifierMap[$repeatFreq]); $currentEnd->$function($modifierMap[$repeatFreq]);
if (\in_array($repeatFreq, $subDay)) { if (\in_array($repeatFreq, $subDay, true)) {
$currentEnd->subDay(); $currentEnd->subDay();
} }
return $currentEnd; return $currentEnd;
} }
$currentEnd->$function(); $currentEnd->$function();
if (\in_array($repeatFreq, $subDay)) { if (\in_array($repeatFreq, $subDay, true)) {
$currentEnd->subDay(); $currentEnd->subDay();
} }

View File

@@ -62,6 +62,7 @@ class Preferences
try { try {
Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete();
} catch (Exception $e) { } catch (Exception $e) {
Log::debug(sprintf('Not interesting: %s', $e->getMessage()));
// don't care. // don't care.
} }
@@ -80,7 +81,7 @@ class Preferences
/** /**
* @param string $name * @param string $name
* @param mixed $default * @param mixed $default
* *
* @return \FireflyIII\Models\Preference|null * @return \FireflyIII\Models\Preference|null
*/ */
@@ -137,7 +138,7 @@ class Preferences
try { try {
$preference->delete(); $preference->delete();
} catch (Exception $e) { } catch (Exception $e) {
Log::debug(sprintf('Could not delete preference #%d', $preference->id)); Log::debug(sprintf('Could not delete preference #%d: %s', $preference->id, $e->getMessage()));
} }
$preference = null; $preference = null;
} }

View File

@@ -101,6 +101,8 @@ class Modifier
try { try {
$compareDate = new Carbon($compare); $compareDate = new Carbon($compare);
} catch (Exception $e) { } catch (Exception $e) {
Log::debug(sprintf('Not interesting: %s', $e->getMessage()));
return false; return false;
} }
@@ -118,6 +120,8 @@ class Modifier
try { try {
$compareDate = new Carbon($compare); $compareDate = new Carbon($compare);
} catch (Exception $e) { } catch (Exception $e) {
Log::debug(sprintf('Not interesting: %s', $e->getMessage()));
return false; return false;
} }
@@ -135,6 +139,8 @@ class Modifier
try { try {
$compareDate = new Carbon($compare); $compareDate = new Carbon($compare);
} catch (Exception $e) { } catch (Exception $e) {
Log::debug(sprintf('Not interesting: %s', $e->getMessage()));
return false; return false;
} }

View File

@@ -63,7 +63,7 @@ class Search implements SearchInterface
public function getWordsAsString(): string public function getWordsAsString(): string
{ {
$string = implode(' ', $this->words); $string = implode(' ', $this->words);
if (0 === \strlen($string)) { if ('' === $string) {
return \is_string($this->originalQuery) ? $this->originalQuery : ''; return \is_string($this->originalQuery) ? $this->originalQuery : '';
} }
@@ -81,7 +81,7 @@ class Search implements SearchInterface
/** /**
* @param string $query * @param string $query
*/ */
public function parseQuery(string $query) public function parseQuery(string $query): void
{ {
$filteredQuery = $query; $filteredQuery = $query;
$this->originalQuery = $query; $this->originalQuery = $query;
@@ -171,7 +171,7 @@ class Search implements SearchInterface
/** /**
* @param int $limit * @param int $limit
*/ */
public function setLimit(int $limit) public function setLimit(int $limit): void
{ {
$this->limit = $limit; $this->limit = $limit;
} }
@@ -179,7 +179,7 @@ class Search implements SearchInterface
/** /**
* @param User $user * @param User $user
*/ */
public function setUser(User $user) public function setUser(User $user): void
{ {
$this->user = $user; $this->user = $user;
} }
@@ -242,13 +242,13 @@ class Search implements SearchInterface
/** /**
* @param string $string * @param string $string
*/ */
private function extractModifier(string $string) private function extractModifier(string $string): void
{ {
$parts = explode(':', $string); $parts = explode(':', $string);
if (2 === \count($parts) && \strlen(trim((string)$parts[0])) > 0 && \strlen(trim((string)$parts[1]))) { if (2 === \count($parts) && \strlen(trim((string)$parts[0])) > 0 && '' !== trim((string)$parts[1])) {
$type = trim((string)$parts[0]); $type = trim((string)$parts[0]);
$value = trim((string)$parts[1]); $value = trim((string)$parts[1]);
if (\in_array($type, $this->validModifiers)) { if (\in_array($type, $this->validModifiers, true)) {
// filter for valid type // filter for valid type
$this->modifiers->push(['type' => $type, 'value' => $value]); $this->modifiers->push(['type' => $type, 'value' => $value]);
} }
@@ -292,9 +292,9 @@ class Search implements SearchInterface
* *
* @return bool * @return bool
*/ */
private function strposArray(string $haystack, array $needle) private function strposArray(string $haystack, array $needle): bool
{ {
if (0 === \strlen($haystack)) { if ('' === $haystack) {
return false; return false;
} }
foreach ($needle as $what) { foreach ($needle as $what) {

View File

@@ -30,6 +30,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log;
/** /**
* Class Steam. * Class Steam.
@@ -249,7 +250,7 @@ class Steam
* @return string * @return string
* @throws \Illuminate\Contracts\Encryption\DecryptException * @throws \Illuminate\Contracts\Encryption\DecryptException
*/ */
public function decrypt(int $isEncrypted, string $value) public function decrypt(int $isEncrypted, string $value): string
{ {
if (1 === $isEncrypted) { if (1 === $isEncrypted) {
return Crypt::decrypt($value); return Crypt::decrypt($value);
@@ -366,6 +367,7 @@ class Steam
$value = Crypt::decrypt($value); $value = Crypt::decrypt($value);
} catch (DecryptException $e) { } catch (DecryptException $e) {
// do not care. // do not care.
Log::debug(sprintf('Not interesting: %s', $e->getMessage()));
} }
return $value; return $value;

View File

@@ -83,7 +83,8 @@ class AmountFormat extends Twig_Extension
{ {
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'formatAmountByAccount', 'formatAmountByAccount',
function (AccountModel $account, string $amount, bool $coloured = true): string { function (AccountModel $account, string $amount, bool $coloured = null): string {
$coloured = $coloured ?? true;
/** @var AccountRepositoryInterface $accountRepos */ /** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class); $accountRepos = app(AccountRepositoryInterface::class);
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
@@ -113,7 +114,9 @@ class AmountFormat extends Twig_Extension
{ {
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'formatAmountByCurrency', 'formatAmountByCurrency',
function (TransactionCurrency $currency, string $amount, bool $coloured = true): string { function (TransactionCurrency $currency, string $amount, bool $coloured = null): string {
$coloured = $coloured ?? true;
return app('amount')->formatAnything($currency, $amount, $coloured); return app('amount')->formatAnything($currency, $amount, $coloured);
}, },
['is_safe' => ['html']] ['is_safe' => ['html']]
@@ -129,7 +132,9 @@ class AmountFormat extends Twig_Extension
{ {
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'formatAmountBySymbol', 'formatAmountBySymbol',
function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string { function (string $amount, string $symbol, int $decimalPlaces = null, bool $coloured = null): string {
$decimalPlaces = $decimalPlaces ?? 2;
$coloured = $coloured ?? true;
$currency = new TransactionCurrency; $currency = new TransactionCurrency;
$currency->symbol = $symbol; $currency->symbol = $symbol;
$currency->decimal_places = $decimalPlaces; $currency->decimal_places = $decimalPlaces;

View File

@@ -136,12 +136,12 @@ class Transaction extends Twig_Extension
} }
// transaction has a budget // transaction has a budget
if (null !== $transaction->transaction_budget_id && $txt === '') { if (null !== $transaction->transaction_budget_id && '' === $txt) {
$name = app('steam')->tryDecrypt($transaction->transaction_budget_name); $name = app('steam')->tryDecrypt($transaction->transaction_budget_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name); $txt = sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
} }
if ($txt === '') { if ('' === $txt) {
// see if the transaction has a budget: // see if the transaction has a budget:
$budgets = $transaction->budgets()->get(); $budgets = $transaction->budgets()->get();
if (0 === $budgets->count()) { if (0 === $budgets->count()) {
@@ -174,12 +174,12 @@ class Transaction extends Twig_Extension
} }
// transaction has a category: // transaction has a category:
if (null !== $transaction->transaction_category_id && $txt === '') { if (null !== $transaction->transaction_category_id && '' === $txt) {
$name = app('steam')->tryDecrypt($transaction->transaction_category_name); $name = app('steam')->tryDecrypt($transaction->transaction_category_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name); $txt = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
} }
if ($txt === '') { if ('' === $txt) {
// see if the transaction has a category: // see if the transaction has a category:
$categories = $transaction->categories()->get(); $categories = $transaction->categories()->get();
if (0 === $categories->count()) { if (0 === $categories->count()) {
@@ -229,14 +229,14 @@ class Transaction extends Twig_Extension
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null !== $transaction->opposing_account_id) { if (null !== $transaction->opposing_account_id && bccomp($transaction->transaction_amount, '0') === -1) {
$name = $transaction->opposing_account_name; $name = $transaction->opposing_account_name;
$transactionId = (int)$transaction->opposing_account_id; $transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type; $type = $transaction->opposing_account_type;
} }
// Find the opposing account and use that one: // Find the opposing account and use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null === $transaction->opposing_account_id) { if (null === $transaction->opposing_account_id && bccomp($transaction->transaction_amount, '0') === -1) {
// if the amount is negative, find the opposing account and use that one: // if the amount is negative, find the opposing account and use that one:
$journalId = $transaction->journal_id; $journalId = $transaction->journal_id;
/** @var TransactionModel $other */ /** @var TransactionModel $other */
@@ -259,7 +259,7 @@ class Transaction extends Twig_Extension
} }
if (AccountType::CASH === $type) { if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . (string)trans('firefly.cash') . ')</span>'; $txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
return $txt; return $txt;
} }
@@ -285,7 +285,7 @@ class Transaction extends Twig_Extension
) )
); );
} }
if ($transaction->attachmentCount === null) { if (null === $transaction->attachmentCount) {
$journalId = (int)$transaction->journal_id; $journalId = (int)$transaction->journal_id;
$count = Attachment::whereNull('deleted_at') $count = Attachment::whereNull('deleted_at')
->where('attachable_type', TransactionJournal::class) ->where('attachable_type', TransactionJournal::class)
@@ -355,11 +355,11 @@ class Transaction extends Twig_Extension
public function isSplit(TransactionModel $transaction): string public function isSplit(TransactionModel $transaction): string
{ {
$res = ''; $res = '';
if ($transaction->is_split === true) { if (true === $transaction->is_split) {
$res = '<i class="fa fa-fw fa-share-alt" aria-hidden="true"></i>'; $res = '<i class="fa fa-fw fa-share-alt" aria-hidden="true"></i>';
} }
if ($transaction->is_split === null) { if (null === $transaction->is_split) {
$journalId = (int)$transaction->journal_id; $journalId = (int)$transaction->journal_id;
$count = TransactionModel::where('transaction_journal_id', $journalId)->whereNull('deleted_at')->count(); $count = TransactionModel::where('transaction_journal_id', $journalId)->whereNull('deleted_at')->count();
if ($count > 2) { if ($count > 2) {
@@ -387,13 +387,13 @@ class Transaction extends Twig_Extension
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null !== $transaction->opposing_account_id) { if (null !== $transaction->opposing_account_id && 1 === bccomp($transaction->transaction_amount, '0')) {
$name = $transaction->opposing_account_name; $name = $transaction->opposing_account_name;
$transactionId = (int)$transaction->opposing_account_id; $transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type; $type = $transaction->opposing_account_type;
} }
// Find the opposing account and use that one: // Find the opposing account and use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null === $transaction->opposing_account_id) { if (null === $transaction->opposing_account_id && 1 === bccomp($transaction->transaction_amount, '0')) {
$journalId = $transaction->journal_id; $journalId = $transaction->journal_id;
/** @var TransactionModel $other */ /** @var TransactionModel $other */
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id) $other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
@@ -410,7 +410,7 @@ class Transaction extends Twig_Extension
} }
if (AccountType::CASH === $type) { if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . (string)trans('firefly.cash') . ')</span>'; $txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
return $txt; return $txt;
} }

View File

@@ -83,7 +83,7 @@ class TransactionJournal extends Twig_Extension
if (null === $result) { if (null === $result) {
return false; return false;
} }
if (\strlen((string)$result) === 0) { if ('' === (string)$result) {
return false; return false;
} }

View File

@@ -174,7 +174,7 @@ class General extends Twig_Extension
/** /**
* @return Twig_SimpleFunction * @return Twig_SimpleFunction
*/ */
protected function formatDate() protected function formatDate(): Twig_SimpleFunction
{ {
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'formatDate', 'formatDate',
@@ -330,7 +330,7 @@ class General extends Twig_Extension
/** /**
* @return Twig_SimpleFunction * @return Twig_SimpleFunction
*/ */
protected function phpdate() protected function phpdate(): Twig_SimpleFunction
{ {
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'phpdate', 'phpdate',

View File

@@ -45,7 +45,7 @@ class Rule extends Twig_Extension
foreach ($ruleActions as $key) { foreach ($ruleActions as $key) {
$possibleActions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice'); $possibleActions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice');
} }
unset($key, $ruleActions); unset($ruleActions);
asort($possibleActions); asort($possibleActions);
return $possibleActions; return $possibleActions;
@@ -84,7 +84,7 @@ class Rule extends Twig_Extension
$possibleTriggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice'); $possibleTriggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice');
} }
} }
unset($key, $ruleTriggers); unset($ruleTriggers);
asort($possibleTriggers); asort($possibleTriggers);
return $possibleTriggers; return $possibleTriggers;