mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-01 03:29:33 +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\Support\Import\Configuration;
|
||||
@@ -26,9 +25,7 @@ namespace FireflyIII\Support\Import\Configuration;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
|
||||
/**
|
||||
* Class ConfigurationInterface
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Configuration
|
||||
* Class ConfigurationInterface.
|
||||
*/
|
||||
interface ConfigurationInterface
|
||||
{
|
||||
|
||||
@@ -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\Support\Import\Configuration\Csv;
|
||||
@@ -31,9 +30,7 @@ use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class CsvInitial
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Configuration
|
||||
* Class CsvInitial.
|
||||
*/
|
||||
class Initial implements ConfigurationInterface
|
||||
{
|
||||
@@ -109,23 +106,22 @@ class Initial implements ConfigurationInterface
|
||||
$importId = $data['csv_import_account'] ?? 0;
|
||||
$account = $repository->find(intval($importId));
|
||||
|
||||
$hasHeaders = isset($data['has_headers']) && intval($data['has_headers']) === 1 ? true : false;
|
||||
$hasHeaders = isset($data['has_headers']) && 1 === intval($data['has_headers']) ? true : false;
|
||||
$config = $this->job->configuration;
|
||||
$config['initial-config-complete'] = true;
|
||||
$config['has-headers'] = $hasHeaders;
|
||||
$config['date-format'] = $data['date_format'];
|
||||
$config['delimiter'] = $data['csv_delimiter'];
|
||||
$config['delimiter'] = $config['delimiter'] === 'tab' ? "\t" : $config['delimiter'];
|
||||
$config['delimiter'] = 'tab' === $config['delimiter'] ? "\t" : $config['delimiter'];
|
||||
|
||||
Log::debug('Entered import account.', ['id' => $importId]);
|
||||
|
||||
|
||||
if (!is_null($account->id)) {
|
||||
if (null !== $account->id) {
|
||||
Log::debug('Found account.', ['id' => $account->id, 'name' => $account->name]);
|
||||
$config['import-account'] = $account->id;
|
||||
}
|
||||
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
Log::error('Could not find anything for csv_import_account.', ['id' => $importId]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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\Support\Import\Configuration\Csv;
|
||||
@@ -33,9 +32,7 @@ use League\Csv\Reader;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Mapping
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Configuration\Csv
|
||||
* Class Mapping.
|
||||
*/
|
||||
class Map implements ConfigurationInterface
|
||||
{
|
||||
@@ -43,13 +40,14 @@ class Map implements ConfigurationInterface
|
||||
private $configuration = [];
|
||||
/** @var array that holds each column to be mapped by the user */
|
||||
private $data = [];
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
/** @var array */
|
||||
private $validSpecifics = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getData(): array
|
||||
@@ -79,10 +77,9 @@ class Map implements ConfigurationInterface
|
||||
}
|
||||
$value = $row[$index];
|
||||
if (strlen($value) > 0) {
|
||||
|
||||
// we can do some preprocessing here,
|
||||
// which is exclusively to fix the tags:
|
||||
if (!is_null($this->data[$index]['preProcessMap']) && strlen($this->data[$index]['preProcessMap']) > 0) {
|
||||
if (null !== $this->data[$index]['preProcessMap'] && strlen($this->data[$index]['preProcessMap']) > 0) {
|
||||
/** @var PreProcessorInterface $preProcessor */
|
||||
$preProcessor = app($this->data[$index]['preProcessMap']);
|
||||
$result = $preProcessor->run($value);
|
||||
@@ -92,7 +89,6 @@ class Map implements ConfigurationInterface
|
||||
Log::debug($rowIndex . ':' . $index . 'Value after preprocessor', ['value-new' => $result]);
|
||||
Log::debug($rowIndex . ':' . $index . 'Value after joining', ['value-complete' => $this->data[$index]['values']]);
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -154,7 +150,7 @@ class Map implements ConfigurationInterface
|
||||
$config['column-mapping-config'][$index] = [];
|
||||
foreach ($data as $value => $mapId) {
|
||||
$mapId = intval($mapId);
|
||||
if ($mapId !== 0) {
|
||||
if (0 !== $mapId) {
|
||||
$config['column-mapping-config'][$index][$value] = intval($mapId);
|
||||
}
|
||||
}
|
||||
@@ -192,15 +188,13 @@ class Map implements ConfigurationInterface
|
||||
$config = $this->job->configuration;
|
||||
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int
|
||||
* @var bool $mustBeMapped
|
||||
*/
|
||||
foreach ($config['column-do-mapping'] as $index => $mustBeMapped) {
|
||||
$column = $this->validateColumnName($config['column-roles'][$index] ?? '_ignore');
|
||||
$shouldMap = $this->shouldMapColumn($column, $mustBeMapped);
|
||||
if ($shouldMap) {
|
||||
|
||||
|
||||
// create configuration entry for this specific column and add column to $this->data array for later processing.
|
||||
$this->data[$index] = [
|
||||
'name' => $column,
|
||||
@@ -226,7 +220,7 @@ class Map implements ConfigurationInterface
|
||||
$hasPreProcess = config('csv.import_roles.' . $column . '.pre-process-map');
|
||||
$preProcessClass = config('csv.import_roles.' . $column . '.pre-process-mapper');
|
||||
|
||||
if (!is_null($hasPreProcess) && $hasPreProcess === true && !is_null($preProcessClass)) {
|
||||
if (null !== $hasPreProcess && true === $hasPreProcess && null !== $preProcessClass) {
|
||||
$name = sprintf('\\FireflyIII\\Import\\MapperPreProcess\\%s', $preProcessClass);
|
||||
}
|
||||
|
||||
@@ -237,6 +231,7 @@ class Map implements ConfigurationInterface
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function runSpecifics(array $row): array
|
||||
@@ -269,13 +264,14 @@ class Map implements ConfigurationInterface
|
||||
{
|
||||
$canBeMapped = config('csv.import_roles.' . $column . '.mappable');
|
||||
|
||||
return ($canBeMapped && $mustBeMapped);
|
||||
return $canBeMapped && $mustBeMapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function validateColumnName(string $column): string
|
||||
|
||||
@@ -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\Support\Import\Configuration\Csv;
|
||||
@@ -30,14 +29,12 @@ use League\Csv\Reader;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Roles
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Configuration\Csv
|
||||
* Class Roles.
|
||||
*/
|
||||
class Roles implements ConfigurationInterface
|
||||
{
|
||||
private $data = [];
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
|
||||
/** @var string */
|
||||
@@ -75,7 +72,7 @@ class Roles implements ConfigurationInterface
|
||||
$count = count($row);
|
||||
$this->data['total'] = $count > $this->data['total'] ? $count : $this->data['total'];
|
||||
$this->processRow($row);
|
||||
$start++;
|
||||
++$start;
|
||||
}
|
||||
|
||||
$this->updateColumCount();
|
||||
@@ -118,7 +115,7 @@ class Roles implements ConfigurationInterface
|
||||
Log::debug('Now in storeConfiguration of Roles.');
|
||||
$config = $this->job->configuration;
|
||||
$count = $config['column-count'];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$role = $data['role'][$i] ?? '_ignore';
|
||||
$mapping = isset($data['map'][$i]) && $data['map'][$i] === '1' ? true : false;
|
||||
$config['column-roles'][$i] = $role;
|
||||
@@ -126,7 +123,6 @@ class Roles implements ConfigurationInterface
|
||||
Log::debug(sprintf('Column %d has been given role %s', $i, $role));
|
||||
}
|
||||
|
||||
|
||||
$this->job->configuration = $config;
|
||||
$this->job->save();
|
||||
|
||||
@@ -134,7 +130,6 @@ class Roles implements ConfigurationInterface
|
||||
$this->setRolesComplete();
|
||||
$this->isMappingNecessary();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -158,11 +153,11 @@ class Roles implements ConfigurationInterface
|
||||
{
|
||||
$config = $this->job->configuration;
|
||||
$count = $config['column-count'];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$role = $config['column-roles'][$i] ?? '_ignore';
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
|
||||
if ($role === '_ignore' && $mapping === true) {
|
||||
if ('_ignore' === $role && true === $mapping) {
|
||||
$mapping = false;
|
||||
Log::debug(sprintf('Column %d has type %s so it cannot be mapped.', $i, $role));
|
||||
}
|
||||
@@ -183,14 +178,14 @@ class Roles implements ConfigurationInterface
|
||||
$config = $this->job->configuration;
|
||||
$count = $config['column-count'];
|
||||
$toBeMapped = 0;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
if ($mapping === true) {
|
||||
$toBeMapped++;
|
||||
if (true === $mapping) {
|
||||
++$toBeMapped;
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Found %d columns that need mapping.', $toBeMapped));
|
||||
if ($toBeMapped === 0) {
|
||||
if (0 === $toBeMapped) {
|
||||
// skip setting of map, because none need to be mapped:
|
||||
$config['column-mapping-complete'] = true;
|
||||
$this->job->configuration = $config;
|
||||
@@ -201,7 +196,7 @@ class Roles implements ConfigurationInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* make unique example data
|
||||
* make unique example data.
|
||||
*/
|
||||
private function makeExamplesUnique(): bool
|
||||
{
|
||||
@@ -258,12 +253,12 @@ class Roles implements ConfigurationInterface
|
||||
$count = $config['column-count'];
|
||||
$assigned = 0;
|
||||
$hasAmount = false;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$role = $config['column-roles'][$i] ?? '_ignore';
|
||||
if ($role !== '_ignore') {
|
||||
$assigned++;
|
||||
if ('_ignore' !== $role) {
|
||||
++$assigned;
|
||||
}
|
||||
if ($role === 'amount') {
|
||||
if ('amount' === $role) {
|
||||
$hasAmount = true;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +268,7 @@ class Roles implements ConfigurationInterface
|
||||
$this->job->save();
|
||||
$this->warning = '';
|
||||
}
|
||||
if ($assigned === 0 || !$hasAmount) {
|
||||
if (0 === $assigned || !$hasAmount) {
|
||||
$this->warning = strval(trans('csv.roles_warning'));
|
||||
}
|
||||
|
||||
|
||||
@@ -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\Support\Import\Information;
|
||||
@@ -38,14 +37,11 @@ use Log;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class BunqInformation
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Information
|
||||
* Class BunqInformation.
|
||||
*/
|
||||
class BunqInformation implements InformationInterface
|
||||
{
|
||||
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -92,7 +88,7 @@ class BunqInformation implements InformationInterface
|
||||
];
|
||||
/** @var Alias $alias */
|
||||
foreach ($account->getAliases() as $alias) {
|
||||
if ($alias->getType() === 'IBAN') {
|
||||
if ('IBAN' === $alias->getType()) {
|
||||
$current['number'] = $alias->getValue();
|
||||
}
|
||||
}
|
||||
@@ -161,6 +157,7 @@ class BunqInformation implements InformationInterface
|
||||
* @param SessionToken $sessionToken
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getUserInformation(SessionToken $sessionToken): int
|
||||
|
||||
@@ -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\Support\Import\Information;
|
||||
@@ -26,13 +25,10 @@ namespace FireflyIII\Support\Import\Information;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
* Interface InformationInterface
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Information
|
||||
* Interface InformationInterface.
|
||||
*/
|
||||
interface InformationInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a collection of accounts. Preferrably, these follow a uniform Firefly III format so they can be managed over banks.
|
||||
*
|
||||
|
||||
@@ -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\Support\Import\Prerequisites;
|
||||
@@ -41,12 +40,10 @@ use Requests_Exception;
|
||||
|
||||
/**
|
||||
* This class contains all the routines necessary to connect to Bunq.
|
||||
*
|
||||
* @package FireflyIII\Support\Import\Prerequisites
|
||||
*/
|
||||
class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -80,7 +77,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
$apiKey = Preferences::getForUser($this->user, 'bunq_api_key', false);
|
||||
|
||||
return ($apiKey->data === false || is_null($apiKey->data));
|
||||
return false === $apiKey->data || null === $apiKey->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,6 +153,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
* to try and detect the server ID for this firefly instance.
|
||||
*
|
||||
* @return DeviceServerId
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getExistingDevice(): DeviceServerId
|
||||
@@ -187,7 +185,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
Log::debug('Get installation token.');
|
||||
$token = Preferences::getForUser($this->user, 'bunq_installation_token', null);
|
||||
if (!is_null($token)) {
|
||||
if (null !== $token) {
|
||||
return $token->data;
|
||||
}
|
||||
Log::debug('Have no token, request one.');
|
||||
@@ -219,7 +217,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
Log::debug('get private key');
|
||||
$preference = Preferences::getForUser($this->user, 'bunq_private_key', null);
|
||||
if (is_null($preference)) {
|
||||
if (null === $preference) {
|
||||
Log::debug('private key is null');
|
||||
// create key pair
|
||||
$this->createKeyPair();
|
||||
@@ -239,7 +237,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
{
|
||||
Log::debug('get public key');
|
||||
$preference = Preferences::getForUser($this->user, 'bunq_public_key', null);
|
||||
if (is_null($preference)) {
|
||||
if (null === $preference) {
|
||||
Log::debug('public key is null');
|
||||
// create key pair
|
||||
$this->createKeyPair();
|
||||
@@ -254,18 +252,19 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
* Request users server remote IP. Let's assume this value will not change any time soon.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRemoteIp(): string
|
||||
{
|
||||
$preference = Preferences::getForUser($this->user, 'external_ip', null);
|
||||
if (is_null($preference)) {
|
||||
if (null === $preference) {
|
||||
try {
|
||||
$response = Requests::get('https://api.ipify.org');
|
||||
} catch (Requests_Exception $e) {
|
||||
throw new FireflyException(sprintf('Could not retrieve external IP: %s', $e->getMessage()));
|
||||
}
|
||||
if ($response->status_code !== 200) {
|
||||
if (200 !== $response->status_code) {
|
||||
throw new FireflyException(sprintf('Could not retrieve external IP: %d %s', $response->status_code, $response->body));
|
||||
}
|
||||
$serverIp = $response->body;
|
||||
@@ -299,7 +298,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
Log::debug('Now in registerDevice');
|
||||
$deviceServerId = Preferences::getForUser($this->user, 'bunq_device_server_id', null);
|
||||
$serverIp = $this->getRemoteIp();
|
||||
if (!is_null($deviceServerId)) {
|
||||
if (null !== $deviceServerId) {
|
||||
Log::debug('Have device server ID.');
|
||||
|
||||
return $deviceServerId->data;
|
||||
@@ -323,7 +322,7 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
if (is_null($deviceServerId)) {
|
||||
if (null === $deviceServerId) {
|
||||
// try get the current from a list:
|
||||
$deviceServerId = $this->getExistingDevice();
|
||||
}
|
||||
|
||||
@@ -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\Support\Import\Prerequisites;
|
||||
|
||||
Reference in New Issue
Block a user