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

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

View File

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

View File

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

View File

@@ -51,7 +51,7 @@ class Date implements BinderInterface
try {
$date = new Carbon($value);
} 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;
}

View File

@@ -27,30 +27,14 @@ use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Routing\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ImportProvider.
*/
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
*/
@@ -99,4 +83,20 @@ class ImportProvider implements BinderInterface
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 = array_unique($list);
if (\count($list) === 0) {
if (0 === \count($list)) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}

View File

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

View File

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