Code cleanup

This commit is contained in:
James Cole
2018-04-28 06:23:13 +02:00
parent 6f0e1c79ac
commit 13b78bdc20
218 changed files with 621 additions and 681 deletions

View File

@@ -262,8 +262,6 @@ class AccountRepository implements AccountRepositoryInterface
* @param array $data
*
* @return Account
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function store(array $data): Account
{
@@ -279,8 +277,6 @@ class AccountRepository implements AccountRepositoryInterface
* @param array $data
*
* @return Account
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function update(Account $account, array $data): Account
{

View File

@@ -70,7 +70,7 @@ trait FindAccountsTrait
->where('account_meta.name', 'accountNumber')
->where('account_meta.data', json_encode($number));
if (count($types) > 0) {
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@@ -95,7 +95,7 @@ trait FindAccountsTrait
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (count($types) > 0) {
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@@ -121,7 +121,7 @@ trait FindAccountsTrait
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (count($types) > 0) {
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@@ -147,7 +147,7 @@ trait FindAccountsTrait
{
$query = $this->user->accounts();
if (count($types) > 0) {
if (\count($types) > 0) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@@ -177,7 +177,7 @@ trait FindAccountsTrait
/** @var Collection $result */
$query = $this->user->accounts();
if (count($accountIds) > 0) {
if (\count($accountIds) > 0) {
$query->whereIn('accounts.id', $accountIds);
}
@@ -200,7 +200,7 @@ trait FindAccountsTrait
{
/** @var Collection $result */
$query = $this->user->accounts();
if (count($types) > 0) {
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
@@ -227,7 +227,7 @@ trait FindAccountsTrait
$query->where('name', 'accountRole');
}]
);
if (count($types) > 0) {
if (\count($types) > 0) {
$query->accountTypeIn($types);
}
$query->where('active', 1);

View File

@@ -44,8 +44,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
* @param Attachment $attachment
*
* @return bool
*
* @throws \Exception
*/
public function destroy(Attachment $attachment): bool
{
@@ -146,7 +145,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
if ($disk->exists($file)) {
$content = Crypt::decrypt($disk->get($file));
}
if (is_bool($content)) {
if (\is_bool($content)) {
Log::error(sprintf('Attachment #%d may be corrupted: the content could not be decrypted.', $attachment->id));
return '';
@@ -203,7 +202,7 @@ class AttachmentRepository implements AttachmentRepositoryInterface
*/
public function updateNote(Attachment $attachment, string $note): bool
{
if (0 === strlen($note)) {
if (0 === \strlen($note)) {
$dbNote = $attachment->notes()->first();
if (null !== $dbNote) {
$dbNote->delete();

View File

@@ -555,37 +555,4 @@ class BillRepository implements BillRepositoryInterface
return $service->update($bill, $data);
}
/**
* @param float $amount
* @param float $min
* @param float $max
*
* @return bool
*/
protected function doAmountMatch($amount, $min, $max): bool
{
return $amount >= $min && $amount <= $max;
}
/**
* @param array $matches
* @param $description
*
* @return bool
*/
protected function doWordMatch(array $matches, $description): bool
{
$wordMatch = false;
$count = 0;
foreach ($matches as $word) {
if (!(false === strpos($description, strtolower($word)))) {
++$count;
}
}
if ($count >= count($matches)) {
$wordMatch = true;
}
return $wordMatch;
}
}

View File

@@ -156,8 +156,7 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Budget $budget
*
* @return bool
*
* @throws \Exception
*/
public function destroy(Budget $budget): bool
{
@@ -569,7 +568,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$set = $collector->getJournals();
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -604,7 +603,7 @@ class BudgetRepository implements BudgetRepositoryInterface
}
);
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -648,8 +647,7 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param string $amount
*
* @return BudgetLimit
*
* @throws \Exception
*/
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit
{

View File

@@ -75,7 +75,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($accounts)->setCategories($categories);
$set = $collector->getJournals();
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -400,7 +400,7 @@ class CategoryRepository implements CategoryRepositoryInterface
$set = $collector->getJournals();
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -435,7 +435,7 @@ class CategoryRepository implements CategoryRepositoryInterface
}
);
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**

View File

@@ -53,8 +53,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/**
* @return bool
*
* @throws \Exception
*/
public function cleanup(): bool
{
@@ -67,7 +66,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/** @var ExportJob $entry */
foreach ($set as $entry) {
$key = $entry->key;
$len = strlen($key);
$len = \strlen($key);
$files = scandir(storage_path('export'), SCANDIR_SORT_NONE);
/** @var string $file */
foreach ($files as $file) {

View File

@@ -171,7 +171,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
public function getConfiguration(ImportJob $job): array
{
$config = $job->configuration;
if (is_array($config)) {
if (\is_array($config)) {
return $config;
}
@@ -188,7 +188,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
public function getExtendedStatus(ImportJob $job): array
{
$status = $job->extended_status;
if (is_array($status)) {
if (\is_array($status)) {
return $status;
}
@@ -226,7 +226,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
$configRaw = $configFileObject->fread($configFileObject->getSize());
$configuration = json_decode($configRaw, true);
Log::debug(sprintf('Raw configuration is %s', $configRaw));
if (null !== $configuration && is_array($configuration)) {
if (null !== $configuration && \is_array($configuration)) {
Log::debug('Found configuration', $configuration);
$this->setConfiguration($job, $configuration);
}

View File

@@ -467,7 +467,7 @@ class JournalRepository implements JournalRepositoryInterface
$value = $entry->data;
// return when array:
if (is_array($value)) {
if (\is_array($value)) {
$return = implode(',', $value);
$cache->store($return);
@@ -661,7 +661,6 @@ class JournalRepository implements JournalRepositoryInterface
]
);
return;
}
/**
@@ -683,7 +682,6 @@ class JournalRepository implements JournalRepositoryInterface
]
);
return;
}
/**

View File

@@ -54,8 +54,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
* @param LinkType $moveTo
*
* @return bool
*
* @throws \Exception
*/
public function destroy(LinkType $linkType, LinkType $moveTo): bool
{
@@ -71,8 +70,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
* @param TransactionJournalLink $link
*
* @return bool
*
* @throws \Exception
*/
public function destroyLink(TransactionJournalLink $link): bool
{
@@ -199,7 +197,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$link->save();
// make note in noteable:
if (strlen($information['notes']) > 0) {
if (\strlen($information['notes']) > 0) {
$dbNote = $link->notes()->first();
if (null === $dbNote) {
$dbNote = new Note();

View File

@@ -143,8 +143,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
* @param PiggyBank $piggyBank
*
* @return bool
*
* @throws \Exception
*/
public function destroy(PiggyBank $piggyBank): bool
{
@@ -238,7 +237,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
// if piggy account matches source account, the amount is positive
if (in_array($piggyBank->account_id, $sources)) {
if (\in_array($piggyBank->account_id, $sources)) {
$amount = bcmul($amount, '-1');
Log::debug(sprintf('Account #%d is the source, so will remove amount from piggy bank.', $piggyBank->account_id));
}
@@ -456,7 +455,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/
private function updateNote(PiggyBank $piggyBank, string $note): bool
{
if (0 === strlen($note)) {
if (0 === \strlen($note)) {
$dbNote = $piggyBank->notes()->first();
if (null !== $dbNote) {
$dbNote->delete();

View File

@@ -49,7 +49,7 @@ class RuleRepository implements RuleRepositoryInterface
* @param Rule $rule
*
* @return bool
*
* @throws \Exception
*/
public function destroy(Rule $rule): bool
{
@@ -261,7 +261,7 @@ class RuleRepository implements RuleRepositoryInterface
$rule->strict = $data['strict'] ?? false;
$rule->stop_processing = 1 === (int)$data['stop_processing'];
$rule->title = $data['title'];
$rule->description = strlen($data['description']) > 0 ? $data['description'] : null;
$rule->description = \strlen($data['description']) > 0 ? $data['description'] : null;
$rule->save();

View File

@@ -49,7 +49,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
* @param RuleGroup|null $moveTo
*
* @return bool
*
* @throws \Exception
*/
public function destroy(RuleGroup $ruleGroup, ?RuleGroup $moveTo): bool
{

View File

@@ -75,8 +75,7 @@ class TagRepository implements TagRepositoryInterface
* @param Tag $tag
*
* @return bool
*
* @throws \Exception
*/
public function destroy(Tag $tag): bool
{
@@ -100,7 +99,7 @@ class TagRepository implements TagRepositoryInterface
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
$set = $collector->getJournals();
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -223,7 +222,7 @@ class TagRepository implements TagRepositoryInterface
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
$set = $collector->getJournals();
return strval($set->sum('transaction_amount'));
return (string)$set->sum('transaction_amount');
}
/**
@@ -354,7 +353,7 @@ class TagRepository implements TagRepositoryInterface
/** @var Tag $tag */
foreach ($result as $tag) {
$tagsWithAmounts[$tag->id] = (string)$tag->amount_sum;
$amount = strlen($tagsWithAmounts[$tag->id]) ? $tagsWithAmounts[$tag->id] : '0';
$amount = \strlen($tagsWithAmounts[$tag->id]) ? $tagsWithAmounts[$tag->id] : '0';
if (null === $min) {
$min = $amount;
}

View File

@@ -144,8 +144,7 @@ class UserRepository implements UserRepositoryInterface
* @param User $user
*
* @return bool
*
* @throws \Exception
*/
public function destroy(User $user): bool
{
@@ -294,7 +293,6 @@ class UserRepository implements UserRepositoryInterface
$user->blocked_code = '';
$user->save();
return;
}
/**