mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test coverage, remove dead code.
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ManageLoginsHandler.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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\Support\Import\Routine\Spectre;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
|
||||
use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
|
||||
use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ManageLoginsHandler
|
||||
*/
|
||||
class ManageLoginsHandler
|
||||
{
|
||||
|
||||
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportDataHandler.php
|
||||
* StageImportDataHandler.phpr.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
@@ -37,11 +37,11 @@ use FireflyIII\Support\Import\Routine\File\OpposingAccountMapper;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ImportDataHandler
|
||||
* Class StageImportDataHandler
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Routine\Spectre
|
||||
*/
|
||||
class ImportDataHandler
|
||||
class StageImportDataHandler
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $accountRepository;
|
||||
@@ -57,7 +57,7 @@ class ImportDataHandler
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug('Now in ImportDataHandler::run()');
|
||||
Log::debug('Now in StageImportDataHandler::run()');
|
||||
$config = $this->importJob->configuration;
|
||||
$accounts = $config['accounts'] ?? [];
|
||||
Log::debug(sprintf('Count of accounts in array is %d', \count($accounts)));
|
||||
@@ -103,7 +103,7 @@ class ImportDataHandler
|
||||
{
|
||||
$array = [];
|
||||
$total = \count($transactions);
|
||||
Log::debug(sprintf('Now in ImportDataHandler::convertToArray() with count %d', \count($transactions)));
|
||||
Log::debug(sprintf('Now in StageImportDataHandler::convertToArray() with count %d', \count($transactions)));
|
||||
/** @var SpectreTransaction $transaction */
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
Log::debug(sprintf('Now creating array for transaction %d of %d', $index + 1, $total));
|
@@ -26,11 +26,9 @@ namespace FireflyIII\Support\Import\Routine\Spectre;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Services\Spectre\Object\Customer;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use FireflyIII\Services\Spectre\Request\ListCustomersRequest;
|
||||
use FireflyIII\Services\Spectre\Request\ListLoginsRequest;
|
||||
use FireflyIII\Services\Spectre\Request\NewCustomerRequest;
|
||||
use FireflyIII\Support\Import\Information\GetSpectreCustomerTrait;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -40,13 +38,24 @@ use Log;
|
||||
*/
|
||||
class StageNewHandler
|
||||
{
|
||||
use GetSpectreCustomerTrait;
|
||||
/** @var int */
|
||||
public $countLogins = 0;
|
||||
private $countLogins = 0;
|
||||
/** @var ImportJob */
|
||||
private $importJob;
|
||||
/** @var ImportJobRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return int
|
||||
*/
|
||||
public function getCountLogins(): int
|
||||
{
|
||||
return $this->countLogins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tasks for this stage:
|
||||
*
|
||||
@@ -59,11 +68,13 @@ class StageNewHandler
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug('Now in ManageLoginsHandler::run()');
|
||||
$customer = $this->getCustomer();
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$customer = $this->getCustomer($this->importJob);
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
|
||||
Log::debug('Going to get a list of logins.');
|
||||
$request = new ListLoginsRequest($this->importJob->user);
|
||||
/** @var ListLoginsRequest $request */
|
||||
$request = app(ListLoginsRequest::class);
|
||||
$request->setUser($this->importJob->user);
|
||||
$request->setCustomer($customer);
|
||||
$request->call();
|
||||
|
||||
@@ -94,49 +105,4 @@ class StageNewHandler
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($importJob->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getCustomer(): Customer
|
||||
{
|
||||
Log::debug('Now in manageLoginsHandler::getCustomer()');
|
||||
$customer = $this->getExistingCustomer();
|
||||
if (null === $customer) {
|
||||
Log::debug('The customer is NULL, will fire a newCustomerRequest.');
|
||||
$newCustomerRequest = new NewCustomerRequest($this->importJob->user);
|
||||
$customer = $newCustomerRequest->getCustomer();
|
||||
|
||||
}
|
||||
Log::debug('The customer is not null.');
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer|null
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getExistingCustomer(): ?Customer
|
||||
{
|
||||
Log::debug('Now in manageLoginsHandler::getExistingCustomer()');
|
||||
$customer = null;
|
||||
$getCustomerRequest = new ListCustomersRequest($this->importJob->user);
|
||||
$getCustomerRequest->call();
|
||||
$customers = $getCustomerRequest->getCustomers();
|
||||
|
||||
Log::debug(sprintf('Found %d customer(s)', \count($customers)));
|
||||
/** @var Customer $current */
|
||||
foreach ($customers as $current) {
|
||||
if ('default_ff3_customer' === $current->getIdentifier()) {
|
||||
$customer = $current;
|
||||
Log::debug('Found the correct customer.');
|
||||
break;
|
||||
}
|
||||
Log::debug(sprintf('Skip customer with name "%s"', $current->getIdentifier()));
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user