mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Code clean up.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Collector;
|
||||
@@ -51,7 +50,6 @@ use Steam;
|
||||
*
|
||||
* Class JournalCollector
|
||||
*
|
||||
* @package FireflyIII\Helpers\Collector
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
@@ -59,10 +57,9 @@ use Steam;
|
||||
*/
|
||||
class JournalCollector implements JournalCollectorInterface
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
private $accountIds = [];
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
private $count = 0;
|
||||
/** @var array */
|
||||
private $fields
|
||||
@@ -101,22 +98,21 @@ class JournalCollector implements JournalCollectorInterface
|
||||
'accounts.encrypted as account_encrypted',
|
||||
'accounts.iban as account_iban',
|
||||
'account_types.type as account_type',
|
||||
|
||||
];
|
||||
/** @var array */
|
||||
private $filters = [InternalTransferFilter::class];
|
||||
|
||||
/** @var bool */
|
||||
/** @var bool */
|
||||
private $joinedBudget = false;
|
||||
/** @var bool */
|
||||
/** @var bool */
|
||||
private $joinedCategory = false;
|
||||
/** @var bool */
|
||||
private $joinedOpposing = false;
|
||||
/** @var bool */
|
||||
private $joinedTag = false;
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
private $limit;
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
private $offset;
|
||||
/** @var int */
|
||||
private $page = 1;
|
||||
@@ -218,11 +214,12 @@ class JournalCollector implements JournalCollectorInterface
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
if ($this->run === true) {
|
||||
if (true === $this->run) {
|
||||
throw new FireflyException('Cannot count after run in JournalCollector.');
|
||||
}
|
||||
|
||||
@@ -258,7 +255,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$transaction->date = new Carbon($transaction->date);
|
||||
$transaction->description = Steam::decrypt(intval($transaction->encrypted), $transaction->description);
|
||||
|
||||
if (!is_null($transaction->bill_name)) {
|
||||
if (null !== $transaction->bill_name) {
|
||||
$transaction->bill_name = Steam::decrypt(intval($transaction->bill_name_encrypted), $transaction->bill_name);
|
||||
}
|
||||
$transaction->opposing_account_name = app('steam')->tryDecrypt($transaction->opposing_account_name);
|
||||
@@ -272,11 +269,12 @@ class JournalCollector implements JournalCollectorInterface
|
||||
|
||||
/**
|
||||
* @return LengthAwarePaginator
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getPaginatedJournals(): LengthAwarePaginator
|
||||
{
|
||||
if ($this->run === true) {
|
||||
if (true === $this->run) {
|
||||
throw new FireflyException('Cannot getPaginatedJournals after run in JournalCollector.');
|
||||
}
|
||||
$this->count();
|
||||
@@ -294,7 +292,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
public function removeFilter(string $filter): JournalCollectorInterface
|
||||
{
|
||||
$key = array_search($filter, $this->filters, true);
|
||||
if (!($key === false)) {
|
||||
if (!(false === $key)) {
|
||||
Log::debug(sprintf('Removed filter %s', $filter));
|
||||
unset($this->filters[$key]);
|
||||
}
|
||||
@@ -320,7 +318,6 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$this->addFilter(TransferFilter::class);
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -416,7 +413,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
public function setBudgets(Collection $budgets): JournalCollectorInterface
|
||||
{
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
if (count($budgetIds) === 0) {
|
||||
if (0 === count($budgetIds)) {
|
||||
return $this;
|
||||
}
|
||||
$this->joinBudgetTables();
|
||||
@@ -440,7 +437,7 @@ class JournalCollector implements JournalCollectorInterface
|
||||
public function setCategories(Collection $categories): JournalCollectorInterface
|
||||
{
|
||||
$categoryIds = $categories->pluck('id')->toArray();
|
||||
if (count($categoryIds) === 0) {
|
||||
if (0 === count($categoryIds)) {
|
||||
return $this;
|
||||
}
|
||||
$this->joinCategoryTables();
|
||||
@@ -514,11 +511,11 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$this->page = $page;
|
||||
|
||||
if ($page > 0) {
|
||||
$page--;
|
||||
--$page;
|
||||
}
|
||||
Log::debug(sprintf('Page is %d', $page));
|
||||
|
||||
if (!is_null($this->limit)) {
|
||||
if (null !== $this->limit) {
|
||||
$offset = ($this->limit * $page);
|
||||
$this->offset = $offset;
|
||||
$this->query->skip($offset);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Collector;
|
||||
@@ -32,9 +31,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface JournalCollectorInterface
|
||||
*
|
||||
* @package FireflyIII\Helpers\Collector
|
||||
* Interface JournalCollectorInterface.
|
||||
*/
|
||||
interface JournalCollectorInterface
|
||||
{
|
||||
@@ -43,28 +40,28 @@ interface JournalCollectorInterface
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function addFilter(string $filter): JournalCollectorInterface;
|
||||
public function addFilter(string $filter): self;
|
||||
|
||||
/**
|
||||
* @param string $amount
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function amountIs(string $amount): JournalCollectorInterface;
|
||||
public function amountIs(string $amount): self;
|
||||
|
||||
/**
|
||||
* @param string $amount
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function amountLess(string $amount): JournalCollectorInterface;
|
||||
public function amountLess(string $amount): self;
|
||||
|
||||
/**
|
||||
* @param string $amount
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function amountMore(string $amount): JournalCollectorInterface;
|
||||
public function amountMore(string $amount): self;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
@@ -86,89 +83,89 @@ interface JournalCollectorInterface
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function removeFilter(string $filter): JournalCollectorInterface;
|
||||
public function removeFilter(string $filter): self;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setAccounts(Collection $accounts): JournalCollectorInterface;
|
||||
public function setAccounts(Collection $accounts): self;
|
||||
|
||||
/**
|
||||
* @param Carbon $after
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setAfter(Carbon $after): JournalCollectorInterface;
|
||||
public function setAfter(Carbon $after): self;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setAllAssetAccounts(): JournalCollectorInterface;
|
||||
public function setAllAssetAccounts(): self;
|
||||
|
||||
/**
|
||||
* @param Carbon $before
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBefore(Carbon $before): JournalCollectorInterface;
|
||||
public function setBefore(Carbon $before): self;
|
||||
|
||||
/**
|
||||
* @param Collection $bills
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBills(Collection $bills): JournalCollectorInterface;
|
||||
public function setBills(Collection $bills): self;
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBudget(Budget $budget): JournalCollectorInterface;
|
||||
public function setBudget(Budget $budget): self;
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setBudgets(Collection $budgets): JournalCollectorInterface;
|
||||
public function setBudgets(Collection $budgets): self;
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setCategories(Collection $categories): JournalCollectorInterface;
|
||||
public function setCategories(Collection $categories): self;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setCategory(Category $category): JournalCollectorInterface;
|
||||
public function setCategory(Category $category): self;
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setLimit(int $limit): JournalCollectorInterface;
|
||||
public function setLimit(int $limit): self;
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setOffset(int $offset): JournalCollectorInterface;
|
||||
public function setOffset(int $offset): self;
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setPage(int $page): JournalCollectorInterface;
|
||||
public function setPage(int $page): self;
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
@@ -176,28 +173,28 @@ interface JournalCollectorInterface
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setRange(Carbon $start, Carbon $end): JournalCollectorInterface;
|
||||
public function setRange(Carbon $start, Carbon $end): self;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setTag(Tag $tag): JournalCollectorInterface;
|
||||
public function setTag(Tag $tag): self;
|
||||
|
||||
/**
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): JournalCollectorInterface;
|
||||
public function setTags(Collection $tags): self;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): JournalCollectorInterface;
|
||||
public function setTypes(array $types): self;
|
||||
|
||||
public function setUser(User $user);
|
||||
|
||||
@@ -209,25 +206,25 @@ interface JournalCollectorInterface
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withBudgetInformation(): JournalCollectorInterface;
|
||||
public function withBudgetInformation(): self;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withCategoryInformation(): JournalCollectorInterface;
|
||||
public function withCategoryInformation(): self;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withOpposingAccount(): JournalCollectorInterface;
|
||||
public function withOpposingAccount(): self;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): JournalCollectorInterface;
|
||||
public function withoutBudget(): self;
|
||||
|
||||
/**
|
||||
* @return JournalCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): JournalCollectorInterface;
|
||||
public function withoutCategory(): self;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user