mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +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\Import\Configurator;
|
||||
@@ -26,9 +25,7 @@ namespace FireflyIII\Import\Configurator;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
|
||||
/**
|
||||
* Interface ConfiguratorInterface
|
||||
*
|
||||
* @package FireflyIII\Import\Configurator
|
||||
* Interface ConfiguratorInterface.
|
||||
*/
|
||||
interface ConfiguratorInterface
|
||||
{
|
||||
@@ -76,8 +73,6 @@ interface ConfiguratorInterface
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setJob(ImportJob $job);
|
||||
}
|
||||
|
||||
@@ -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\Import\Configurator;
|
||||
@@ -32,13 +31,11 @@ use FireflyIII\Support\Import\Configuration\Csv\Roles;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class CsvConfigurator
|
||||
*
|
||||
* @package FireflyIII\Import\Configurator
|
||||
* Class CsvConfigurator.
|
||||
*/
|
||||
class CsvConfigurator implements ConfiguratorInterface
|
||||
{
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
|
||||
/** @var string */
|
||||
@@ -57,6 +54,7 @@ class CsvConfigurator implements ConfiguratorInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function configureJob(array $data): bool
|
||||
@@ -76,6 +74,7 @@ class CsvConfigurator implements ConfiguratorInterface
|
||||
* Return the data required for the next step in the job configuration.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getNextData(): array
|
||||
@@ -91,6 +90,7 @@ class CsvConfigurator implements ConfiguratorInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getNextView(): string
|
||||
@@ -146,7 +146,7 @@ class CsvConfigurator implements ConfiguratorInterface
|
||||
public function setJob(ImportJob $job)
|
||||
{
|
||||
$this->job = $job;
|
||||
if (is_null($this->job->configuration) || count($this->job->configuration) === 0) {
|
||||
if (null === $this->job->configuration || 0 === count($this->job->configuration)) {
|
||||
Log::debug(sprintf('Gave import job %s initial configuration.', $this->job->key));
|
||||
$this->job->configuration = config('csv.default_config');
|
||||
$this->job->save();
|
||||
@@ -155,26 +155,27 @@ class CsvConfigurator implements ConfiguratorInterface
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getConfigurationClass(): string
|
||||
{
|
||||
$class = false;
|
||||
switch (true) {
|
||||
case (!$this->job->configuration['initial-config-complete']):
|
||||
case !$this->job->configuration['initial-config-complete']:
|
||||
$class = Initial::class;
|
||||
break;
|
||||
case (!$this->job->configuration['column-roles-complete']):
|
||||
case !$this->job->configuration['column-roles-complete']:
|
||||
$class = Roles::class;
|
||||
break;
|
||||
case (!$this->job->configuration['column-mapping-complete']):
|
||||
case !$this->job->configuration['column-mapping-complete']:
|
||||
$class = Map::class;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ($class === false || strlen($class) === 0) {
|
||||
if (false === $class || 0 === strlen($class)) {
|
||||
throw new FireflyException('Cannot handle current job state in getConfigurationClass().');
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
|
||||
@@ -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\Import\Converter;
|
||||
@@ -26,16 +25,13 @@ namespace FireflyIII\Import\Converter;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RabobankDebetCredit
|
||||
*
|
||||
* @package FireflyIII\Import\Converter
|
||||
* Class RabobankDebetCredit.
|
||||
*/
|
||||
class Amount implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
|
||||
* - Jamie Zawinski
|
||||
* - Jamie Zawinski.
|
||||
*
|
||||
*
|
||||
* @param $value
|
||||
@@ -46,7 +42,7 @@ class Amount implements ConverterInterface
|
||||
*/
|
||||
public function convert($value): string
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (null === $value) {
|
||||
return '0';
|
||||
}
|
||||
$value = strval($value);
|
||||
@@ -56,35 +52,35 @@ class Amount implements ConverterInterface
|
||||
$altPosition = $len - 2;
|
||||
$decimal = null;
|
||||
|
||||
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
||||
if (($len > 2 && '.' === $value[$decimalPosition]) || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
||||
$decimal = '.';
|
||||
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
|
||||
}
|
||||
if ($len > 2 && $value{$decimalPosition} === ',') {
|
||||
if ($len > 2 && ',' === $value[$decimalPosition]) {
|
||||
$decimal = ',';
|
||||
Log::debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
|
||||
}
|
||||
// decimal character is null? find out if "0.1" or ".1" or "0,1" or ",1"
|
||||
if ($len > 1 && ($value{$altPosition} === '.' || $value{$altPosition} === ',')) {
|
||||
$decimal = $value{$altPosition};
|
||||
if ($len > 1 && ('.' === $value[$altPosition] || ',' === $value[$altPosition])) {
|
||||
$decimal = $value[$altPosition];
|
||||
Log::debug(sprintf('Alternate search resulted in "%s" for decimal sign.', $decimal));
|
||||
}
|
||||
|
||||
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
|
||||
if ($decimal === '.') {
|
||||
if ('.' === $decimal) {
|
||||
$search = [',', ' '];
|
||||
$oldValue = $value;
|
||||
$value = str_replace($search, '', $value);
|
||||
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
|
||||
}
|
||||
if ($decimal === ',') {
|
||||
if (',' === $decimal) {
|
||||
$search = ['.', ' '];
|
||||
$oldValue = $value;
|
||||
$value = str_replace($search, '', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
|
||||
}
|
||||
if (is_null($decimal)) {
|
||||
if (null === $decimal) {
|
||||
// replace all:
|
||||
$search = ['.', ' ', ','];
|
||||
$oldValue = $value;
|
||||
|
||||
@@ -18,21 +18,17 @@
|
||||
* 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\Import\Converter;
|
||||
|
||||
/**
|
||||
* Interface ConverterInterface
|
||||
*
|
||||
* @package FireflyIII\Import\Converter
|
||||
* Interface ConverterInterface.
|
||||
*/
|
||||
interface ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
*/
|
||||
public function convert($value);
|
||||
}
|
||||
|
||||
@@ -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\Import\Converter;
|
||||
@@ -26,13 +25,10 @@ namespace FireflyIII\Import\Converter;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class INGDebetCredit
|
||||
*
|
||||
* @package FireflyIII\Import\Converter
|
||||
* Class INGDebetCredit.
|
||||
*/
|
||||
class INGDebetCredit implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
@@ -42,7 +38,7 @@ class INGDebetCredit implements ConverterInterface
|
||||
{
|
||||
Log::debug('Going to convert ing debet credit', ['value' => $value]);
|
||||
|
||||
if ($value === 'Af') {
|
||||
if ('Af' === $value) {
|
||||
Log::debug('Return -1');
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -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\Import\Converter;
|
||||
@@ -26,13 +25,10 @@ namespace FireflyIII\Import\Converter;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RabobankDebetCredit
|
||||
*
|
||||
* @package FireflyIII\Import\Converter
|
||||
* Class RabobankDebetCredit.
|
||||
*/
|
||||
class RabobankDebetCredit implements ConverterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
@@ -42,7 +38,7 @@ class RabobankDebetCredit implements ConverterInterface
|
||||
{
|
||||
Log::debug('Going to convert ', ['value' => $value]);
|
||||
|
||||
if ($value === 'D') {
|
||||
if ('D' === $value) {
|
||||
Log::debug('Return -1');
|
||||
|
||||
return -1;
|
||||
|
||||
@@ -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\Import\FileProcessor;
|
||||
@@ -37,12 +36,10 @@ use Log;
|
||||
* Class CsvProcessor, as the name suggests, goes over CSV file line by line and creates
|
||||
* "ImportJournal" objects, which are used in another step to create new journals and transactions
|
||||
* and what-not.
|
||||
*
|
||||
* @package FireflyIII\Import\FileProcessor
|
||||
*/
|
||||
class CsvProcessor implements FileProcessorInterface
|
||||
{
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
/** @var Collection */
|
||||
private $objects;
|
||||
@@ -136,6 +133,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function annotateValue(int $index, string $value)
|
||||
@@ -167,7 +165,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
$config = $this->job->configuration;
|
||||
$reader = Reader::createFromString($content);
|
||||
$delimiter = $config['delimiter'];
|
||||
if ($delimiter === 'tab') {
|
||||
if ('tab' === $delimiter) {
|
||||
$delimiter = "\t";
|
||||
}
|
||||
$reader->setDelimiter($delimiter);
|
||||
@@ -213,6 +211,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
* @param array $array
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRowHash(array $array): string
|
||||
@@ -220,7 +219,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
$json = json_encode($array);
|
||||
$jsonError = json_last_error();
|
||||
|
||||
if ($json === false) {
|
||||
if (false === $json) {
|
||||
throw new FireflyException(sprintf('Error while encoding JSON for CSV row: %s', $this->getJsonError($jsonError)));
|
||||
}
|
||||
$hash = hash('sha256', $json);
|
||||
@@ -235,6 +234,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
* @param array $row
|
||||
*
|
||||
* @return ImportJournal
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function importRow(int $index, array $row): ImportJournal
|
||||
@@ -248,7 +248,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
$journal->setHash($hash);
|
||||
|
||||
/**
|
||||
* @var int $rowIndex
|
||||
* @var int
|
||||
* @var string $value
|
||||
*/
|
||||
foreach ($row as $rowIndex => $value) {
|
||||
@@ -280,7 +280,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
->where('data', $json)
|
||||
->where('name', 'importHash')
|
||||
->first();
|
||||
if (!is_null($entry)) {
|
||||
if (null !== $entry) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -293,6 +293,7 @@ class CsvProcessor implements FileProcessorInterface
|
||||
* @param array $row
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function specifics(array $row): array
|
||||
|
||||
@@ -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\Import\FileProcessor;
|
||||
@@ -27,14 +26,10 @@ use FireflyIII\Models\ImportJob;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface FileProcessorInterface
|
||||
*
|
||||
* @package FireflyIII\Import\FileProcessor
|
||||
* Interface FileProcessorInterface.
|
||||
*/
|
||||
interface FileProcessorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -50,5 +45,5 @@ interface FileProcessorInterface
|
||||
*
|
||||
* @return FileProcessorInterface
|
||||
*/
|
||||
public function setJob(ImportJob $job): FileProcessorInterface;
|
||||
public function setJob(ImportJob $job): self;
|
||||
}
|
||||
|
||||
@@ -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\Import\Logging;
|
||||
@@ -27,14 +26,11 @@ use Illuminate\Console\Command;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
|
||||
/**
|
||||
* Class CommandHandler
|
||||
*
|
||||
* @package FireflyIII\Import\Logging
|
||||
* Class CommandHandler.
|
||||
*/
|
||||
class CommandHandler extends AbstractProcessingHandler
|
||||
{
|
||||
|
||||
/** @var Command */
|
||||
/** @var Command */
|
||||
private $command;
|
||||
|
||||
/**
|
||||
@@ -51,11 +47,9 @@ class CommandHandler extends AbstractProcessingHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the record down to the log of the implementing handler
|
||||
* Writes the record down to the log of the implementing handler.
|
||||
*
|
||||
* @param array $record
|
||||
*
|
||||
* @return void
|
||||
* @param array $record
|
||||
*/
|
||||
protected function write(array $record)
|
||||
{
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -28,13 +27,10 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class AssetAccounts
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class AssetAccounts.
|
||||
*/
|
||||
class AssetAccountIbans implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -52,7 +48,7 @@ class AssetAccountIbans implements MapperInterface
|
||||
if (strlen($iban) > 0) {
|
||||
$topList[$account->id] = $account->iban . ' (' . $account->name . ')';
|
||||
}
|
||||
if (strlen($iban) === 0) {
|
||||
if (0 === strlen($iban)) {
|
||||
$list[$account->id] = $account->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -28,13 +27,10 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class AssetAccounts
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class AssetAccounts.
|
||||
*/
|
||||
class AssetAccounts implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -27,13 +26,10 @@ use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Bills
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class Bills.
|
||||
*/
|
||||
class Bills implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -27,13 +26,10 @@ use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Budgets
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class Budgets.
|
||||
*/
|
||||
class Budgets implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -27,13 +26,10 @@ use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Categories
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class Categories.
|
||||
*/
|
||||
class Categories implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
* 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\Import\Mapper;
|
||||
|
||||
/**
|
||||
* Interface MapperInterface
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Interface MapperInterface.
|
||||
*/
|
||||
interface MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -28,13 +27,10 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class OpposingAccounts
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class OpposingAccounts.
|
||||
*/
|
||||
class OpposingAccountIbans implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -58,7 +54,7 @@ class OpposingAccountIbans implements MapperInterface
|
||||
if (strlen($iban) > 0) {
|
||||
$topList[$account->id] = $account->iban . ' (' . $account->name . ')';
|
||||
}
|
||||
if (strlen($iban) === 0) {
|
||||
if (0 === strlen($iban)) {
|
||||
$list[$account->id] = $account->name;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +64,6 @@ class OpposingAccountIbans implements MapperInterface
|
||||
$list = $topList + $list;
|
||||
$list = [0 => trans('csv.map_do_not_map')] + $list;
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -28,13 +27,10 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class OpposingAccounts
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class OpposingAccounts.
|
||||
*/
|
||||
class OpposingAccounts implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -27,13 +26,10 @@ use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class Tags
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class Tags.
|
||||
*/
|
||||
class Tags implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -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\Import\Mapper;
|
||||
@@ -26,13 +25,10 @@ namespace FireflyIII\Import\Mapper;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
|
||||
/**
|
||||
* Class TransactionCurrencies
|
||||
*
|
||||
* @package FireflyIII\Import\Mapper
|
||||
* Class TransactionCurrencies.
|
||||
*/
|
||||
class TransactionCurrencies implements MapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
* 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\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Interface PreProcessorInterface
|
||||
*
|
||||
* @package FireflyIII\Import\MapperPreProcess
|
||||
* Interface PreProcessorInterface.
|
||||
*/
|
||||
interface PreProcessorInterface
|
||||
{
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
* 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\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Class TagsComma
|
||||
*
|
||||
* @package FireflyIII\Import\MapperPreProcess
|
||||
* Class TagsComma.
|
||||
*/
|
||||
class TagsComma implements PreProcessorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
* 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\Import\MapperPreProcess;
|
||||
|
||||
/**
|
||||
* Class TagsSpace
|
||||
*
|
||||
* @package FireflyIII\Import\MapperPreProcess
|
||||
* Class TagsSpace.
|
||||
*/
|
||||
class TagsSpace implements PreProcessorInterface
|
||||
{
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -31,19 +30,15 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ImportAccount
|
||||
*
|
||||
* @package FireflyIII\Import\Object
|
||||
* Class ImportAccount.
|
||||
*/
|
||||
class ImportAccount
|
||||
{
|
||||
|
||||
/** @var Account */
|
||||
/** @var Account */
|
||||
private $account;
|
||||
/** @var array */
|
||||
private $accountIban = [];
|
||||
/** @var array */
|
||||
/** @var array */
|
||||
private $accountId = [];
|
||||
/** @var array */
|
||||
private $accountName = [];
|
||||
@@ -61,9 +56,9 @@ class ImportAccount
|
||||
* @var int
|
||||
*/
|
||||
private $forbiddenAccountId = 0;
|
||||
/** @var AccountRepositoryInterface */
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -82,7 +77,7 @@ class ImportAccount
|
||||
*/
|
||||
public function getAccount(): Account
|
||||
{
|
||||
if (is_null($this->account->id)) {
|
||||
if (null === $this->account->id) {
|
||||
$this->store();
|
||||
}
|
||||
|
||||
@@ -174,14 +169,14 @@ class ImportAccount
|
||||
$accountType = AccountType::whereType($this->expectedType)->first();
|
||||
|
||||
// 1: find by ID, iban or name (and type)
|
||||
if (count($this->accountId) === 3) {
|
||||
if (3 === count($this->accountId)) {
|
||||
Log::debug(sprintf('Finding account of type %d and ID %d', $accountType->id, $this->accountId['value']));
|
||||
/** @var Account $account */
|
||||
$account = $this->user->accounts()->where('id', '!=', $this->forbiddenAccountId)->where('account_type_id', $accountType->id)->where(
|
||||
'id',
|
||||
$this->accountId['value']
|
||||
)->first();
|
||||
if (!is_null($account)) {
|
||||
if (null !== $account) {
|
||||
Log::debug(sprintf('Found unmapped %s account by ID (#%d): %s', $this->expectedType, $account->id, $account->name));
|
||||
|
||||
return $account;
|
||||
@@ -191,7 +186,7 @@ class ImportAccount
|
||||
/** @var Collection $accounts */
|
||||
$accounts = $this->repository->getAccountsByType([$accountType->type]);
|
||||
// Two: find by IBAN (and type):
|
||||
if (count($this->accountIban) === 3) {
|
||||
if (3 === count($this->accountIban)) {
|
||||
$iban = $this->accountIban['value'];
|
||||
Log::debug(sprintf('Finding account of type %d and IBAN %s', $accountType->id, $iban));
|
||||
$filtered = $accounts->filter(
|
||||
@@ -207,14 +202,14 @@ class ImportAccount
|
||||
return null;
|
||||
}
|
||||
);
|
||||
if ($filtered->count() === 1) {
|
||||
if (1 === $filtered->count()) {
|
||||
return $filtered->first();
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
}
|
||||
|
||||
// Three: find by name (and type):
|
||||
if (count($this->accountName) === 3) {
|
||||
if (3 === count($this->accountName)) {
|
||||
$name = $this->accountName['value'];
|
||||
Log::debug(sprintf('Finding account of type %d and name %s', $accountType->id, $name));
|
||||
$filtered = $accounts->filter(
|
||||
@@ -229,7 +224,7 @@ class ImportAccount
|
||||
}
|
||||
);
|
||||
|
||||
if ($filtered->count() === 1) {
|
||||
if (1 === $filtered->count()) {
|
||||
return $filtered->first();
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
@@ -253,7 +248,7 @@ class ImportAccount
|
||||
Log::debug(sprintf('Find mapped account based on field "%s" with value', $field), $array);
|
||||
// check if a pre-mapped object exists.
|
||||
$mapped = $this->getMappedObject($array);
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug(sprintf('Found account #%d!', $mapped->id));
|
||||
|
||||
return $mapped;
|
||||
@@ -272,13 +267,13 @@ class ImportAccount
|
||||
private function getMappedObject(array $array): Account
|
||||
{
|
||||
Log::debug('In getMappedObject() for Account');
|
||||
if (count($array) === 0) {
|
||||
if (0 === count($array)) {
|
||||
Log::debug('Array is empty, nothing will come of this.');
|
||||
|
||||
return new Account;
|
||||
}
|
||||
|
||||
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
|
||||
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
|
||||
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
|
||||
|
||||
return new Account;
|
||||
@@ -289,7 +284,7 @@ class ImportAccount
|
||||
$search = intval($array['mapped']);
|
||||
$account = $this->repository->find($search);
|
||||
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
Log::error(sprintf('There is no account with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
return new Account;
|
||||
@@ -297,7 +292,7 @@ class ImportAccount
|
||||
// must be of the same type
|
||||
// except when mapped is an asset, then it's fair game.
|
||||
// which only shows that user must map very carefully.
|
||||
if ($account->accountType->type !== $this->expectedType && $account->accountType->type !== AccountType::ASSET) {
|
||||
if ($account->accountType->type !== $this->expectedType && AccountType::ASSET !== $account->accountType->type) {
|
||||
Log::error(
|
||||
sprintf(
|
||||
'Mapped account #%d is of type "%s" but we expect a "%s"-account. Mapping will be ignored.',
|
||||
@@ -322,14 +317,14 @@ class ImportAccount
|
||||
{
|
||||
// 1: find mapped object:
|
||||
$mapped = $this->findMappedObject();
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
$this->account = $mapped;
|
||||
|
||||
return true;
|
||||
}
|
||||
// 2: find existing by given values:
|
||||
$found = $this->findExistingObject();
|
||||
if (!is_null($found->id)) {
|
||||
if (null !== $found->id) {
|
||||
$this->account = $found;
|
||||
|
||||
return true;
|
||||
@@ -340,7 +335,7 @@ class ImportAccount
|
||||
$oldExpectedType = $this->expectedType;
|
||||
$this->expectedType = AccountType::ASSET;
|
||||
$found = $this->findExistingObject();
|
||||
if (!is_null($found->id)) {
|
||||
if (null !== $found->id) {
|
||||
Log::debug('Found asset account!');
|
||||
$this->account = $found;
|
||||
|
||||
@@ -349,7 +344,7 @@ class ImportAccount
|
||||
$this->expectedType = $oldExpectedType;
|
||||
|
||||
// 4: if search for an asset account, fall back to given "default account" (mandatory)
|
||||
if ($this->expectedType === AccountType::ASSET) {
|
||||
if (AccountType::ASSET === $this->expectedType) {
|
||||
$this->account = $this->repository->find($this->defaultAccountId);
|
||||
Log::debug(sprintf('Fall back to default account #%d "%s"', $this->account->id, $this->account->name));
|
||||
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -31,13 +30,10 @@ use Log;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* Class ImportBill
|
||||
*
|
||||
* @package FireflyIII\Import\Object
|
||||
* Class ImportBill.
|
||||
*/
|
||||
class ImportBill
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $amount = '1';
|
||||
/** @var Bill */
|
||||
@@ -48,7 +44,7 @@ class ImportBill
|
||||
private $name = [];
|
||||
/** @var BillRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -66,7 +62,7 @@ class ImportBill
|
||||
*/
|
||||
public function getBill(): Bill
|
||||
{
|
||||
if (is_null($this->bill->id)) {
|
||||
if (null === $this->bill->id) {
|
||||
$this->store();
|
||||
}
|
||||
|
||||
@@ -114,11 +110,11 @@ class ImportBill
|
||||
Log::debug('In findExistingObject() for Bill');
|
||||
// 1: find by ID, or name
|
||||
|
||||
if (count($this->id) === 3) {
|
||||
if (3 === count($this->id)) {
|
||||
Log::debug(sprintf('Finding bill with ID #%d', $this->id['value']));
|
||||
/** @var Bill $bill */
|
||||
$bill = $this->repository->find(intval($this->id['value']));
|
||||
if (!is_null($bill->id)) {
|
||||
if (null !== $bill->id) {
|
||||
Log::debug(sprintf('Found unmapped bill by ID (#%d): %s', $bill->id, $bill->name));
|
||||
|
||||
return $bill;
|
||||
@@ -126,7 +122,7 @@ class ImportBill
|
||||
Log::debug('Found nothing.');
|
||||
}
|
||||
// 2: find by name
|
||||
if (count($this->name) === 3) {
|
||||
if (3 === count($this->name)) {
|
||||
/** @var Collection $bills */
|
||||
$bills = $this->repository->getBills();
|
||||
$name = $this->name['value'];
|
||||
@@ -143,7 +139,7 @@ class ImportBill
|
||||
}
|
||||
);
|
||||
|
||||
if ($filtered->count() === 1) {
|
||||
if (1 === $filtered->count()) {
|
||||
return $filtered->first();
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
@@ -167,7 +163,7 @@ class ImportBill
|
||||
Log::debug(sprintf('Find mapped bill based on field "%s" with value', $field), $array);
|
||||
// check if a pre-mapped object exists.
|
||||
$mapped = $this->getMappedObject($array);
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug(sprintf('Found bill #%d!', $mapped->id));
|
||||
|
||||
return $mapped;
|
||||
@@ -186,13 +182,13 @@ class ImportBill
|
||||
private function getMappedObject(array $array): Bill
|
||||
{
|
||||
Log::debug('In getMappedObject() for Bill');
|
||||
if (count($array) === 0) {
|
||||
if (0 === count($array)) {
|
||||
Log::debug('Array is empty, nothing will come of this.');
|
||||
|
||||
return new Bill;
|
||||
}
|
||||
|
||||
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
|
||||
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
|
||||
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
|
||||
|
||||
return new Bill;
|
||||
@@ -203,13 +199,12 @@ class ImportBill
|
||||
$search = intval($array['mapped']);
|
||||
$bill = $this->repository->find($search);
|
||||
|
||||
if (is_null($bill->id)) {
|
||||
if (null === $bill->id) {
|
||||
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
return new Bill;
|
||||
}
|
||||
|
||||
|
||||
Log::debug(sprintf('Found bill! #%d ("%s"). Return it', $bill->id, $bill->name));
|
||||
|
||||
return $bill;
|
||||
@@ -222,21 +217,21 @@ class ImportBill
|
||||
{
|
||||
// 1: find mapped object:
|
||||
$mapped = $this->findMappedObject();
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
$this->bill = $mapped;
|
||||
|
||||
return true;
|
||||
}
|
||||
// 2: find existing by given values:
|
||||
$found = $this->findExistingObject();
|
||||
if (!is_null($found->id)) {
|
||||
if (null !== $found->id) {
|
||||
$this->bill = $found;
|
||||
|
||||
return true;
|
||||
}
|
||||
$name = $this->name['value'] ?? '';
|
||||
|
||||
if (strlen($name) === 0) {
|
||||
if (0 === strlen($name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -255,7 +250,6 @@ class ImportBill
|
||||
|
||||
Log::debug('Found no bill so must create one ourselves. Assume default values.', $data);
|
||||
|
||||
|
||||
$this->bill = $this->repository->store($data);
|
||||
Log::debug(sprintf('Successfully stored new bill #%d: %s', $this->bill->id, $this->bill->name));
|
||||
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -30,13 +29,10 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ImportBudget
|
||||
*
|
||||
* @package FireflyIII\Import\Object
|
||||
* Class ImportBudget.
|
||||
*/
|
||||
class ImportBudget
|
||||
{
|
||||
|
||||
/** @var Budget */
|
||||
private $budget;
|
||||
/** @var array */
|
||||
@@ -45,7 +41,7 @@ class ImportBudget
|
||||
private $name = [];
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -63,7 +59,7 @@ class ImportBudget
|
||||
*/
|
||||
public function getBudget(): Budget
|
||||
{
|
||||
if (is_null($this->budget->id)) {
|
||||
if (null === $this->budget->id) {
|
||||
$this->store();
|
||||
}
|
||||
|
||||
@@ -103,11 +99,11 @@ class ImportBudget
|
||||
Log::debug('In findExistingObject() for Budget');
|
||||
// 1: find by ID, or name
|
||||
|
||||
if (count($this->id) === 3) {
|
||||
if (3 === count($this->id)) {
|
||||
Log::debug(sprintf('Finding budget with ID #%d', $this->id['value']));
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->repository->find(intval($this->id['value']));
|
||||
if (!is_null($budget->id)) {
|
||||
if (null !== $budget->id) {
|
||||
Log::debug(sprintf('Found unmapped budget by ID (#%d): %s', $budget->id, $budget->name));
|
||||
|
||||
return $budget;
|
||||
@@ -115,7 +111,7 @@ class ImportBudget
|
||||
Log::debug('Found nothing.');
|
||||
}
|
||||
// 2: find by name
|
||||
if (count($this->name) === 3) {
|
||||
if (3 === count($this->name)) {
|
||||
/** @var Collection $budgets */
|
||||
$budgets = $this->repository->getBudgets();
|
||||
$name = $this->name['value'];
|
||||
@@ -132,7 +128,7 @@ class ImportBudget
|
||||
}
|
||||
);
|
||||
|
||||
if ($filtered->count() === 1) {
|
||||
if (1 === $filtered->count()) {
|
||||
return $filtered->first();
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
@@ -156,7 +152,7 @@ class ImportBudget
|
||||
Log::debug(sprintf('Find mapped budget based on field "%s" with value', $field), $array);
|
||||
// check if a pre-mapped object exists.
|
||||
$mapped = $this->getMappedObject($array);
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug(sprintf('Found budget #%d!', $mapped->id));
|
||||
|
||||
return $mapped;
|
||||
@@ -175,13 +171,13 @@ class ImportBudget
|
||||
private function getMappedObject(array $array): Budget
|
||||
{
|
||||
Log::debug('In getMappedObject() for Budget');
|
||||
if (count($array) === 0) {
|
||||
if (0 === count($array)) {
|
||||
Log::debug('Array is empty, nothing will come of this.');
|
||||
|
||||
return new Budget;
|
||||
}
|
||||
|
||||
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
|
||||
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
|
||||
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
|
||||
|
||||
return new Budget;
|
||||
@@ -192,7 +188,7 @@ class ImportBudget
|
||||
$search = intval($array['mapped']);
|
||||
$budget = $this->repository->find($search);
|
||||
|
||||
if (is_null($budget->id)) {
|
||||
if (null === $budget->id) {
|
||||
Log::error(sprintf('There is no budget with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
return new Budget;
|
||||
@@ -210,21 +206,21 @@ class ImportBudget
|
||||
{
|
||||
// 1: find mapped object:
|
||||
$mapped = $this->findMappedObject();
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
$this->budget = $mapped;
|
||||
|
||||
return true;
|
||||
}
|
||||
// 2: find existing by given values:
|
||||
$found = $this->findExistingObject();
|
||||
if (!is_null($found->id)) {
|
||||
if (null !== $found->id) {
|
||||
$this->budget = $found;
|
||||
|
||||
return true;
|
||||
}
|
||||
$name = $this->name['value'] ?? '';
|
||||
|
||||
if (strlen($name) === 0) {
|
||||
if (0 === strlen($name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -39,7 +38,7 @@ class ImportCategory
|
||||
private $name = [];
|
||||
/** @var CategoryRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -57,7 +56,7 @@ class ImportCategory
|
||||
*/
|
||||
public function getCategory(): Category
|
||||
{
|
||||
if (is_null($this->category->id)) {
|
||||
if (null === $this->category->id) {
|
||||
$this->store();
|
||||
}
|
||||
|
||||
@@ -97,11 +96,11 @@ class ImportCategory
|
||||
Log::debug('In findExistingObject() for Category');
|
||||
// 1: find by ID, or name
|
||||
|
||||
if (count($this->id) === 3) {
|
||||
if (3 === count($this->id)) {
|
||||
Log::debug(sprintf('Finding category with ID #%d', $this->id['value']));
|
||||
/** @var Category $category */
|
||||
$category = $this->repository->find(intval($this->id['value']));
|
||||
if (!is_null($category->id)) {
|
||||
if (null !== $category->id) {
|
||||
Log::debug(sprintf('Found unmapped category by ID (#%d): %s', $category->id, $category->name));
|
||||
|
||||
return $category;
|
||||
@@ -109,7 +108,7 @@ class ImportCategory
|
||||
Log::debug('Found nothing.');
|
||||
}
|
||||
// 2: find by name
|
||||
if (count($this->name) === 3) {
|
||||
if (3 === count($this->name)) {
|
||||
/** @var Collection $categories */
|
||||
$categories = $this->repository->getCategories();
|
||||
$name = $this->name['value'];
|
||||
@@ -126,7 +125,7 @@ class ImportCategory
|
||||
}
|
||||
);
|
||||
|
||||
if ($filtered->count() === 1) {
|
||||
if (1 === $filtered->count()) {
|
||||
return $filtered->first();
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
@@ -150,7 +149,7 @@ class ImportCategory
|
||||
Log::debug(sprintf('Find mapped category based on field "%s" with value', $field), $array);
|
||||
// check if a pre-mapped object exists.
|
||||
$mapped = $this->getMappedObject($array);
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug(sprintf('Found category #%d!', $mapped->id));
|
||||
|
||||
return $mapped;
|
||||
@@ -169,13 +168,13 @@ class ImportCategory
|
||||
private function getMappedObject(array $array): Category
|
||||
{
|
||||
Log::debug('In getMappedObject() for Category');
|
||||
if (count($array) === 0) {
|
||||
if (0 === count($array)) {
|
||||
Log::debug('Array is empty, nothing will come of this.');
|
||||
|
||||
return new Category;
|
||||
}
|
||||
|
||||
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
|
||||
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
|
||||
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
|
||||
|
||||
return new Category;
|
||||
@@ -186,7 +185,7 @@ class ImportCategory
|
||||
$search = intval($array['mapped']);
|
||||
$category = $this->repository->find($search);
|
||||
|
||||
if (is_null($category->id)) {
|
||||
if (null === $category->id) {
|
||||
Log::error(sprintf('There is no category with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
return new Category;
|
||||
@@ -204,21 +203,21 @@ class ImportCategory
|
||||
{
|
||||
// 1: find mapped object:
|
||||
$mapped = $this->findMappedObject();
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
$this->category = $mapped;
|
||||
|
||||
return true;
|
||||
}
|
||||
// 2: find existing by given values:
|
||||
$found = $this->findExistingObject();
|
||||
if (!is_null($found->id)) {
|
||||
if (null !== $found->id) {
|
||||
$this->category = $found;
|
||||
|
||||
return true;
|
||||
}
|
||||
$name = $this->name['value'] ?? '';
|
||||
|
||||
if (strlen($name) === 0) {
|
||||
if (0 === strlen($name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -32,17 +31,17 @@ class ImportCurrency
|
||||
{
|
||||
/** @var array */
|
||||
private $code = [];
|
||||
/** @var TransactionCurrency */
|
||||
/** @var TransactionCurrency */
|
||||
private $currency;
|
||||
/** @var array */
|
||||
private $id = [];
|
||||
/** @var array */
|
||||
private $name = [];
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var array */
|
||||
private $symbol = [];
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -59,14 +58,14 @@ class ImportCurrency
|
||||
*/
|
||||
public function getTransactionCurrency(): TransactionCurrency
|
||||
{
|
||||
if (!is_null($this->currency->id)) {
|
||||
if (null !== $this->currency->id) {
|
||||
return $this->currency;
|
||||
}
|
||||
Log::debug('In createCurrency()');
|
||||
// check if any of them is mapped:
|
||||
$mapped = $this->findMappedObject();
|
||||
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug('Mapped existing currency.', ['new' => $mapped->toArray()]);
|
||||
$this->currency = $mapped;
|
||||
|
||||
@@ -74,7 +73,7 @@ class ImportCurrency
|
||||
}
|
||||
|
||||
$searched = $this->findExistingObject();
|
||||
if (!is_null($searched->id)) {
|
||||
if (null !== $searched->id) {
|
||||
Log::debug('Found existing currency.', ['found' => $searched->toArray()]);
|
||||
$this->currency = $searched;
|
||||
|
||||
@@ -86,7 +85,7 @@ class ImportCurrency
|
||||
'name' => $this->name['value'] ?? null,
|
||||
'decimal_places' => 2,
|
||||
];
|
||||
if (is_null($data['code'])) {
|
||||
if (null === $data['code']) {
|
||||
Log::debug('Need at least a code to create currency, return nothing.');
|
||||
|
||||
return new TransactionCurrency();
|
||||
@@ -97,7 +96,6 @@ class ImportCurrency
|
||||
$this->currency = $currency;
|
||||
Log::info('Made new currency.', ['input' => $data, 'new' => $currency->toArray()]);
|
||||
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
@@ -156,11 +154,11 @@ class ImportCurrency
|
||||
];
|
||||
foreach ($search as $field => $function) {
|
||||
$value = $this->$field['value'] ?? null;
|
||||
if (!is_null($value)) {
|
||||
if (null !== $value) {
|
||||
Log::debug(sprintf('Searching for %s using function %s and value %s', $field, $function, $value));
|
||||
$currency = $this->repository->$function($value);
|
||||
|
||||
if (!is_null($currency->id)) {
|
||||
if (null !== $currency->id) {
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
@@ -181,7 +179,7 @@ class ImportCurrency
|
||||
Log::debug(sprintf('Find mapped currency based on field "%s" with value', $field), $array);
|
||||
// check if a pre-mapped object exists.
|
||||
$mapped = $this->getMappedObject($array);
|
||||
if (!is_null($mapped->id)) {
|
||||
if (null !== $mapped->id) {
|
||||
Log::debug(sprintf('Found currency #%d!', $mapped->id));
|
||||
|
||||
return $mapped;
|
||||
@@ -200,13 +198,13 @@ class ImportCurrency
|
||||
private function getMappedObject(array $array): TransactionCurrency
|
||||
{
|
||||
Log::debug('In getMappedObject()');
|
||||
if (count($array) === 0) {
|
||||
if (0 === count($array)) {
|
||||
Log::debug('Array is empty, nothing will come of this.');
|
||||
|
||||
return new TransactionCurrency;
|
||||
}
|
||||
|
||||
if (array_key_exists('mapped', $array) && is_null($array['mapped'])) {
|
||||
if (array_key_exists('mapped', $array) && null === $array['mapped']) {
|
||||
Log::debug(sprintf('No map present for value "%s". Return NULL.', $array['value']));
|
||||
|
||||
return new TransactionCurrency;
|
||||
@@ -217,8 +215,7 @@ class ImportCurrency
|
||||
$search = intval($array['mapped']);
|
||||
$currency = $this->repository->find($search);
|
||||
|
||||
|
||||
if (is_null($currency->id)) {
|
||||
if (null === $currency->id) {
|
||||
Log::error(sprintf('There is no currency with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
return new TransactionCurrency;
|
||||
|
||||
@@ -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\Import\Object;
|
||||
@@ -34,25 +33,23 @@ use Log;
|
||||
use Steam;
|
||||
|
||||
/**
|
||||
* Class ImportJournal
|
||||
*
|
||||
* @package FireflyIII\Import\Object
|
||||
* Class ImportJournal.
|
||||
*/
|
||||
class ImportJournal
|
||||
{
|
||||
/** @var ImportAccount */
|
||||
public $asset;
|
||||
/** @var ImportBill */
|
||||
/** @var ImportBill */
|
||||
public $bill;
|
||||
/** @var ImportBudget */
|
||||
public $budget;
|
||||
/** @var ImportCategory */
|
||||
public $category;
|
||||
/** @var ImportCurrency */
|
||||
/** @var ImportCurrency */
|
||||
public $currency;
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
public $description = '';
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
public $hash;
|
||||
/** @var array */
|
||||
public $metaDates = [];
|
||||
@@ -64,7 +61,7 @@ class ImportJournal
|
||||
public $tags = [];
|
||||
/** @var string */
|
||||
private $amount;
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
private $convertedAmount = null;
|
||||
/** @var string */
|
||||
private $date = '';
|
||||
@@ -72,7 +69,7 @@ class ImportJournal
|
||||
private $externalId = '';
|
||||
/** @var array */
|
||||
private $modifiers = [];
|
||||
/** @var User */
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
@@ -98,12 +95,13 @@ class ImportJournal
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
Log::debug('Now in getAmount()');
|
||||
if (is_null($this->convertedAmount)) {
|
||||
if (null === $this->convertedAmount) {
|
||||
Log::debug('convertedAmount is NULL');
|
||||
/** @var ConverterInterface $amountConverter */
|
||||
$amountConverter = app(Amount::class);
|
||||
@@ -124,7 +122,7 @@ class ImportJournal
|
||||
Log::debug(sprintf('After modifiers the result is: "%s"', $this->convertedAmount));
|
||||
}
|
||||
Log::debug(sprintf('convertedAmount is: "%s"', $this->convertedAmount));
|
||||
if (bccomp($this->convertedAmount, '0') === 0) {
|
||||
if (0 === bccomp($this->convertedAmount, '0')) {
|
||||
throw new FireflyException('Amount is zero.');
|
||||
}
|
||||
|
||||
@@ -154,7 +152,7 @@ class ImportJournal
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if ($this->description === '') {
|
||||
if ('' === $this->description) {
|
||||
return '(no description)';
|
||||
}
|
||||
|
||||
|
||||
@@ -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\Import\Routine;
|
||||
@@ -35,19 +34,17 @@ use Log;
|
||||
|
||||
class ImportRoutine
|
||||
{
|
||||
|
||||
/** @var Collection */
|
||||
/** @var Collection */
|
||||
public $errors;
|
||||
/** @var Collection */
|
||||
/** @var Collection */
|
||||
public $journals;
|
||||
/** @var int */
|
||||
public $lines = 0;
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
private $job;
|
||||
|
||||
/**
|
||||
* ImportRoutine constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -60,7 +57,7 @@ class ImportRoutine
|
||||
*/
|
||||
public function run(): bool
|
||||
{
|
||||
if ($this->job->status !== 'configured') {
|
||||
if ('configured' !== $this->job->status) {
|
||||
Log::error(sprintf('Job %s is in state "%s" so it cannot be started.', $this->job->key, $this->job->status));
|
||||
|
||||
return false;
|
||||
@@ -93,7 +90,6 @@ class ImportRoutine
|
||||
|
||||
Log::info(sprintf('Done with import job %s', $this->job->key));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,8 +113,7 @@ class ImportRoutine
|
||||
$processor = app($class);
|
||||
$processor->setJob($this->job);
|
||||
|
||||
if ($this->job->status === 'configured') {
|
||||
|
||||
if ('configured' === $this->job->status) {
|
||||
// set job as "running"...
|
||||
$this->job->status = 'running';
|
||||
$this->job->save();
|
||||
|
||||
@@ -18,24 +18,21 @@
|
||||
* 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\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class AbnAmroDescription
|
||||
* Class AbnAmroDescription.
|
||||
*
|
||||
* Parses the description from txt files for ABN AMRO bank accounts.
|
||||
*
|
||||
* Based on the logic as described in the following Gist:
|
||||
* https://gist.github.com/vDorst/68d555a6a90f62fec004
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
*/
|
||||
class AbnAmroDescription implements SpecificInterface
|
||||
{
|
||||
/** @var array */
|
||||
/** @var array */
|
||||
public $row;
|
||||
|
||||
/**
|
||||
@@ -70,7 +67,6 @@ class AbnAmroDescription implements SpecificInterface
|
||||
// Try to parse the description in known formats.
|
||||
$parsed = $this->parseSepaDescription() || $this->parseTRTPDescription() || $this->parseGEABEADescription() || $this->parseABNAMRODescription();
|
||||
|
||||
|
||||
// If the description could not be parsed, specify an unknown opposing
|
||||
// account, as an opposing account is required
|
||||
if (!$parsed) {
|
||||
@@ -81,7 +77,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description with costs from ABN AMRO itself
|
||||
* Parses the current description with costs from ABN AMRO itself.
|
||||
*
|
||||
* @return bool true if the description is GEA/BEA-format, false otherwise
|
||||
*/
|
||||
@@ -99,7 +95,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in GEA/BEA format
|
||||
* Parses the current description in GEA/BEA format.
|
||||
*
|
||||
* @return bool true if the description is GEA/BEAformat, false otherwise
|
||||
*/
|
||||
@@ -107,12 +103,11 @@ class AbnAmroDescription implements SpecificInterface
|
||||
{
|
||||
// See if the current description is formatted in GEA/BEA format
|
||||
if (preg_match('/([BG]EA) +(NR:[a-zA-Z:0-9]+) +([0-9.\/]+) +([^,]*)/', $this->row[7], $matches)) {
|
||||
|
||||
// description and opposing account will be the same.
|
||||
$this->row[8] = $matches[4]; // 'opposing-account-name'
|
||||
$this->row[7] = $matches[4]; // 'description'
|
||||
|
||||
if ($matches[1] === 'GEA') {
|
||||
if ('GEA' === $matches[1]) {
|
||||
$this->row[7] = 'GEA ' . $matches[4]; // 'description'
|
||||
}
|
||||
|
||||
@@ -123,7 +118,8 @@ class AbnAmroDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in SEPA format
|
||||
* Parses the current description in SEPA format.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
* @return bool true if the description is SEPA format, false otherwise
|
||||
@@ -167,7 +163,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
// Set a new description for the current transaction. If none was given
|
||||
// set the description to type, name and reference
|
||||
$this->row[7] = $newDescription;
|
||||
if (strlen($newDescription) === 0) {
|
||||
if (0 === strlen($newDescription)) {
|
||||
$this->row[7] = sprintf('%s - %s (%s)', $type, $name, $reference);
|
||||
}
|
||||
|
||||
@@ -178,7 +174,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the current description in TRTP format
|
||||
* Parses the current description in TRTP format.
|
||||
*
|
||||
* @return bool true if the description is TRTP format, false otherwise
|
||||
*/
|
||||
@@ -222,7 +218,7 @@ class AbnAmroDescription implements SpecificInterface
|
||||
// Set a new description for the current transaction. If none was given
|
||||
// set the description to type, name and reference
|
||||
$this->row[7] = $newDescription;
|
||||
if (strlen($newDescription) === 0) {
|
||||
if (0 === strlen($newDescription)) {
|
||||
$this->row[7] = sprintf('%s - %s (%s)', $type, $name, $reference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* IngDescription.php
|
||||
* Copyright (C) 2016 https://github.com/tomwerf
|
||||
* Copyright (C) 2016 https://github.com/tomwerf.
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
@@ -18,13 +18,12 @@
|
||||
* 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\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class IngDescription
|
||||
* Class IngDescription.
|
||||
*
|
||||
* Parses the description from CSV files for Ing bank accounts.
|
||||
*
|
||||
@@ -32,12 +31,10 @@ namespace FireflyIII\Import\Specifics;
|
||||
* 'Incasso' the Name of Opposing account the Opposing IBAN number are in the
|
||||
* Description. This class will remove them, and add Name in description by
|
||||
* 'Betaalautomaat' so those are easily recognizable
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
*/
|
||||
class IngDescription implements SpecificInterface
|
||||
{
|
||||
/** @var array */
|
||||
/** @var array */
|
||||
public $row;
|
||||
|
||||
/**
|
||||
@@ -84,7 +81,7 @@ class IngDescription implements SpecificInterface
|
||||
|
||||
/**
|
||||
* Add the Opposing name from cell 1 in the description for Betaalautomaten
|
||||
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'
|
||||
* Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
@@ -97,7 +94,7 @@ class IngDescription implements SpecificInterface
|
||||
|
||||
/**
|
||||
* Remove IBAN number out of the description
|
||||
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>
|
||||
* Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
@@ -110,7 +107,7 @@ class IngDescription implements SpecificInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' )
|
||||
* Remove name from the description (Remove everything before the description incl the word 'Omschrijving' ).
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
* 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\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class PresidentsChoice
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
* Class PresidentsChoice.
|
||||
*/
|
||||
class PresidentsChoice implements SpecificInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -56,7 +52,7 @@ class PresidentsChoice implements SpecificInterface
|
||||
{
|
||||
// first, if column 2 is empty and 3 is not, do nothing.
|
||||
// if column 3 is empty and column 2 is not, move amount to column 3, *-1
|
||||
if (isset($row[3]) && strlen($row[3]) === 0) {
|
||||
if (isset($row[3]) && 0 === strlen($row[3])) {
|
||||
$row[3] = bcmul($row[2], '-1');
|
||||
}
|
||||
if (isset($row[1])) {
|
||||
|
||||
@@ -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\Import\Specifics;
|
||||
@@ -26,9 +25,7 @@ namespace FireflyIII\Import\Specifics;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RabobankDescription
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
* Class RabobankDescription.
|
||||
*/
|
||||
class RabobankDescription implements SpecificInterface
|
||||
{
|
||||
|
||||
@@ -21,22 +21,19 @@
|
||||
|
||||
/**
|
||||
* snsDescription.php
|
||||
* Author 2017 hugovanduijn@gmail.com
|
||||
* Author 2017 hugovanduijn@gmail.com.
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class SnsDescription
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
* Class SnsDescription.
|
||||
*/
|
||||
class SnsDescription implements SpecificInterface
|
||||
{
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
* 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\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Interface SpecificInterface
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
* Interface SpecificInterface.
|
||||
*/
|
||||
interface SpecificInterface
|
||||
{
|
||||
|
||||
@@ -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\Import\Storage;
|
||||
@@ -35,21 +34,19 @@ use Log;
|
||||
|
||||
/**
|
||||
* Is capable of storing individual ImportJournal objects.
|
||||
* Class ImportStorage
|
||||
*
|
||||
* @package FireflyIII\Import\Storage
|
||||
* Class ImportStorage.
|
||||
*/
|
||||
class ImportStorage
|
||||
{
|
||||
use ImportSupport;
|
||||
|
||||
/** @var Collection */
|
||||
/** @var Collection */
|
||||
public $errors;
|
||||
/** @var Collection */
|
||||
public $journals;
|
||||
/** @var int */
|
||||
/** @var int */
|
||||
protected $defaultCurrencyId = 1; // yes, hard coded
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
protected $job;
|
||||
/** @var Collection */
|
||||
protected $rules;
|
||||
@@ -57,7 +54,7 @@ class ImportStorage
|
||||
private $dateFormat = 'Ymd';
|
||||
/** @var Collection */
|
||||
private $objects;
|
||||
/** @var array */
|
||||
/** @var array */
|
||||
private $transfers = [];
|
||||
|
||||
/**
|
||||
@@ -125,6 +122,7 @@ class ImportStorage
|
||||
* @param ImportJournal $importJournal
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function storeImportJournal(int $index, ImportJournal $importJournal): bool
|
||||
@@ -139,7 +137,7 @@ class ImportStorage
|
||||
$transactionType = $this->getTransactionType($amount, $opposingAccount);
|
||||
$description = $importJournal->getDescription();
|
||||
|
||||
/*** First step done! */
|
||||
// First step done!
|
||||
$this->job->addStepsDone(1);
|
||||
|
||||
/**
|
||||
@@ -173,12 +171,11 @@ class ImportStorage
|
||||
'date' => $date,
|
||||
'hash' => $importJournal->hash,
|
||||
'amount' => $amount,
|
||||
|
||||
];
|
||||
$journal = $this->storeJournal($parameters);
|
||||
unset($parameters);
|
||||
|
||||
/*** Another step done! */
|
||||
// Another step done!
|
||||
$this->job->addStepsDone(1);
|
||||
|
||||
// store meta object things:
|
||||
@@ -202,12 +199,12 @@ class ImportStorage
|
||||
$journal->completed = true;
|
||||
$journal->save();
|
||||
|
||||
/*** Another step done! */
|
||||
// Another step done!
|
||||
$this->job->addStepsDone(1);
|
||||
|
||||
// run rules:
|
||||
$this->applyRules($journal);
|
||||
/*** Another step done! */
|
||||
// Another step done!
|
||||
$this->job->addStepsDone(1);
|
||||
$this->journals->push($journal);
|
||||
|
||||
@@ -224,7 +221,7 @@ class ImportStorage
|
||||
private function isDoubleTransfer(array $parameters): bool
|
||||
{
|
||||
Log::debug('Check if is a double transfer.');
|
||||
if ($parameters['type'] !== TransactionType::TRANSFER) {
|
||||
if (TransactionType::TRANSFER !== $parameters['type']) {
|
||||
Log::debug(sprintf('Is a %s, not a transfer so no.', $parameters['type']));
|
||||
|
||||
return false;
|
||||
@@ -239,23 +236,23 @@ class ImportStorage
|
||||
foreach ($this->transfers as $transfer) {
|
||||
$hits = 0;
|
||||
if ($parameters['description'] === $transfer['description']) {
|
||||
$hits++;
|
||||
++$hits;
|
||||
Log::debug(sprintf('Description "%s" equals "%s", hits = %d', $parameters['description'], $transfer['description'], $hits));
|
||||
}
|
||||
if ($names === $transfer['names']) {
|
||||
$hits++;
|
||||
++$hits;
|
||||
Log::debug(sprintf('Involved accounts, "%s" equals "%s", hits = %d', join(',', $names), join(',', $transfer['names']), $hits));
|
||||
}
|
||||
if (bccomp($amount, $transfer['amount']) === 0) {
|
||||
$hits++;
|
||||
if (0 === bccomp($amount, $transfer['amount'])) {
|
||||
++$hits;
|
||||
Log::debug(sprintf('Amount %s equals %s, hits = %d', $amount, $transfer['amount'], $hits));
|
||||
}
|
||||
if ($parameters['date'] === $transfer['date']) {
|
||||
$hits++;
|
||||
++$hits;
|
||||
Log::debug(sprintf('Date %s equals %s, hits = %d', $parameters['date'], $transfer['date'], $hits));
|
||||
}
|
||||
// number of hits is 4? Then it's a match
|
||||
if ($hits === 4) {
|
||||
if (4 === $hits) {
|
||||
Log::error(
|
||||
'There already is a transfer imported with these properties. Compare existing with new. ',
|
||||
['existing' => $transfer, 'new' => $parameters]
|
||||
@@ -265,7 +262,6 @@ class ImportStorage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\Import\Storage;
|
||||
@@ -46,17 +45,15 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Trait ImportSupport
|
||||
*
|
||||
* @package FireflyIII\Import\Storage
|
||||
* Trait ImportSupport.
|
||||
*/
|
||||
trait ImportSupport
|
||||
{
|
||||
/** @var int */
|
||||
protected $defaultCurrencyId = 1;
|
||||
/** @var ImportJob */
|
||||
/** @var ImportJob */
|
||||
protected $job;
|
||||
/** @var Collection */
|
||||
/** @var Collection */
|
||||
protected $rules;
|
||||
|
||||
/**
|
||||
@@ -88,6 +85,7 @@ trait ImportSupport
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function createTransaction(array $parameters): bool
|
||||
@@ -100,7 +98,7 @@ trait ImportSupport
|
||||
$transaction->foreign_currency_id = $parameters['foreign_currency'];
|
||||
$transaction->foreign_amount = $parameters['foreign_amount'];
|
||||
$transaction->save();
|
||||
if (is_null($transaction->id)) {
|
||||
if (null === $transaction->id) {
|
||||
$errorText = join(', ', $transaction->getErrors()->all());
|
||||
throw new FireflyException($errorText);
|
||||
}
|
||||
@@ -129,7 +127,7 @@ trait ImportSupport
|
||||
|
||||
// use given currency
|
||||
$currency = $importJournal->currency->getTransactionCurrency();
|
||||
if (!is_null($currency->id)) {
|
||||
if (null !== $currency->id) {
|
||||
return $currency->id;
|
||||
}
|
||||
|
||||
@@ -154,7 +152,7 @@ trait ImportSupport
|
||||
{
|
||||
// use given currency by import journal.
|
||||
$currency = $importJournal->currency->getTransactionCurrency();
|
||||
if (!is_null($currency->id) && $currency->id !== $currencyId) {
|
||||
if (null !== $currency->id && $currency->id !== $currencyId) {
|
||||
return $currency->id;
|
||||
}
|
||||
|
||||
@@ -226,7 +224,9 @@ trait ImportSupport
|
||||
* @param Account $account
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @see ImportSupport::getOpposingAccount()
|
||||
*/
|
||||
private function getTransactionType(string $amount, Account $account): string
|
||||
@@ -237,18 +237,18 @@ trait ImportSupport
|
||||
$transactionType = TransactionType::WITHDRAWAL;
|
||||
}
|
||||
|
||||
if (bccomp($amount, '0') === 1) {
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
$transactionType = TransactionType::DEPOSIT;
|
||||
}
|
||||
|
||||
// if opposing is an asset account, it's a transfer:
|
||||
if ($account->accountType->type === AccountType::ASSET) {
|
||||
if (AccountType::ASSET === $account->accountType->type) {
|
||||
Log::debug(sprintf('Opposing account #%d %s is an asset account, make transfer.', $account->id, $account->name));
|
||||
$transactionType = TransactionType::TRANSFER;
|
||||
}
|
||||
|
||||
// verify that opposing account is of the correct type:
|
||||
if ($account->accountType->type === AccountType::EXPENSE && $transactionType !== TransactionType::WITHDRAWAL) {
|
||||
if (AccountType::EXPENSE === $account->accountType->type && TransactionType::WITHDRAWAL !== $transactionType) {
|
||||
$message = 'This row is imported as a withdrawal but opposing is an expense account. This cannot be!';
|
||||
Log::error($message);
|
||||
throw new FireflyException($message);
|
||||
@@ -289,8 +289,8 @@ trait ImportSupport
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name', 'destination.amount'
|
||||
, 'transaction_journals.date']
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name', 'destination.amount',
|
||||
'transaction_journals.date',]
|
||||
);
|
||||
$array = [];
|
||||
/** @var TransactionJournal $entry */
|
||||
@@ -323,7 +323,7 @@ trait ImportSupport
|
||||
->where('data', $json)
|
||||
->where('name', 'importHash')
|
||||
->first();
|
||||
if (!is_null($entry)) {
|
||||
if (null !== $entry) {
|
||||
Log::error(sprintf('A journal with hash %s has already been imported (spoiler: it\'s journal #%d)', $hash, $entry->transaction_journal_id));
|
||||
|
||||
return true;
|
||||
@@ -338,7 +338,7 @@ trait ImportSupport
|
||||
*/
|
||||
private function storeBill(TransactionJournal $journal, Bill $bill)
|
||||
{
|
||||
if (!is_null($bill->id)) {
|
||||
if (null !== $bill->id) {
|
||||
Log::debug(sprintf('Linked bill #%d to journal #%d', $bill->id, $journal->id));
|
||||
$journal->bill()->associate($bill);
|
||||
$journal->save();
|
||||
@@ -351,7 +351,7 @@ trait ImportSupport
|
||||
*/
|
||||
private function storeBudget(TransactionJournal $journal, Budget $budget)
|
||||
{
|
||||
if (!is_null($budget->id)) {
|
||||
if (null !== $budget->id) {
|
||||
Log::debug(sprintf('Linked budget #%d to journal #%d', $budget->id, $journal->id));
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ trait ImportSupport
|
||||
*/
|
||||
private function storeCategory(TransactionJournal $journal, Category $category)
|
||||
{
|
||||
if (!is_null($category->id)) {
|
||||
if (null !== $category->id) {
|
||||
Log::debug(sprintf('Linked category #%d to journal #%d', $category->id, $journal->id));
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
@@ -403,7 +403,7 @@ trait ImportSupport
|
||||
'currency' => $parameters['currency'],
|
||||
'amount' => $parameters['amount'],
|
||||
'foreign_currency' => $parameters['foreign_currency'],
|
||||
'foreign_amount' => is_null($parameters['foreign_currency']) ? null : $parameters['amount'],
|
||||
'foreign_amount' => null === $parameters['foreign_currency'] ? null : $parameters['amount'],
|
||||
];
|
||||
$opposite = app('steam')->opposite($parameters['amount']);
|
||||
$two = [
|
||||
@@ -412,7 +412,7 @@ trait ImportSupport
|
||||
'currency' => $parameters['currency'],
|
||||
'amount' => $opposite,
|
||||
'foreign_currency' => $parameters['foreign_currency'],
|
||||
'foreign_amount' => is_null($parameters['foreign_currency']) ? null : $opposite,
|
||||
'foreign_amount' => null === $parameters['foreign_currency'] ? null : $opposite,
|
||||
];
|
||||
$this->createTransaction($one);
|
||||
$this->createTransaction($two);
|
||||
@@ -449,10 +449,10 @@ trait ImportSupport
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$dbTag = $repository->findByTag($tag);
|
||||
if (is_null($dbTag->id)) {
|
||||
if (null === $dbTag->id) {
|
||||
$dbTag = $repository->store(
|
||||
['tag' => $tag, 'date' => null, 'description' => null, 'latitude' => null, 'longitude' => null,
|
||||
'zoomLevel' => null, 'tagMode' => 'nothing']
|
||||
'zoomLevel' => null, 'tagMode' => 'nothing',]
|
||||
);
|
||||
}
|
||||
$journal->tags()->save($dbTag);
|
||||
|
||||
Reference in New Issue
Block a user