mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-16 06:38:09 +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\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)';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user